yingyu.vue 5.6 KB

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