shuxue.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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="{ 'brand-active': index === 0 }">
  10. <view 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 translateData(data) {
  73. return gradeMapping[data.nianji] + termMapping[data.cardId]
  74. }
  75. function handleCheckCatalogue() {
  76. $emit('handleCheckCatalogue');
  77. }
  78. function onTouchStart(event) {
  79. console.log(event.touches.length);
  80. isSliding.value = false
  81. if (event.touches.length === 1) {
  82. isSliding.value = true;
  83. startX.value = event.touches[0].pageX;
  84. } else {
  85. isSliding.value = false;
  86. event.preventDefault()
  87. return
  88. }
  89. }
  90. function onSwipeLeft(event) {
  91. console.log('11111');
  92. if (cacheManager.get('auth')) {
  93. $emit('onLeft');
  94. }
  95. }
  96. function onSwipeRight(event) {
  97. console.log('22222');
  98. if (cacheManager.get('auth')) {
  99. $emit('onRight');
  100. }
  101. }
  102. function onTouchEnd(event) {
  103. if (isSliding.value) {
  104. const distanceX = event.changedTouches[0].clientX - startX.value
  105. if (distanceX > 0) {
  106. onSwipeLeft();
  107. } else if (distanceX < 0) {
  108. onSwipeRight();
  109. }
  110. isSliding.value = false
  111. } else {
  112. console.log('error');
  113. }
  114. }
  115. function dataRecom(data){
  116. if(data&&data.jieList.length>0){
  117. data.jieList.some(item => {
  118. if (item.studyFlag == 0) {
  119. item.daeFlag = true;
  120. return true; // 返回 true 以终止 some 循环
  121. }
  122. return false;
  123. });
  124. }
  125. console.log(data);
  126. console.log("1111");
  127. }
  128. watch(() => props.options, (newVal, oldVal) => {
  129. console.log('New options:', newVal);
  130. console.log('Old options:', oldVal);
  131. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  132. gradeTerm.value = translateData(newVal);
  133. dataRecom(newVal)
  134. }, {
  135. deep: true,
  136. immediate: true
  137. });
  138. </script>
  139. <style>
  140. </style>