yingyu.vue 3.6 KB

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