yingyu.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. import {
  61. onShow
  62. } from '@dcloudio/uni-app';
  63. const growthType = ref(null);
  64. onShow(() => growthType.value = cacheManager.get('auth').growthType)
  65. const $emit = defineEmits(['clickGradeTerm', 'onLeft', 'onRight', 'handleCheckCatalogue', 'listClick'])
  66. const props = defineProps({
  67. options: {
  68. type: Object,
  69. },
  70. gradeTerm: {
  71. type: String,
  72. },
  73. })
  74. const isVip = getUserIdentity();
  75. const gradeMapping = {
  76. 1: '一年级',
  77. 2: '二年级',
  78. 3: '三年级',
  79. 4: '四年级',
  80. 5: '五年级',
  81. 6: '六年级'
  82. };
  83. const termMapping = {
  84. 1: ' 数学',
  85. 2: ' 英语'
  86. };
  87. let startX = ref(0);
  88. let isSliding = ref(false);
  89. let endX = ref(0);
  90. let gradeTerm = ref('');
  91. function clickGradeTerm() {
  92. $emit('clickGradeTerm');
  93. }
  94. function listClick(data) {
  95. $emit('listClick', data);
  96. }
  97. // 章换行显示
  98. function getZhangContent(data){
  99. console.log(data.length,'data.length');
  100. let length = data.length;
  101. // 初始将字符串平分成两半
  102. let halfLength = Math.floor(length / 2);
  103. // 插入换行符
  104. let firstLine = data.slice(0, halfLength);
  105. let secondLine = data.slice(halfLength);
  106. console.log(firstLine + '\n' + secondLine,'firstLine + + secondLine');
  107. return firstLine + '\n' + secondLine;
  108. }
  109. // 获取节class
  110. function getClass (data,index,isVip){
  111. let brandActive = '';
  112. if(isVip==='VIP'){
  113. brandActive = 'brand-active';
  114. }else if(data[index].firstFlag==1){
  115. brandActive = 'brand-active';
  116. }else{
  117. brandActive = '';
  118. }
  119. let indexLast = data.length -1;
  120. // 判断最后一个为名称是否为单元测试,是单元测试则返回ceshi-jie
  121. if(index===indexLast && data[data.length -1].jieName =='Testing'){
  122. return 'ceshi-brand-item' +' '+ brandActive;
  123. }else{
  124. return brandActive;
  125. }
  126. }
  127. function handleCheckCatalogue() {
  128. $emit('handleCheckCatalogue');
  129. }
  130. function onTouchStart(event) {
  131. console.log(event.touches.length);
  132. isSliding.value = false
  133. if (event.touches.length === 1) {
  134. isSliding.value = true;
  135. startX.value = event.touches[0].pageX;
  136. } else {
  137. isSliding.value = false;
  138. event.preventDefault()
  139. return
  140. }
  141. }
  142. function onSwipeLeft(event) {
  143. console.log('11111');
  144. if (cacheManager.get('auth')) {
  145. $emit('onLeft');
  146. }
  147. }
  148. function onSwipeRight(event) {
  149. console.log('22222');
  150. if (cacheManager.get('auth')) {
  151. $emit('onRight');
  152. }
  153. }
  154. function onTouchEnd(event) {
  155. if (isSliding.value) {
  156. const distanceX = event.changedTouches[0].clientX - startX.value
  157. if (distanceX > 0) {
  158. onSwipeLeft();
  159. } else if (distanceX < 0) {
  160. onSwipeRight();
  161. }
  162. isSliding.value = false
  163. } else {
  164. console.log('error');
  165. }
  166. }
  167. function dataRecom(data){
  168. if(data&&data.jieList.length>0){
  169. data.jieList.some(item => {
  170. if (item.studyFlag == 0) {
  171. item.daeFlag = true;
  172. return true; // 返回 true 以终止 some 循环
  173. }
  174. return false;
  175. });
  176. }
  177. }
  178. watch(() => props.options, (newVal, oldVal) => {
  179. // console.log('New options:', newVal);
  180. // console.log('Old options:', oldVal);
  181. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  182. dataRecom(newVal)
  183. }, {
  184. deep: true,
  185. immediate: true
  186. });
  187. watch(() => props.gradeTerm, (newVal, oldVal) => {
  188. // console.log('New options:', newVal);
  189. // console.log('Old options:', oldVal);
  190. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  191. gradeTerm.value = newVal
  192. }, {
  193. deep: true,
  194. immediate: true
  195. });
  196. </script>
  197. <style>
  198. </style>