index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. const comingSoonDialogRef = ref(null);
  43. function useSelectGrade() {
  44. const userCode = getUserIdentity();
  45. const data = reactive({
  46. activeNianji: null, // 当前年级
  47. activeXueke: null, // 当前学期
  48. activeTipFlag: null, // 当前学期
  49. });
  50. onLoad(({nianji,cardId,tipFlag}) => {
  51. // comingSoonDialogRef.value.handleShow();
  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. goDAOToStudy();
  84. }
  85. // 跳转 岛 学习
  86. function goDAOToStudy() {
  87. if (userCode !== 'Visitor') {
  88. const auth = cacheManager.get('auth');
  89. cacheManager.updateObject('auth', {
  90. nianji: data.activeNianji,
  91. zhangId: data.activeNianji == auth.nianji && data.activeXueke == auth.cardId ? auth.zhangId: 0,
  92. cardId: data.activeXueke,
  93. currentZhang: 0
  94. })
  95. cacheManager.remove('daoPageCache')
  96. // 数序
  97. uni.redirectTo({
  98. url: `/pages/study/index`
  99. })
  100. } else {
  101. // 数序
  102. uni.redirectTo({
  103. url: `/pages/study/index?nianji=${data.activeNianji}&cardId=${data.activeXueke}&zhangId=0&tipFlag=${data.activeTipFlag}`
  104. })
  105. }
  106. }
  107. function handleBack() {
  108. if (userCode !== 'Visitor') {
  109. uni.redirectTo({ url: `/pages/study/index`})
  110. } else {
  111. uni.redirectTo({url: '/pages/login/index'})
  112. }
  113. }
  114. return {
  115. ...toRefs(data),
  116. handleBack,
  117. // 方法
  118. handleConfirm, // 选择年级+学科
  119. };
  120. }
  121. const {
  122. activeNianji,
  123. activeXueke,
  124. handleConfirm,
  125. handleBack
  126. } = useSelectGrade()
  127. function handleSelectGrade(item) {
  128. activeNianji.value = item.id;
  129. }
  130. function handleSelectXueke(item) {
  131. activeXueke.value = item.id;
  132. }
  133. </script>