yingyu.vue 6.2 KB

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