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 v-if="options.number ==1 && item.firstFlag ==1" class="brand-icon">{{ item.number }} </view>
  23. <!-- 锁 -->
  24. <view v-else 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. <!-- 序号 -->
  32. <view class="brand-icon">{{ item.number }} </view>
  33. <!-- 锁 -->
  34. <view v-if="options.number !='1' || item.type==2" class="brand-lock"></view>
  35. <!-- 箭头 -->
  36. <view v-if="item.daeFlag && animalNum == index &&isVip != 'Visitor'" class="brand-arrow"> </view>
  37. <!-- 节名称 -->
  38. <view class="brand-content"><text>{{ item.jieName }}</text></view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script setup>
  46. import {
  47. reactive,
  48. ref,
  49. watch,
  50. getCurrentInstance,
  51. onMounted,
  52. nextTick
  53. } from "vue";
  54. import cacheManager from "@/utils/cacheManager.js";
  55. import {
  56. toast,
  57. getUserIdentity
  58. } from "@/utils/common";
  59. import {
  60. onShow
  61. } from '@dcloudio/uni-app';
  62. const growthType = ref(null);
  63. const growthImg = ref(null);
  64. onShow(() => {
  65. growthType.value = cacheManager.get('auth') ? cacheManager.get('auth').growthType : null;
  66. growthImg.value = cacheManager.get('auth') ? cacheManager.get('zhangInfo').icon : null;
  67. })
  68. const $emit = defineEmits(['clickGradeTerm', 'onLeft', 'onRight', 'handleCheckCatalogue', 'listClick'])
  69. const props = defineProps({
  70. options: {
  71. type: Object,
  72. },
  73. gradeTerm: {
  74. type: String,
  75. },
  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. function currentGrowth(data) {
  117. if (growthType.value == 0) {
  118. return 'animal-img dan-img'
  119. } else if (growthType.value == 1) {
  120. return 'animal-img xiao-e-img'
  121. } else if (growthType.value == 2) {
  122. return 'animal-img zhong-e-img'
  123. } else {
  124. return 'animal-img da-e-img'
  125. }
  126. }
  127. // 章换行显示
  128. function getZhangContent(data) {
  129. let length = data.length;
  130. // 初始将字符串平分成两半
  131. let halfLength = Math.floor(length / 2);
  132. // 插入换行符
  133. let firstLine = data.slice(0, halfLength);
  134. let secondLine = data.slice(halfLength);
  135. //console.log(firstLine + '\n' + secondLine, 'firstLine + + secondLine');
  136. return firstLine + '\n' + secondLine;
  137. }
  138. // 获取节class
  139. function getClass(data, index, isVip,item) {
  140. let brandActive = '';
  141. if (isVip === 'VIP') {
  142. brandActive = 'brand-active';
  143. } else if (data.number == 1&&item.firstFlag==1 && isVip =='Not-Vip') {
  144. brandActive = 'brand-active';
  145. } else if (data.number == 1&&item.firstFlag==1 && isVip =='Visitor' &&item.type ==1) {
  146. brandActive = 'brand-active';
  147. } else {
  148. brandActive = '';
  149. }
  150. return brandActive
  151. }
  152. function handleCheckCatalogue() {
  153. $emit('handleCheckCatalogue');
  154. }
  155. function onTouchStart(event) {
  156. console.log(event.touches.length);
  157. isSliding.value = false
  158. if (event.touches.length === 1) {
  159. isSliding.value = true;
  160. startX.value = event.touches[0].pageX;
  161. } else {
  162. isSliding.value = false;
  163. event.preventDefault()
  164. return
  165. }
  166. }
  167. function onSwipeLeft(event) {
  168. console.log('11111');
  169. if (cacheManager.get('auth')) {
  170. $emit('onLeft');
  171. }
  172. }
  173. function onSwipeRight(event) {
  174. console.log('22222');
  175. console.log(cacheManager.get('auth'));
  176. if (cacheManager.get('auth')) {
  177. console.log('啊啊啊啊啊');
  178. $emit('onRight');
  179. }
  180. }
  181. function onTouchEnd(event) {
  182. if (isSliding.value) {
  183. const distanceX = event.changedTouches[0].clientX - startX.value
  184. if (distanceX > 200) {
  185. onSwipeLeft();
  186. } else if (distanceX < -200) {
  187. onSwipeRight();
  188. }
  189. isSliding.value = false
  190. } else {
  191. console.log('error');
  192. }
  193. }
  194. function dataRecom(data) {
  195. const index = data.jieList.findIndex(item => item.studyFlag == 0);
  196. if (index !== -1) {
  197. data.jieList[index].daeFlag = true;
  198. animalNum.value = index
  199. }
  200. }
  201. watch(() => props.options, (newVal, oldVal) => {
  202. // console.log('New options:', newVal);
  203. // console.log('Old options:', oldVal);
  204. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  205. dataRecom(newVal)
  206. }, {
  207. deep: true,
  208. immediate: true
  209. });
  210. watch(() => props.gradeTerm, (newVal, oldVal) => {
  211. // console.log('New options:', newVal);
  212. // console.log('Old options:', oldVal);
  213. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  214. gradeTerm.value = newVal
  215. }, {
  216. deep: true,
  217. immediate: true
  218. });
  219. </script>
  220. <style>
  221. </style>