shuxue.vue 7.1 KB

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