shuxueNew.vue 6.2 KB

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