shuxue.vue 7.2 KB

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