yingyu.vue 7.1 KB

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