yingyu.vue 5.5 KB

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