index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <view class="ezy-ziliao-page">
  3. <view class="icon-title-navBar-box">
  4. <text class="nav-bar-title">资料</text>
  5. </view>
  6. <view class="ezy-page-body">
  7. <!-- 科目标签切换 -->
  8. <view class="ezy-xueke-tab-box">
  9. <ezyActiveVue class="tab-item ezy-btn-active" v-for="item in data.list" :key="item.value"
  10. :class="{active: item.key == data.chanpinActiveSelect}" @aclick="handleSelectChanpin(item)">
  11. {{item.label}}</ezyActiveVue>
  12. </view>
  13. <!-- 资源卡片列表 -->
  14. <!-- 数学 -->
  15. <ShuXueList v-if="data.chanpinActiveSelect === 'shuxue'" :list="data.shuxueList" />
  16. <!-- 英语 -->
  17. <YingYuList v-if="data.chanpinActiveSelect === 'yingyu'" :list="data.yingyuList" />
  18. <!-- 语文 -->
  19. <YuWenList v-if="data.chanpinActiveSelect === 'yuwen'" :list="data.yuwenList" />
  20. </view>
  21. </view>
  22. <custom-tab-bar :show="true" :current-index="currentTabIndex" />
  23. </template>
  24. <script setup>
  25. import {reactive, ref} from "vue";
  26. import {onLoad,onShow} from "@dcloudio/uni-app"
  27. import {ziliaoIndex} from '@/api/ziliao.js'
  28. import CustomTabBar from "@/components/custom-tabbar/index.vue";
  29. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue";
  30. import ShuXueList from "./shuxue/sxList.vue"
  31. import YingYuList from "./yingyu/yyList.vue"
  32. import YuWenList from "./yuwen/ywList.vue"
  33. import {useSelectDateForUpdate} from "@/utils/common";
  34. let currentTabIndex = ref(2);
  35. const {isNowDate,resetDate} = useSelectDateForUpdate('ziliaoDate')
  36. const data = reactive({
  37. list:[
  38. { key: 'shuxue', label: '数学' },
  39. { key: 'yingyu', label: '英语' },
  40. { key: 'yuwen', label: '语文' }
  41. ],
  42. chanpinActiveSelect: 'shuxue',
  43. shuxueList: {},
  44. yingyuList: {},
  45. yuwenList: {}
  46. })
  47. // tab click
  48. function handleSelectChanpin(item) {
  49. data.chanpinActiveSelect = item.key
  50. }
  51. // ziliao list
  52. function getZiliaoList() {
  53. ziliaoIndex({}).then(res => {
  54. const result = getFormatData(res.data);
  55. data.shuxueList = result.shuxue;
  56. data.yingyuList = result.yingyu;
  57. data.yingyuList = result.yuwen;
  58. if (!data.shuxueList.length && !data.yingyuList.length && !data.yingyuList.length) {
  59. // 并无数据时,清理时间缓存
  60. resetDate()
  61. }
  62. }).catch(err => {
  63. // 请求异常时,清理时间缓存
  64. resetDate()
  65. })
  66. }
  67. // Format
  68. function getFormatData(data) {
  69. const shuxue = data.shuxue || {};
  70. const yingyu = data.yingyu || {};
  71. const yuwen = data.yuwen || {};
  72. return {
  73. shuxue: Object.entries(shuxue).map(([chanpin, content]) => {
  74. return { chanpin, content };
  75. }),
  76. yingyu:Object.entries(yingyu).map(([chanpin, content]) => {
  77. return { chanpin, content };
  78. }),
  79. yuwen:Object.entries(yuwen).map(([chanpin, content]) => {
  80. return { chanpin, content };
  81. }),
  82. }
  83. }
  84. onShow(() => {
  85. currentTabIndex.value = 2;
  86. data.chanpinActiveSelect = 'shuxue'
  87. if (isNowDate()) {
  88. // 当天不刷新
  89. } else {
  90. //每日刷新
  91. getZiliaoList()
  92. }
  93. })
  94. onLoad(() => {
  95. // 隐藏默认系统导航栏显示自定义导航栏
  96. uni.hideTabBar()
  97. getZiliaoList()
  98. })
  99. </script>
  100. <style>
  101. </style>