shuxue.vue 6.4 KB

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