shuxueNew.vue 6.1 KB

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