index.vue 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <z-paging ref="paging" v-model="list" @query="handleQuery" @on-refresh="handleRefresh">
  3. <template #top>
  4. <mx-nav-bar title="专业库"/>
  5. <view class="px-20 py-10 bg-white">
  6. <mx-search v-model="name" placeholder="输入专业名称" @search="handleSearch" @clear="handleSearch"/>
  7. </view>
  8. <uv-line/>
  9. </template>
  10. <view v-if="isCultural" class="h-[50px] fx-row fx-cen-cen">
  11. <mx-subsection v-model="current" :list="types" @change="handleSearch" width="65vw"/>
  12. </view>
  13. <view v-for="(levelOne,idx) in list">
  14. <view class="bg-white" :class="{'mt-20':isCultural?idx>0:true}" v-if="levelOne.level == 1">
  15. <view class="text-lg py-20 pl-30 font-bold">{{ levelOne.name }}</view>
  16. <uv-cell v-for="item in levelOne.children" class="f-333" :border="levelOne.childCount > 1" isLink
  17. :title="item.name" :value="`${item.childCount}个专业`" @click="goDetail(item)">
  18. </uv-cell>
  19. </view>
  20. <uv-cell v-else :value="levelOne.childCount ? `${levelOne.childCount}个专业` : ''" isLink
  21. :title="levelOne.name" class="bg-white" :class="{'mt-20':idx==0&&!isCultural}"
  22. @click="goDetail(levelOne)">
  23. </uv-cell>
  24. </view>
  25. </z-paging>
  26. </template>
  27. <script setup>
  28. import {ref, computed} from 'vue';
  29. import {useUserStore} from "@/hooks/useUserStore";
  30. import {useCacheStore} from "@/hooks/useCacheStore";
  31. import {cacheActions} from "@/hooks/defineCacheActions";
  32. import {useTransfer} from "@/hooks/useTransfer";
  33. const paging = ref(null)
  34. const list = ref([])
  35. const {isCultural} = useUserStore()
  36. const {dispatchCache, removeCache} = useCacheStore()
  37. const {transferTo} = useTransfer()
  38. const name = ref('')
  39. const current = ref(0)
  40. const types = ref(['本科', '专科', '职教本科'])
  41. const type = computed(() => types.value[current.value])
  42. const handleSearch = () => {
  43. paging.value.reload()
  44. }
  45. const handleRefresh = () => {
  46. removeCache(cacheActions.getMajorTree)
  47. }
  48. const handleQuery = () => {
  49. // payload这样申明是为了在无条件时构建通用缓存,减少请求次数,
  50. // 与其它地方dispatchCache(cacheActions.getMajorTree)调用重合
  51. let payload = undefined
  52. if (name.value) {
  53. payload = payload || {}
  54. payload.name = name.value
  55. payload.level = 1
  56. }
  57. if (isCultural.value) {
  58. payload = payload || {}
  59. payload.type = type.value
  60. }
  61. dispatchCache(cacheActions.getMajorTree, payload)
  62. .then(tree => paging.value.completeByNoMore(tree, true))
  63. .catch(e => paging.value.complete(false))
  64. }
  65. const goDetail = (item) => {
  66. const paths = [, , 'level-two/level-two', 'detail/detail']
  67. const path = paths[item.level]
  68. if (!path) return
  69. transferTo('/pages/major-library/' + path, ['code'], item)
  70. }
  71. </script>
  72. <style lang="scss">
  73. </style>