index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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">
  17. <view v-for="item in nianji_list" :key="item.id" @click="handleSelectGrade(item)"
  18. :class="['grade-item', {active: item.id == activeNianji}]">{{item.label}}</view>
  19. </view>
  20. <view class="grade-line"></view>
  21. <button class="grade-confirm-btn" @click="handleConfirm"></button>
  22. </view>
  23. <coming-soon-dialog ref="comingSoonDialogRef"></coming-soon-dialog>
  24. </view>
  25. </template>
  26. <script setup>
  27. import comingSoonDialog from './comingSoonDialog.vue';
  28. import {
  29. reactive,
  30. toRefs,
  31. ref,
  32. } from "vue";
  33. import {
  34. nianji_list,
  35. xueke_list,
  36. } from "@/utils/constant.js";
  37. import {
  38. onLoad
  39. } from "@dcloudio/uni-app";
  40. import {getUserIdentity} from "@/utils/common.js"
  41. import cacheManager from "@/utils/cacheManager.js"
  42. import {getCardOnline} from "../../api/catalogue";
  43. const comingSoonDialogRef = ref(null);
  44. function useSelectGrade() {
  45. const userCode = getUserIdentity();
  46. const data = reactive({
  47. activeNianji: null, // 当前年级
  48. activeXueke: null, // 当前学期
  49. activeTipFlag: null, // 当前学期
  50. });
  51. onLoad(({nianji,cardId,tipFlag}) => {
  52. if (userCode !== 'Visitor') {
  53. const {
  54. nianji: nianji_,
  55. cardId: cardId_
  56. } = cacheManager.get('auth');
  57. data.activeNianji = nianji_;
  58. data.activeXueke = cardId_;
  59. } else {
  60. data.activeNianji = nianji;
  61. data.activeXueke = cardId;
  62. data.activeTipFlag = tipFlag || '0';
  63. }
  64. });
  65. // 选择 年级+学期
  66. function handleConfirm() {
  67. if (!data.activeXueke) {
  68. uni.showToast({
  69. title: "请选择课程类别",
  70. duration: 2000,
  71. icon: 'error'
  72. });
  73. return;
  74. }
  75. if (!data.activeNianji) {
  76. uni.showToast({
  77. title: "请选择课程等级",
  78. duration: 2000,
  79. icon: 'error'
  80. });
  81. return;
  82. }
  83. getCardOnline({cardId: data.activeXueke,nianji: data.activeNianji}).then(res => {
  84. if (res.data) {
  85. goDAOToStudy();
  86. } else {
  87. comingSoonDialogRef.value.handleShow();
  88. }
  89. })
  90. }
  91. // 跳转 岛 学习
  92. function goDAOToStudy() {
  93. if (userCode !== 'Visitor') {
  94. const auth = cacheManager.get('auth');
  95. cacheManager.updateObject('auth', {
  96. nianji: data.activeNianji,
  97. zhangId: data.activeNianji == auth.nianji && data.activeXueke == auth.cardId ? auth.zhangId: 0,
  98. cardId: data.activeXueke,
  99. currentZhang: 0
  100. })
  101. cacheManager.remove('daoPageCache')
  102. // 数序
  103. uni.redirectTo({
  104. url: `/pages/study/index`
  105. })
  106. } else {
  107. // 数序
  108. uni.redirectTo({
  109. url: `/pages/study/index?nianji=${data.activeNianji}&cardId=${data.activeXueke}&zhangId=0&tipFlag=${data.activeTipFlag}`
  110. })
  111. }
  112. }
  113. function handleBack() {
  114. if (userCode !== 'Visitor') {
  115. uni.redirectTo({ url: `/pages/study/index`})
  116. } else {
  117. uni.redirectTo({url: '/pages/login/index'})
  118. }
  119. }
  120. return {
  121. ...toRefs(data),
  122. handleBack,
  123. // 方法
  124. handleConfirm, // 选择年级+学科
  125. };
  126. }
  127. const {
  128. activeNianji,
  129. activeXueke,
  130. handleConfirm,
  131. handleBack
  132. } = useSelectGrade()
  133. function handleSelectGrade(item) {
  134. activeNianji.value = item.id;
  135. }
  136. function handleSelectXueke(item) {
  137. activeXueke.value = item.id;
  138. }
  139. </script>