college-profile.vue 9.7 KB

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