shuxue.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <view class="ezy-study-page ezy-shuxue-study-page">
  3. <view class="study-school-year" @click="clickGradeTerm">{{gradeTerm}}</view>
  4. <view class="ezy-study-wrap">
  5. <view class="chapter-box" @click="handleCheckCatalogue">{{options.numberStr}}</view>
  6. <view @click="handleCheckCatalogue" :class="getTitleClass(options.zhangName)">
  7. {{getZhangName(options.zhangName)}}
  8. </view>
  9. <view>
  10. <!-- 小岛 -->
  11. <view class="brand-item" v-for="(item, index) in options.jieList" :key="item.jieId"
  12. @click="listClick(item, index)" :class="getClass(options.jieList,index,isVip)">
  13. <view v-if="isVip === 'VIP'">
  14. <!-- 序号 -->
  15. <view class="brand-icon" v-if="item.studyFlag===0">{{ item.number }}</view>
  16. <!-- 星星 -->
  17. <view class="brand-finish-icon" v-if="item.studyFlag===1"></view>
  18. <!-- 动物类型 -->
  19. <view v-if="item.daeFlag &&animalNum == index" :class="currentGrowth()"></view>
  20. <!-- 节名称 -->
  21. <view class="brand-content">{{ item.jieName }}</view>
  22. </view>
  23. <view v-if="isVip !== 'VIP'">
  24. <!-- 序号或锁 -->
  25. <view v-if="options.number ==1 && item.firstFlag ==1" class="brand-icon">{{ item.number }}
  26. </view>
  27. <view v-else class="brand-lock"></view>
  28. <!-- 动物类型 -->
  29. <view v-if="item.daeFlag && animalNum == index" :class="currentGrowth()"></view>
  30. <!-- 节名称 -->
  31. <view class="brand-content"> {{ item.jieName }} </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script setup>
  39. import {
  40. reactive,
  41. ref,
  42. watch,
  43. getCurrentInstance,
  44. onMounted,
  45. nextTick
  46. } from "vue";
  47. import cacheManager from "@/utils/cacheManager.js";
  48. import {
  49. toast,
  50. getUserIdentity
  51. } from "@/utils/common";
  52. import {
  53. onShow
  54. } from '@dcloudio/uni-app';
  55. const growthType = ref(null);
  56. onShow(() => growthType.value = cacheManager.get('auth').growthType)
  57. const $emit = defineEmits(['clickGradeTerm', 'onLeft', 'onRight', 'handleCheckCatalogue', 'listClick'])
  58. const props = defineProps({
  59. options: {
  60. type: Object,
  61. },
  62. gradeTerm: {
  63. type: String,
  64. },
  65. })
  66. const isVip = getUserIdentity();
  67. console.log('isVip',isVip);
  68. const gradeMapping = {
  69. 1: '一年级',
  70. 2: '二年级',
  71. 3: '三年级',
  72. 4: '四年级',
  73. 5: '五年级',
  74. 6: '六年级'
  75. };
  76. const termMapping = {
  77. 1: ' 数学',
  78. 2: ' 英语'
  79. };
  80. let startX = ref(0);
  81. let isSliding = ref(false);
  82. let endX = ref(0);
  83. let gradeTerm = ref('');
  84. let animalNum = ref(0);
  85. function clickGradeTerm() {
  86. $emit('clickGradeTerm');
  87. }
  88. function listClick(data, index) {
  89. data.daeFlag = true
  90. nextTick(() => {
  91. animalNum.value = index
  92. })
  93. setTimeout(() => {
  94. $emit('listClick', data);
  95. }, 1000)
  96. }
  97. // 获取章name
  98. function getZhangName(data) {
  99. if (data.length <= 9) {
  100. return data
  101. } else {
  102. return getZhangContent(data);
  103. }
  104. }
  105. function currentGrowth(data) {
  106. if (growthType.value == 0) {
  107. return 'animal-img dan-img'
  108. } else if (growthType.value == 2) {
  109. return 'animal-img xiao-e-img'
  110. } else if (growthType.value == 3) {
  111. return 'animal-img zhong-e-img'
  112. } else {
  113. return 'animal-img da-e-img'
  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 getTitleClass(data) {
  129. if (data.length <= 5) {
  130. return 'chapter-title-box chapter-small-title-box'
  131. } else if (data.length <= 9) {
  132. return 'chapter-title-box chapter-middle-title-box'
  133. } else if (data.length > 9) {
  134. return 'chapter-title-box chapter-big-title-box'
  135. }
  136. }
  137. // 获取节class
  138. function getClass(data, index, isVip) {
  139. let brandActive = '';
  140. if (isVip === 'VIP') {
  141. brandActive = 'brand-active';
  142. } else if (data[index].firstFlag == 1) {
  143. brandActive = 'brand-active';
  144. } else {
  145. brandActive = '';
  146. }
  147. let indexLast = data.length - 1;
  148. // 判断最后一个为名称是否为单元测试,是单元测试则返回ceshi-jie
  149. if (index === indexLast && data[data.length - 1].jieName == '单元测试') {
  150. return 'ceshi-brand-item' + ' ' + brandActive;
  151. } else {
  152. return getJieClass(data, index, brandActive)
  153. }
  154. }
  155. // 根据获取节字数获取class
  156. function getJieClass(data, index, active) {
  157. let itemJieName = data[index].jieName.length;
  158. if (itemJieName > 7) {
  159. return 'big-brand-item' + ' ' + active;
  160. } else {
  161. return 'small-brand-item' + ' ' + active;
  162. }
  163. }
  164. function handleCheckCatalogue() {
  165. $emit('handleCheckCatalogue');
  166. }
  167. function onTouchStart(event) {
  168. console.log(event.touches.length);
  169. isSliding.value = false
  170. if (event.touches.length === 1) {
  171. isSliding.value = true;
  172. startX.value = event.touches[0].pageX;
  173. } else {
  174. isSliding.value = false;
  175. event.preventDefault()
  176. return
  177. }
  178. }
  179. function onSwipeLeft(event) {
  180. console.log('11111');
  181. if (cacheManager.get('auth')) {
  182. $emit('onLeft');
  183. }
  184. }
  185. function onSwipeRight(event) {
  186. console.log('22222');
  187. console.log(cacheManager.get('auth'));
  188. if (cacheManager.get('auth')) {
  189. console.log('啊啊啊啊啊');
  190. $emit('onRight');
  191. }
  192. }
  193. function onTouchEnd(event) {
  194. if (isSliding.value) {
  195. const distanceX = event.changedTouches[0].clientX - startX.value
  196. if (distanceX > 200) {
  197. onSwipeLeft();
  198. } else if (distanceX < -200) {
  199. onSwipeRight();
  200. }
  201. isSliding.value = false
  202. } else {
  203. console.log('error');
  204. }
  205. }
  206. function dataRecom(data) {
  207. const index = data.jieList.findIndex(item => item.studyFlag == 0);
  208. if (index !== -1) {
  209. data.jieList[index].daeFlag = true;
  210. animalNum.value = index
  211. }
  212. }
  213. watch(() => props.options, (newVal, oldVal) => {
  214. // console.log('New options:', newVal);
  215. // console.log('Old options:', oldVal);
  216. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  217. dataRecom(newVal)
  218. }, {
  219. deep: true,
  220. immediate: true
  221. });
  222. watch(() => props.gradeTerm, (newVal, oldVal) => {
  223. // console.log('New options:', newVal);
  224. // console.log('Old options:', oldVal);
  225. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  226. gradeTerm.value = newVal
  227. }, {
  228. deep: true,
  229. immediate: true
  230. });
  231. </script>
  232. <style>
  233. </style>