index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view class="grades-terms-page">
  3. <view class="icon-title-navBar-box">
  4. <!-- 返回按钮↓ -->
  5. <view class="nav-bar-icon" @click="handleBack"></view>
  6. </view>
  7. <view class="grades-body">
  8. <view class="grades-change-title"></view>
  9. <text class="grades-title-desc">我们会根据您选择,为您匹配对应的学习内容</text>
  10. <view class="grades-terms-title terms-title-img"></view>
  11. <view class="grade-item-box">
  12. <view v-for="item in xueke_list" :key="item.id" @click="handleSelectXueke(item)"
  13. :class="['grade-item',{active: item.id == activeXueke}]">{{item.label}}</view>
  14. </view>
  15. <view class="grades-terms-title grades-title-img"></view>
  16. <view class="grade-item-box" v-if="activeXueke != 2">
  17. <!-- 数学 -->
  18. <view v-for="item in nianji_list" :key="item.id" @click="handleSelectGrade(item)"
  19. :class="['grade-item', {active: item.id == activeNianji}]">{{item.label}}</view>
  20. </view>
  21. <view class="grade-item-box" v-else>
  22. <!-- 英语 -->
  23. <template v-for="item in nianji_list" :key="item.id">
  24. <view @click="handleSelectGrade(item)" v-if="item.id != 6"
  25. :class="['grade-item', {active: item.id == activeNianji}]">{{item.label}}</view>
  26. <view v-else class="grade-yingyu-item"></view>
  27. </template>
  28. </view>
  29. <view class="grade-line"></view>
  30. <button class="grade-confirm-btn" @click="handleConfirm"></button>
  31. </view>
  32. <coming-soon-dialog ref="comingSoonDialogRef"></coming-soon-dialog>
  33. </view>
  34. </template>
  35. <script setup>
  36. import comingSoonDialog from './comingSoonDialog.vue';
  37. import {
  38. reactive,
  39. toRefs,
  40. ref,
  41. } from "vue";
  42. import {
  43. nianji_list,
  44. xueke_list,
  45. } from "@/utils/constant.js";
  46. import {
  47. onLoad
  48. } from "@dcloudio/uni-app";
  49. import {
  50. getUserIdentity
  51. } from "@/utils/common.js"
  52. import cacheManager from "@/utils/cacheManager.js"
  53. import {
  54. getCardOnline
  55. } from "../../api/catalogue";
  56. const comingSoonDialogRef = ref(null);
  57. function useSelectGrade() {
  58. const userCode = getUserIdentity();
  59. const data = reactive({
  60. activeNianji: null, // 当前年级
  61. activeXueke: null, // 当前学期
  62. activeTipFlag: null, // 当前学期
  63. });
  64. onLoad(({
  65. nianji,
  66. cardId,
  67. tipFlag
  68. }) => {
  69. if (userCode !== 'Visitor') {
  70. const {
  71. nianji: nianji_,
  72. cardId: cardId_
  73. } = cacheManager.get('auth');
  74. data.activeNianji = nianji_;
  75. data.activeXueke = cardId_;
  76. } else {
  77. data.activeNianji = nianji;
  78. data.activeXueke = cardId;
  79. data.activeTipFlag = tipFlag || '0';
  80. }
  81. });
  82. // 选择 年级+学期
  83. function handleConfirm() {
  84. if (!data.activeXueke) {
  85. uni.showToast({
  86. title: "请选择课程类别",
  87. duration: 2000,
  88. icon: 'error'
  89. });
  90. return;
  91. }
  92. if (!data.activeNianji) {
  93. uni.showToast({
  94. title: "请选择课程等级",
  95. duration: 2000,
  96. icon: 'error'
  97. });
  98. return;
  99. }
  100. getCardOnline({
  101. cardId: data.activeXueke,
  102. nianji: data.activeNianji
  103. }).then(res => {
  104. if (res.data) {
  105. goDAOToStudy();
  106. } else {
  107. comingSoonDialogRef.value.handleShow();
  108. }
  109. })
  110. }
  111. // 跳转 岛 学习
  112. function goDAOToStudy() {
  113. if (userCode !== 'Visitor') {
  114. const auth = cacheManager.get('auth');
  115. cacheManager.updateObject('auth', {
  116. typeId: typeId,
  117. levelId: levelId,
  118. subjectId: subjectId, // 此处subjectId 独立加入缓存,单独维护,勿动 @date 2025/05/14
  119. zhangId: data.activeProduct == auth.nianji && data.activeXueke == auth.cardId ? auth.zhangId :
  120. 0,
  121. currentZhang: 0
  122. })
  123. cacheManager.remove('daoPageCache')
  124. // 数序
  125. uni.redirectTo({
  126. url: `/pages/study/index`
  127. })
  128. } else {
  129. // 数序
  130. uni.redirectTo({
  131. url: `/pages/study/index?nianji=${data.activeNianji}&cardId=${data.activeXueke}&zhangId=0&tipFlag=${data.activeTipFlag}`
  132. })
  133. }
  134. }
  135. function handleBack() {
  136. if (userCode !== 'Visitor') {
  137. uni.redirectTo({
  138. url: `/pages/study/index`
  139. })
  140. } else {
  141. uni.redirectTo({
  142. url: '/pages/login/index'
  143. })
  144. }
  145. }
  146. return {
  147. ...toRefs(data),
  148. handleBack,
  149. // 方法
  150. handleConfirm, // 选择年级+学科
  151. };
  152. }
  153. const {
  154. activeNianji,
  155. activeXueke,
  156. handleConfirm,
  157. handleBack
  158. } = useSelectGrade()
  159. function handleSelectGrade(item) {
  160. activeNianji.value = item.id;
  161. }
  162. function handleSelectXueke(item) {
  163. activeXueke.value = item.id;
  164. }
  165. </script>