yingyuNew.vue 6.6 KB

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