index.vue 3.5 KB

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