shuxue.vue 7.2 KB

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