college-profile.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view class="p-30">
  3. <uv-read-more ref="more" show-height="120" close-text="展开全部" toggle>
  4. <uv-parse :content="baseInfo.introduction" content-style="color:#1A1A1A; font-size: 28rpx"
  5. container-style="padding:30rpx; border-radius: 24rpx; background-color: var(--back-light)"/>
  6. </uv-read-more>
  7. <view class="mt-30 flex justify-between items-center text-28 gap-20">
  8. <view class="bg-secondary-light text-secondary" :class="buttonClass" @click="handleWebsite">
  9. <uv-icon name="share-fill" color="var(--secondary)"/>
  10. <text class="text-secondary">招生官网</text>
  11. </view>
  12. <view class="bg-primary-100 text-primary" :class="buttonClass" @click="handlePhone">
  13. <uv-icon name="phone-fill" color="primary"/>
  14. <text class="text-primary">招生电话</text>
  15. </view>
  16. </view>
  17. <view class="mt-30">
  18. <view class="text-32 font-bold text-fore-title">开设专业</view>
  19. <uv-gap v-if="loading" height="15"/>
  20. <uv-skeleton v-if="loading" :title="false" rows="3" rows-height="44" :rows-width="['100%','100%','100%']"/>
  21. <view v-for="(g,i) in grouped" :key="i"
  22. class="mt-28 p-28 flex justify-between items-center bg-back-light rounded-lg">
  23. <view class="text-28 font-bold text-fore-title truncate">{{ g.root.name }}</view>
  24. <view class="text-24 text-fore-title flex items-center" @click="handleProfessionGroup(g)">
  25. <text>{{ g.count }}个专业</text>
  26. <uv-icon name="arrow-right"/>
  27. </view>
  28. </view>
  29. </view>
  30. <!-- <uv-action-sheet ref="actionSheet" :title="baseInfo.tel" :actions="actions" safe-area-inset-bottom-->
  31. <!-- close-on-click-overlay cancel-text="取消" @select="handleActionSelect"/>-->
  32. <ie-popup ref="popup" :show-toolbar="false">
  33. <template v-if="popupGroup">
  34. <view class="h-90 flex justify-center items-center text-32 font-bold">{{ popupGroup.root.name }}</view>
  35. <scroll-view scroll-y :style="{maxHeight: '50vh', backgroundColor: 'var(--back-light)'}">
  36. <uv-cell-group v-for="(g,i) in popupGroup.subGroups" :key="i" title="1">
  37. <template #title>
  38. <text class="text-24 text-fore-tip">{{g.parent.name}}</text>
  39. </template>
  40. <uv-cell v-for="p in g.list" :title="p.name" custom-class="bg-white"/>
  41. </uv-cell-group>
  42. </scroll-view>
  43. </template>
  44. </ie-popup>
  45. </view>
  46. </template>
  47. <script setup lang="ts">
  48. import {MAJOR_TREE, UNIVERSITY_DETAIL} from "@/types/injectionSymbols";
  49. import {University, UniversityDetail, UniversityProfession} from "@/types/university";
  50. import {MajorItem} from "@/types/major";
  51. import UvReadMore from "@/uni_modules/uv-read-more/components/uv-read-more/uv-read-more.vue";
  52. import UvActionSheet from "@/uni_modules/uv-action-sheet/components/uv-action-sheet/uv-action-sheet.vue";
  53. import IePopup from "@/components/ie-popup/ie-popup.vue";
  54. interface ActionItem {
  55. id: string;
  56. name: string;
  57. icon?: string;
  58. color?: string;
  59. iconColor?: string;
  60. disabled?: boolean;
  61. }
  62. interface ProfessionSubGroup {
  63. parent: MajorItem;
  64. list: UniversityProfession[];
  65. }
  66. interface ProfessionGroup {
  67. root: MajorItem;
  68. subGroups: ProfessionSubGroup[];
  69. count: number;
  70. }
  71. defineProps({
  72. loading: Boolean
  73. })
  74. const detail = inject(UNIVERSITY_DETAIL) || ref({} as UniversityDetail)
  75. const majorTree = inject(MAJOR_TREE) || ref([])
  76. const baseInfo = computed<University>(() => detail.value.baseInfo || {})
  77. const professions = computed<UniversityProfession[]>(() => detail.value.professions || [])
  78. const more = ref<InstanceType<typeof UvReadMore>>()
  79. const actionSheet = ref<InstanceType<typeof UvActionSheet>>()
  80. const buttonClass = "flex-1 py-16 rounded-lg flex justify-center items-center gap-8"
  81. const actions = computed(() => [{
  82. id: 'call',
  83. name: '打电话'
  84. }, {
  85. id: 'copy',
  86. name: '复制'
  87. }])
  88. const skeleton = [{
  89. num: 3,
  90. type: 'line',
  91. gap: '30rpx',
  92. style: ['height: 100rpx']
  93. }]
  94. const popup = ref<InstanceType<typeof IePopup>>()
  95. const popupGroup = ref<ProfessionGroup>()
  96. const grouped = computed<ProfessionGroup[]>(() => {
  97. if (!majorTree.value || !professions.value) return [];
  98. // 预先构建三级节点到其路径的映射
  99. const nodePathCache = new Map<string, { root: MajorItem; parent: MajorItem }>();
  100. const buildPathCache = (node: MajorItem, root?: MajorItem, parent?: MajorItem) => {
  101. if (node.children?.length) {
  102. // 非叶子节点
  103. const newRoot = root || node;
  104. const isRoot = !root;
  105. const newParent = isRoot ? undefined : (parent || node);
  106. node.children.forEach(child => buildPathCache(child, newRoot, newParent));
  107. } else {
  108. // 叶子节点(三级节点)
  109. if (root && parent) {
  110. nodePathCache.set(node.code, {root, parent});
  111. }
  112. }
  113. };
  114. majorTree.value.forEach(node => buildPathCache(node));
  115. // 分组逻辑
  116. const rootMap = new Map<string, {
  117. root: MajorItem;
  118. parentMap: Map<string, {
  119. parent: MajorItem;
  120. list: UniversityProfession[];
  121. }>;
  122. count: number;
  123. }>();
  124. professions.value.forEach(profession => {
  125. const path = nodePathCache.get(profession.code);
  126. if (!path) return;
  127. const {root, parent} = path;
  128. let rootEntry = rootMap.get(root.code);
  129. if (!rootEntry) {
  130. rootEntry = {
  131. root,
  132. parentMap: new Map(),
  133. count: 0
  134. };
  135. rootMap.set(root.code, rootEntry);
  136. }
  137. let parentEntry = rootEntry.parentMap.get(parent.code);
  138. if (!parentEntry) {
  139. parentEntry = {
  140. parent,
  141. list: []
  142. };
  143. rootEntry.parentMap.set(parent.code, parentEntry);
  144. }
  145. parentEntry.list.push(profession);
  146. rootEntry.count++;
  147. });
  148. // 转换为最终格式
  149. return Array.from(rootMap.values())
  150. .map(({root, parentMap, count}) => ({
  151. root,
  152. subGroups: Array.from(parentMap.values()),
  153. count
  154. }))
  155. });
  156. const handleWebsite = () => {
  157. if (baseInfo.value.webSite) {
  158. uni.$ie.openBrowser(baseInfo.value.webSite)
  159. } else {
  160. uni.$ie.showToast('未提供网址')
  161. }
  162. }
  163. const handlePhone = () => {
  164. if (baseInfo.value.tel) {
  165. //UvActionSheet 在这里打开有异常,所以先使用粘贴板
  166. // actionSheet.value?.open()
  167. uni.setClipboardData({
  168. data: baseInfo.value.tel,
  169. showToast: false,
  170. success: () => {
  171. uni.showModal({
  172. title: '提示',
  173. content: '号码已复制',
  174. showCancel: false
  175. })
  176. }
  177. })
  178. } else {
  179. uni.$ie.showToast('未提供电话')
  180. }
  181. }
  182. const handleActionSelect = (e: ActionItem) => {
  183. if (e.id == 'call') {
  184. uni.makePhoneCall({phoneNumber: baseInfo.value.tel})
  185. } else if (e.id == 'copy') {
  186. uni.setClipboardData({
  187. data: baseInfo.value.tel,
  188. success: () => {
  189. uni.showModal({
  190. title: '提示',
  191. content: '号码已复制',
  192. showCancel: false
  193. })
  194. }
  195. })
  196. }
  197. }
  198. const handleProfessionGroup = (g: ProfessionGroup) => {
  199. popupGroup.value = g
  200. popup.value?.open()
  201. }
  202. watch(() => baseInfo.value.introduction, async (val) => {
  203. if (val) {
  204. await nextTick()
  205. more.value?.init()
  206. }
  207. })
  208. </script>
  209. <style scoped lang="scss">
  210. ::v-deep .uv-cell-group__title__text {
  211. font-size: 12px;
  212. color: #999999;
  213. }
  214. </style>