shuxue.vue 3.7 KB

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