yingyuNew.vue 6.7 KB

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