yingyu.vue 5.5 KB

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