shuxue.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. const gradeMapping = {
  68. 1: '一年级',
  69. 2: '二年级',
  70. 3: '三年级',
  71. 4: '四年级',
  72. 5: '五年级',
  73. 6: '六年级'
  74. };
  75. const termMapping = {
  76. 1: ' 数学',
  77. 2: ' 英语'
  78. };
  79. let startX = ref(0);
  80. let isSliding = ref(false);
  81. let endX = ref(0);
  82. let gradeTerm = ref('');
  83. let animalNum = ref(0);
  84. function clickGradeTerm() {
  85. $emit('clickGradeTerm');
  86. }
  87. function listClick(data, index) {
  88. data.daeFlag = true
  89. nextTick(() => {
  90. animalNum.value = index
  91. })
  92. setTimeout(() => {
  93. $emit('listClick', data);
  94. }, 1000)
  95. }
  96. // 获取章name
  97. function getZhangName(data) {
  98. if (data.length <= 9) {
  99. return data
  100. } else {
  101. return getZhangContent(data);
  102. }
  103. }
  104. function currentGrowth(data) {
  105. if (growthType.value == 0) {
  106. return 'animal-img dan-img'
  107. } else if (growthType.value == 2) {
  108. return 'animal-img xiao-e-img'
  109. } else if (growthType.value == 3) {
  110. return 'animal-img zhong-e-img'
  111. } else {
  112. return 'animal-img da-e-img'
  113. }
  114. }
  115. // 章换行显示
  116. function getZhangContent(data) {
  117. let length = data.length;
  118. // 初始将字符串平分成两半
  119. let halfLength = Math.floor(length / 2);
  120. // 插入换行符
  121. let firstLine = data.slice(0, halfLength);
  122. let secondLine = data.slice(halfLength);
  123. //console.log(firstLine + '\n' + secondLine, 'firstLine + + secondLine');
  124. return firstLine + '\n' + secondLine;
  125. }
  126. // 章class
  127. function getTitleClass(data) {
  128. if (data.length <= 5) {
  129. return 'chapter-title-box chapter-small-title-box'
  130. } else if (data.length <= 9) {
  131. return 'chapter-title-box chapter-middle-title-box'
  132. } else if (data.length > 9) {
  133. return 'chapter-title-box chapter-big-title-box'
  134. }
  135. }
  136. // 获取节class
  137. function getClass(data, index, isVip) {
  138. let brandActive = '';
  139. if (isVip === 'VIP') {
  140. brandActive = 'brand-active';
  141. } else if (data[index].firstFlag == 1) {
  142. brandActive = 'brand-active';
  143. } else {
  144. brandActive = '';
  145. }
  146. let indexLast = data.length - 1;
  147. // 判断最后一个为名称是否为单元测试,是单元测试则返回ceshi-jie
  148. if (index === indexLast && data[data.length - 1].jieName == '单元测试') {
  149. return 'ceshi-brand-item' + ' ' + brandActive;
  150. } else {
  151. return getJieClass(data, index, brandActive)
  152. }
  153. }
  154. // 根据获取节字数获取class
  155. function getJieClass(data, index, active) {
  156. let itemJieName = data[index].jieName.length;
  157. if (itemJieName > 7) {
  158. return 'big-brand-item' + ' ' + active;
  159. } else {
  160. return 'small-brand-item' + ' ' + active;
  161. }
  162. }
  163. function handleCheckCatalogue() {
  164. $emit('handleCheckCatalogue');
  165. }
  166. function onTouchStart(event) {
  167. console.log(event.touches.length);
  168. isSliding.value = false
  169. if (event.touches.length === 1) {
  170. isSliding.value = true;
  171. startX.value = event.touches[0].pageX;
  172. } else {
  173. isSliding.value = false;
  174. event.preventDefault()
  175. return
  176. }
  177. }
  178. function onSwipeLeft(event) {
  179. console.log('11111');
  180. if (cacheManager.get('auth')) {
  181. $emit('onLeft');
  182. }
  183. }
  184. function onSwipeRight(event) {
  185. console.log('22222');
  186. console.log(cacheManager.get('auth'));
  187. if (cacheManager.get('auth')) {
  188. console.log('啊啊啊啊啊');
  189. $emit('onRight');
  190. }
  191. }
  192. function onTouchEnd(event) {
  193. if (isSliding.value) {
  194. const distanceX = event.changedTouches[0].clientX - startX.value
  195. if (distanceX > 200) {
  196. onSwipeLeft();
  197. } else if (distanceX < -200) {
  198. onSwipeRight();
  199. }
  200. isSliding.value = false
  201. } else {
  202. console.log('error');
  203. }
  204. }
  205. function dataRecom(data) {
  206. // if (data && data.jieList.length > 0) {
  207. // data.jieList.some(item => {
  208. // if (item.studyFlag == 0) {
  209. // item.daeFlag = true;
  210. // animalNum.value
  211. // return true; // 返回 true 以终止 some 循环
  212. // }
  213. // return false;
  214. // });
  215. // }
  216. const index = data.jieList.findIndex(item => item.studyFlag == 0);
  217. if (index !== -1) {
  218. data.jieList[index].daeFlag = true;
  219. animalNum.value = index
  220. }
  221. }
  222. watch(() => props.options, (newVal, oldVal) => {
  223. // console.log('New options:', newVal);
  224. // console.log('Old options:', oldVal);
  225. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  226. dataRecom(newVal)
  227. }, {
  228. deep: true,
  229. immediate: true
  230. });
  231. watch(() => props.gradeTerm, (newVal, oldVal) => {
  232. // console.log('New options:', newVal);
  233. // console.log('Old options:', oldVal);
  234. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  235. gradeTerm.value = newVal
  236. }, {
  237. deep: true,
  238. immediate: true
  239. });
  240. </script>
  241. <style>
  242. </style>