yingyu.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="ezy-study-page ezy-yingyu-study-page">
  3. <view class="study-school-year" @click="clickGradeTerm">{{gradeTerm}}</view>
  4. <view class="ezy-study-wrap" @touchstart="onTouchStart" @touchend="onTouchEnd">
  5. <view class="yingyu-house-box">
  6. <view @click="handleCheckCatalogue" class="chapter-title-box">{{options.zhangName}}</view>
  7. </view>
  8. <view>
  9. <!-- 小岛 -->
  10. <view class="brand-item" v-for="(item, index) in options.jieList" :key="item.jieId"
  11. @click="listClick(item, index)" :class="getClass(options.jieList,index,isVip)">
  12. <view v-if="isVip === 'VIP'">
  13. <!-- 星星 -->
  14. <view class="brand-finish-icon" v-if="item.studyFlag===1"></view>
  15. <!-- 动物类型 -->
  16. <view v-if="item.daeFlag && growthType ==0" class="animal-img dan-img"></view>
  17. <view v-if="item.daeFlag && growthType ==1" class="animal-img xiao-e-img"></view>
  18. <view v-if="item.daeFlag && growthType ==2" class="animal-img zhong-e-img"></view>
  19. <view v-if="item.daeFlag && growthType ==3" class="animal-img da-e-img"></view>
  20. <view class="icon-content-box">
  21. <!-- 序号 -->
  22. <view class="brand-icon" v-if="item.studyFlag===0">{{ item.number }}</view>
  23. <!-- 节名称 -->
  24. <view class="brand-content">{{ item.jieName }}</view>
  25. </view>
  26. </view>
  27. <view v-if="isVip !== 'VIP'">
  28. <!-- 锁 -->
  29. <view v-if="item.firstFlag !='1'" class="brand-lock"></view>
  30. <!-- 动物类型 -->
  31. <view v-if="item.daeFlag && growthType ==0" class="animal-img dan-img"></view>
  32. <view v-if="item.daeFlag && growthType ==1" class="animal-img xiao-e-img"></view>
  33. <view v-if="item.daeFlag && growthType ==2" class="animal-img zhong-e-img"></view>
  34. <view v-if="item.daeFlag && growthType ==3" class="animal-img da-e-img"></view>
  35. <view class="icon-content-box">
  36. <!-- 序号 -->
  37. <view class="brand-icon">{{ item.number }}</view>
  38. <!-- 节名称 -->
  39. <view class="brand-content"> {{ item.jieName }} </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script setup>
  48. import {
  49. reactive,
  50. ref,
  51. watch,
  52. getCurrentInstance,
  53. onMounted
  54. } from "vue";
  55. import cacheManager from "@/utils/cacheManager.js";
  56. import {
  57. toast,
  58. getUserIdentity
  59. } from "@/utils/common";
  60. const $emit = defineEmits(['clickGradeTerm', 'onLeft', 'onRight', 'handleCheckCatalogue', 'listClick'])
  61. const props = defineProps({
  62. options: {
  63. type: Object,
  64. },
  65. })
  66. const isVip = getUserIdentity();
  67. const growthType = cacheManager.get('auth').growthType;
  68. const gradeMapping = {
  69. 1: '一年级',
  70. 2: '二年级',
  71. 3: '三年级',
  72. 4: '四年级',
  73. 5: '五年级',
  74. 6: '六年级'
  75. };
  76. const termMapping = {
  77. 1: ' 数学',
  78. 2: ' 英语'
  79. };
  80. let startX = ref(0);
  81. let isSliding = ref(false);
  82. let endX = ref(0);
  83. let gradeTerm = ref('');
  84. function clickGradeTerm() {
  85. $emit('clickGradeTerm');
  86. }
  87. function listClick(data) {
  88. $emit('listClick', data);
  89. }
  90. // 章换行显示
  91. function getZhangContent(data){
  92. console.log(data.length,'data.length');
  93. let length = data.length;
  94. // 初始将字符串平分成两半
  95. let halfLength = Math.floor(length / 2);
  96. // 插入换行符
  97. let firstLine = data.slice(0, halfLength);
  98. let secondLine = data.slice(halfLength);
  99. console.log(firstLine + '\n' + secondLine,'firstLine + + secondLine');
  100. return firstLine + '\n' + secondLine;
  101. }
  102. // 获取节class
  103. function getClass (data,index,isVip){
  104. let brandActive = '';
  105. if(isVip==='VIP'){
  106. brandActive = 'brand-active';
  107. }else if(index===0){
  108. brandActive = 'brand-active';
  109. }else{
  110. brandActive = '';
  111. }
  112. let indexLast = data.length -1;
  113. // 判断最后一个为名称是否为单元测试,是单元测试则返回ceshi-jie
  114. if(index===indexLast && data[data.length -1].jieName =='Testing'){
  115. return 'ceshi-brand-item' +' '+ brandActive;
  116. }else{
  117. return brandActive;
  118. }
  119. }
  120. function translateData(data) {
  121. return gradeMapping[data.nianji] + termMapping[data.cardId]
  122. }
  123. function handleCheckCatalogue() {
  124. $emit('handleCheckCatalogue');
  125. }
  126. function onTouchStart(event) {
  127. console.log(event.touches.length);
  128. isSliding.value = false
  129. if (event.touches.length === 1) {
  130. isSliding.value = true;
  131. startX.value = event.touches[0].pageX;
  132. } else {
  133. isSliding.value = false;
  134. event.preventDefault()
  135. return
  136. }
  137. }
  138. function onSwipeLeft(event) {
  139. console.log('11111');
  140. if (cacheManager.get('auth')) {
  141. $emit('onLeft');
  142. }
  143. }
  144. function onSwipeRight(event) {
  145. console.log('22222');
  146. if (cacheManager.get('auth')) {
  147. $emit('onRight');
  148. }
  149. }
  150. function onTouchEnd(event) {
  151. if (isSliding.value) {
  152. const distanceX = event.changedTouches[0].clientX - startX.value
  153. if (distanceX > 0) {
  154. onSwipeLeft();
  155. } else if (distanceX < 0) {
  156. onSwipeRight();
  157. }
  158. isSliding.value = false
  159. } else {
  160. console.log('error');
  161. }
  162. }
  163. function dataRecom(data){
  164. if(data&&data.jieList.length>0){
  165. data.jieList.some(item => {
  166. if (item.studyFlag == 0) {
  167. item.daeFlag = true;
  168. return true; // 返回 true 以终止 some 循环
  169. }
  170. return false;
  171. });
  172. }
  173. }
  174. watch(() => props.options, (newVal, oldVal) => {
  175. // console.log('New options:', newVal);
  176. // console.log('Old options:', oldVal);
  177. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  178. gradeTerm.value = translateData(newVal);
  179. dataRecom(newVal)
  180. }, {
  181. deep: true,
  182. immediate: true
  183. });
  184. </script>
  185. <style>
  186. </style>