shuxue.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view>
  3. <view class="study-school-year" @click="clickGradeTerm">{{gradeTerm}}</view>
  4. <view class="ezy-study-wrap" @touchstart="onTouchStart" @touchend="onTouchEnd">
  5. <view class="chapter-box" @click="handleCheckCatalogue">{{options.numberStr}}</view>
  6. <view class="chapter-title-box">{{options.zhangName}}</view>
  7. <view>
  8. <view class="brand-item" v-for="(item, index) in options.jieList" :key="item.jieId"
  9. @click="listClick(item, index)" :class="getClass(options.jieList,index)">
  10. <view v-if="isVip === 'VIP'" class="brand-icon">
  11. {{ item.number }}
  12. <view v-if="item.daeFlag">
  13. <template v-if="growthType ==0">蛋</template>
  14. <template v-if="growthType ==1">小鹅</template>
  15. <template v-if="growthType ==2">中鹅</template>
  16. <template v-if="growthType ==3">大鹅</template>
  17. </view>
  18. <view class="brand-content">
  19. {{ item.jieName }}
  20. </view>
  21. </view>
  22. <view v-if="isVip !== 'VIP'">
  23. <view v-if="item.number ==1" class="brand-icon">{{ item.number }}</view>
  24. <view v-if="item.number !=1" class="brand-lock">{{ item.number }}</view>
  25. <view v-if="item.daeFlag">
  26. <template v-if="growthType ==0">蛋</template>
  27. <template v-if="growthType ==1">小鹅</template>
  28. <template v-if="growthType ==2">中鹅</template>
  29. <template v-if="growthType ==3">大鹅</template>
  30. </view>
  31. <view class="brand-content">
  32. {{ item.jieName }}
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script setup>
  41. import {
  42. reactive,
  43. ref,
  44. watch,
  45. getCurrentInstance,
  46. onMounted
  47. } from "vue";
  48. import cacheManager from "@/utils/cacheManager.js";
  49. import {
  50. toast,
  51. getUserIdentity
  52. } from "@/utils/common";
  53. const $emit = defineEmits(['clickGradeTerm', 'onLeft', 'onRight', 'handleCheckCatalogue', 'listClick'])
  54. const props = defineProps({
  55. options: {
  56. type: Object,
  57. },
  58. })
  59. const isVip = getUserIdentity();
  60. const growthType = cacheManager.get('auth').growthType;
  61. const gradeMapping = {
  62. 1: '一年级',
  63. 2: '二年级',
  64. 3: '三年级',
  65. 4: '四年级',
  66. 5: '五年级',
  67. 6: '六年级'
  68. };
  69. const termMapping = {
  70. 1: ' 数学',
  71. 2: ' 英语'
  72. };
  73. let startX = ref(0);
  74. let isSliding = ref(false);
  75. let endX = ref(0);
  76. let gradeTerm = ref('');
  77. function clickGradeTerm() {
  78. $emit('clickGradeTerm');
  79. }
  80. function listClick(data) {
  81. $emit('listClick', data);
  82. }
  83. function getClass (data,index){
  84. // 节 4个 且最后一个为单元测试
  85. if(data.length ==4 && data[data.length -1].jieName =='单元测试'){
  86. // if(data[index].jieName.length){
  87. // return 'class1'
  88. // }else{
  89. // return 'class2'
  90. // }
  91. }else{
  92. // if(data[index].jieName.length){
  93. // return 'class3'
  94. // }else{
  95. // return 'class4'
  96. // }
  97. }
  98. }
  99. function translateData(data) {
  100. return gradeMapping[data.nianji] + termMapping[data.cardId]
  101. }
  102. function handleCheckCatalogue() {
  103. $emit('handleCheckCatalogue');
  104. }
  105. function onTouchStart(event) {
  106. console.log(event.touches.length);
  107. isSliding.value = false
  108. if (event.touches.length === 1) {
  109. isSliding.value = true;
  110. startX.value = event.touches[0].pageX;
  111. } else {
  112. isSliding.value = false;
  113. event.preventDefault()
  114. return
  115. }
  116. }
  117. function onSwipeLeft(event) {
  118. console.log('11111');
  119. if (cacheManager.get('auth')) {
  120. $emit('onLeft');
  121. }
  122. }
  123. function onSwipeRight(event) {
  124. console.log('22222');
  125. if (cacheManager.get('auth')) {
  126. $emit('onRight');
  127. }
  128. }
  129. function onTouchEnd(event) {
  130. if (isSliding.value) {
  131. const distanceX = event.changedTouches[0].clientX - startX.value
  132. if (distanceX > 0) {
  133. onSwipeLeft();
  134. } else if (distanceX < 0) {
  135. onSwipeRight();
  136. }
  137. isSliding.value = false
  138. } else {
  139. console.log('error');
  140. }
  141. }
  142. function dataRecom(data){
  143. if(data&&data.jieList.length>0){
  144. data.jieList.some(item => {
  145. if (item.studyFlag == 0) {
  146. item.daeFlag = true;
  147. return true; // 返回 true 以终止 some 循环
  148. }
  149. return false;
  150. });
  151. }
  152. }
  153. watch(() => props.options, (newVal, oldVal) => {
  154. // console.log('New options:', newVal);
  155. // console.log('Old options:', oldVal);
  156. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  157. gradeTerm.value = translateData(newVal);
  158. dataRecom(newVal)
  159. }, {
  160. deep: true,
  161. immediate: true
  162. });
  163. </script>
  164. <style>
  165. </style>