yingyuNew.vue 6.4 KB

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