index2.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 {getUserIdentity} from "@/utils/common.js"
  50. import cacheManager from "@/utils/cacheManager.js"
  51. import {getCardOnline} from "../../api/catalogue";
  52. const comingSoonDialogRef = ref(null);
  53. function useSelectGrade() {
  54. const userCode = getUserIdentity();
  55. const data = reactive({
  56. activeNianji: null, // 当前年级
  57. activeXueke: null, // 当前学期
  58. activeTipFlag: null, // 当前学期
  59. });
  60. onLoad(({nianji,cardId,tipFlag}) => {
  61. if (userCode !== 'Visitor') {
  62. const {
  63. nianji: nianji_,
  64. cardId: cardId_
  65. } = cacheManager.get('auth');
  66. data.activeNianji = nianji_;
  67. data.activeXueke = cardId_;
  68. } else {
  69. data.activeNianji = nianji;
  70. data.activeXueke = cardId;
  71. data.activeTipFlag = tipFlag || '0';
  72. }
  73. });
  74. // 选择 年级+学期
  75. function handleConfirm() {
  76. if (!data.activeXueke) {
  77. uni.showToast({
  78. title: "请选择课程类别",
  79. duration: 2000,
  80. icon: 'error'
  81. });
  82. return;
  83. }
  84. if (!data.activeNianji) {
  85. uni.showToast({
  86. title: "请选择课程等级",
  87. duration: 2000,
  88. icon: 'error'
  89. });
  90. return;
  91. }
  92. getCardOnline({cardId: data.activeXueke,nianji: data.activeNianji}).then(res => {
  93. if (res.data) {
  94. goDAOToStudy();
  95. } else {
  96. comingSoonDialogRef.value.handleShow();
  97. }
  98. })
  99. }
  100. // 跳转 岛 学习
  101. function goDAOToStudy() {
  102. if (userCode !== 'Visitor') {
  103. const auth = cacheManager.get('auth');
  104. cacheManager.updateObject('auth', {
  105. nianji: data.activeNianji,
  106. zhangId: data.activeNianji == auth.nianji && data.activeXueke == auth.cardId ? auth.zhangId: 0,
  107. cardId: data.activeXueke,
  108. currentZhang: 0
  109. })
  110. cacheManager.remove('daoPageCache')
  111. // 数序
  112. uni.redirectTo({
  113. url: `/pages/study/index`
  114. })
  115. } else {
  116. // 数序
  117. uni.redirectTo({
  118. url: `/pages/study/index?nianji=${data.activeNianji}&cardId=${data.activeXueke}&zhangId=0&tipFlag=${data.activeTipFlag}`
  119. })
  120. }
  121. }
  122. function handleBack() {
  123. if (userCode !== 'Visitor') {
  124. uni.redirectTo({ url: `/pages/study/index`})
  125. } else {
  126. uni.redirectTo({url: '/pages/login/index'})
  127. }
  128. }
  129. return {
  130. ...toRefs(data),
  131. handleBack,
  132. // 方法
  133. handleConfirm, // 选择年级+学科
  134. };
  135. }
  136. const {
  137. activeNianji,
  138. activeXueke,
  139. handleConfirm,
  140. handleBack
  141. } = useSelectGrade()
  142. function handleSelectGrade(item) {
  143. activeNianji.value = item.id;
  144. }
  145. function handleSelectXueke(item) {
  146. activeXueke.value = item.id;
  147. }
  148. </script>