yingyuNew.vue 6.6 KB

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