yingyuNew.vue 6.6 KB

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