shuxueNew.vue 5.7 KB

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