yingyu.vue 6.2 KB

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