shuxue.vue 6.4 KB

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