index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="ezy-xuanke-page">
  3. <!-- 返回区域 -->
  4. <view class="icon-title-navBar-box">
  5. <text class="nav-bar-title">选课</text>
  6. </view>
  7. <view class="ezy-page-body">
  8. <!-- 头部区域 -->
  9. <view class="ezy-xueke-tab-box">
  10. <!-- 动画按钮 -->
  11. <ezyActiveVue class="ezy-btn-active tab-item" v-for="item in data.list" :key="item.key"
  12. :class="{active: item.key == data.chanpinActiveSelect}" @aclick="handleSelectChanpin(item)">
  13. {{ item.label }}
  14. </ezyActiveVue>
  15. </view>
  16. <!-- 数学列表 -->
  17. <shuxueListVue v-if="data.chanpinActiveSelect == 'shuxue'" :list="data.shuxueList"></shuxueListVue>
  18. <!-- 英语列表 -->
  19. <yingyuListVue v-if="data.chanpinActiveSelect == 'yingyu'" :list="data.yingyuList"></yingyuListVue>
  20. <!-- 语文列表 -->
  21. <yuwenListVue v-if="data.chanpinActiveSelect == 'yuwen'" :list="data.yuwenList"></yuwenListVue>
  22. </view>
  23. </view>
  24. <custom-tab-bar :show="true" :current-index="currentTabIndex" />
  25. </template>
  26. <script setup>
  27. import {
  28. reactive,
  29. ref
  30. } from "vue";
  31. import shuxueListVue from "./components/shuxueList.vue";
  32. import yingyuListVue from "./components/yingyuList.vue";
  33. import yuwenListVue from "./components/yuwenList.vue";
  34. import {
  35. onLoad,
  36. onShow
  37. } from "@dcloudio/uni-app"
  38. import * as shuxueHttp from "@/api/chanpinShuxue.js"
  39. import CustomTabBar from "@/components/custom-tabbar/index.vue";
  40. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue";
  41. import {
  42. getChanpinTongyongIndex
  43. } from "@/api/chanpinShuxue";
  44. import {
  45. useSelectDateForUpdate
  46. } from "@/utils/common";
  47. let currentTabIndex = ref(0)
  48. const data = reactive({
  49. list: [{
  50. key: 'shuxue',
  51. label: '数学'
  52. },
  53. {
  54. key: 'yingyu',
  55. label: '英语'
  56. },
  57. {
  58. key: 'yuwen',
  59. label: '语文'
  60. }
  61. ],
  62. chanpinActiveSelect: 'shuxue',
  63. shuxueList: [],
  64. yingyuList: [],
  65. yuwenList: [],
  66. })
  67. const {isNowDate,resetDate} = useSelectDateForUpdate('xuankeDate')
  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, value]) => {
  74. return {
  75. chanpin,
  76. value
  77. };
  78. }),
  79. yingyu: Object.entries(yingyu).map(([chanpin, value]) => {
  80. return {
  81. chanpin,
  82. value
  83. };
  84. }),
  85. yuwen: Object.entries(yuwen).map(([chanpin, value]) => {
  86. return {
  87. chanpin,
  88. value
  89. };
  90. }),
  91. }
  92. }
  93. function getShuxueList() {
  94. shuxueHttp.getChanpinTongyongIndex().then(res => {
  95. const result = getFormatData(res.data);
  96. data.shuxueList = result.shuxue;
  97. data.yingyuList = result.yingyu;
  98. data.yuwenList = result.yuwen;
  99. if (!data.shuxueList.length && !data.yingyuList.length && !data.yuwenList.length) {
  100. // 并无学习数据时,清理时间缓存
  101. resetDate()
  102. }
  103. }).catch(err => {
  104. // 请求异常时,清理时间缓存
  105. resetDate()
  106. })
  107. }
  108. function handleSelectChanpin(item) {
  109. data.chanpinActiveSelect = item.key
  110. }
  111. onShow(() => {
  112. currentTabIndex.value = 0;
  113. data.chanpinActiveSelect = 'shuxue';
  114. if (isNowDate()) {
  115. // 当天不刷新
  116. } else {
  117. //每日刷新
  118. getShuxueList()
  119. }
  120. })
  121. onLoad(() => {
  122. uni.hideTabBar()
  123. })
  124. </script>