shuxue.vue 6.5 KB

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