yingyuNew.vue 6.4 KB

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