index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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="xuanke-tab-box">
  10. <!-- 动画按钮 -->
  11. <ezyActiveVue class="ezy-btn-active tab-item" v-for="item in data.list"
  12. :key="item.value"
  13. :class="{active: item.value == data.chanpinActiveSelect}"
  14. @aclick="handleSelectChanpin(item)">
  15. {{ item.name }}
  16. </ezyActiveVue>
  17. </view>
  18. <!-- 数学列表 -->
  19. <shuxueListVue v-if="data.chanpinActiveSelect == 1" :list="data.shuxueList"></shuxueListVue>
  20. <!-- 英语列表 -->
  21. <yingyuListVue v-if="data.chanpinActiveSelect == 2" :list="data.yingyuList"></yingyuListVue>
  22. <!-- 语文列表 -->
  23. <yuwenListVue v-if="data.chanpinActiveSelect == 3" :list="data.yuwenList"></yuwenListVue>
  24. </view>
  25. </view>
  26. <custom-tab-bar :show="true" :current-index="currentTabIndex"/>
  27. </template>
  28. <script setup>
  29. import {
  30. reactive, ref
  31. } from "vue";
  32. import shuxueListVue from "./components/shuxueList.vue";
  33. import yingyuListVue from "./components/yingyuList.vue";
  34. import yuwenListVue from "./components/yuwenList.vue";
  35. import {
  36. onLoad,
  37. onShow
  38. } from "@dcloudio/uni-app"
  39. import * as shuxueHttp from "@/api/chanpinShuxue.js"
  40. import CustomTabBar from "@/components/custom-tabbar/index.vue";
  41. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue";
  42. import {getChanpinTongyongIndex} from "../../api/chanpinShuxue";
  43. import {getFullTimer} from "../../utils/common";
  44. let currentTabIndex = ref(0)
  45. const data = reactive({
  46. list: [
  47. {
  48. name: '数学',
  49. value: 1
  50. },
  51. {
  52. name: '英语',
  53. value: 2
  54. },
  55. {
  56. name: '语文',
  57. value: 3
  58. },
  59. ],
  60. chanpinActiveSelect: 1,
  61. shuxueList: [],
  62. })
  63. function getFormatData(data) {
  64. const shuxue = data.shuxue || {};
  65. const yingyu = data.yingyu || {};
  66. const yuwen = data.yuwen || {};
  67. return {
  68. shuxue: Object.entries(shuxue).map(([chanpin, value]) => {
  69. return { chanpin, value };
  70. }),
  71. yingyu:Object.entries(yingyu).map(([chanpin, value]) => {
  72. return { chanpin, value };
  73. }),
  74. yuwen:Object.entries(yuwen).map(([chanpin, value]) => {
  75. return { chanpin, value };
  76. }),
  77. }
  78. }
  79. function getShuxueList() {
  80. shuxueHttp.getChanpinTongyongIndex().then(res => {
  81. const result = getFormatData(res.data);
  82. data.shuxueList = result.shuxue;
  83. data.yingyuList = result.yingyu;
  84. data.yuwenList = result.yuwen;
  85. })
  86. }
  87. function handleSelectChanpin(item) {
  88. data.chanpinActiveSelect = item.value
  89. }
  90. onShow(() => {
  91. currentTabIndex.value = 0;
  92. data.chanpinActiveSelect = 1;
  93. if (getFullTimer() !== `2026-01-28`) {
  94. //每日刷新
  95. getShuxueList();
  96. }
  97. })
  98. onLoad(() => {
  99. uni.hideTabBar()
  100. getShuxueList()
  101. })
  102. </script>