shuxue.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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" @touchstart="onTouchStart" @touchend="onTouchEnd">
  5. <view class="chapter-box" @click="handleCheckCatalogue">{{options.numberStr}}</view>
  6. <view @click="handleCheckCatalogue" :class="getTitleClass(options.zhangName)">{{getZhangName(options.zhangName)}}</view>
  7. <view>
  8. <!-- 小岛 -->
  9. <view class="brand-item" v-for="(item, index) in options.jieList" :key="item.jieId"
  10. @click="listClick(item, index)" :class="getClass(options.jieList,index,isVip)">
  11. <view v-if="isVip === 'VIP'">
  12. <!-- 序号 -->
  13. <view class="brand-icon" v-if="item.studyFlag===0">{{ item.number }}</view>
  14. <!-- 星星 -->
  15. <view class="brand-finish-icon" v-if="item.studyFlag===1"></view>
  16. <!-- 动物类型 -->
  17. <view v-if="item.daeFlag && growthType ==0" class="animal-img dan-img"></view>
  18. <view v-if="item.daeFlag && growthType ==1" class="animal-img xiao-e-img"></view>
  19. <view v-if="item.daeFlag && growthType ==2" class="animal-img zhong-e-img"></view>
  20. <view v-if="item.daeFlag && growthType ==3" class="animal-img da-e-img"></view>
  21. <!-- 节名称 -->
  22. <view class="brand-content">{{ item.jieName }}</view>
  23. </view>
  24. <view v-if="isVip !== 'VIP'">
  25. <!-- 序号或锁 -->
  26. <view v-if="item.firstFlag ==1" class="brand-icon">{{ item.number }}</view>
  27. <view v-if="item.firstFlag !=1" class="brand-lock"></view>
  28. <!-- 动物类型 -->
  29. <view v-if="item.daeFlag && growthType ==0" class="animal-img dan-img"></view>
  30. <view v-if="item.daeFlag && growthType ==1" class="animal-img xiao-e-img"></view>
  31. <view v-if="item.daeFlag && growthType ==2" class="animal-img zhong-e-img"></view>
  32. <view v-if="item.daeFlag && growthType ==3" class="animal-img da-e-img"></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. } 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. })
  65. const isVip = getUserIdentity();
  66. const gradeMapping = {
  67. 1: '一年级',
  68. 2: '二年级',
  69. 3: '三年级',
  70. 4: '四年级',
  71. 5: '五年级',
  72. 6: '六年级'
  73. };
  74. const termMapping = {
  75. 1: ' 数学',
  76. 2: ' 英语'
  77. };
  78. let startX = ref(0);
  79. let isSliding = ref(false);
  80. let endX = ref(0);
  81. let gradeTerm = ref('');
  82. function clickGradeTerm() {
  83. $emit('clickGradeTerm');
  84. }
  85. function listClick(data) {
  86. $emit('listClick', data);
  87. }
  88. // 获取章name
  89. function getZhangName(data){
  90. if(data.length <=9){
  91. return data
  92. }else{
  93. return getZhangContent(data);
  94. }
  95. }
  96. // 章换行显示
  97. function getZhangContent(data){
  98. console.log(data.length,'data.length');
  99. let length = data.length;
  100. // 初始将字符串平分成两半
  101. let halfLength = Math.floor(length / 2);
  102. // 插入换行符
  103. let firstLine = data.slice(0, halfLength);
  104. let secondLine = data.slice(halfLength);
  105. console.log(firstLine + '\n' + secondLine,'firstLine + + secondLine');
  106. return firstLine + '\n' + secondLine;
  107. }
  108. // 章class
  109. function getTitleClass(data){
  110. console.log(data.length,'getTitleClass');
  111. if(data.length <=5){
  112. return 'chapter-title-box chapter-small-title-box'
  113. }else if(data.length <=9){
  114. return 'chapter-title-box chapter-middle-title-box'
  115. }else if(data.length >9){
  116. return 'chapter-title-box chapter-big-title-box'
  117. }
  118. }
  119. // 获取节class
  120. function getClass (data,index,isVip){
  121. let brandActive = '';
  122. if(isVip==='VIP'){
  123. brandActive = 'brand-active';
  124. }else if(index===0){
  125. brandActive = 'brand-active';
  126. }else{
  127. brandActive = '';
  128. }
  129. let indexLast = data.length -1;
  130. // 判断最后一个为名称是否为单元测试,是单元测试则返回ceshi-jie
  131. if(index===indexLast && data[data.length -1].jieName =='单元测试'){
  132. return 'ceshi-brand-item' +' '+ brandActive;
  133. }else{
  134. return getJieClass(data,index,brandActive)
  135. }
  136. }
  137. // 根据获取节字数获取class
  138. function getJieClass(data,index,active){
  139. let itemJieName = data[index].jieName.length;
  140. if(itemJieName > 7){
  141. return 'big-brand-item' +' '+ active;
  142. }else{
  143. return 'small-brand-item' +' '+ active;
  144. }
  145. }
  146. function translateData(data) {
  147. return gradeMapping[data.nianji] + termMapping[data.cardId]
  148. }
  149. function handleCheckCatalogue() {
  150. $emit('handleCheckCatalogue');
  151. }
  152. function onTouchStart(event) {
  153. console.log(event.touches.length);
  154. isSliding.value = false
  155. if (event.touches.length === 1) {
  156. isSliding.value = true;
  157. startX.value = event.touches[0].pageX;
  158. } else {
  159. isSliding.value = false;
  160. event.preventDefault()
  161. return
  162. }
  163. }
  164. function onSwipeLeft(event) {
  165. console.log('11111');
  166. if (cacheManager.get('auth')) {
  167. $emit('onLeft');
  168. }
  169. }
  170. function onSwipeRight(event) {
  171. console.log('22222');
  172. if (cacheManager.get('auth')) {
  173. $emit('onRight');
  174. }
  175. }
  176. function onTouchEnd(event) {
  177. if (isSliding.value) {
  178. const distanceX = event.changedTouches[0].clientX - startX.value
  179. if (distanceX > 0) {
  180. onSwipeLeft();
  181. } else if (distanceX < 0) {
  182. onSwipeRight();
  183. }
  184. isSliding.value = false
  185. } else {
  186. console.log('error');
  187. }
  188. }
  189. function dataRecom(data){
  190. if(data&&data.jieList.length>0){
  191. data.jieList.some(item => {
  192. if (item.studyFlag == 0) {
  193. item.daeFlag = true;
  194. return true; // 返回 true 以终止 some 循环
  195. }
  196. return false;
  197. });
  198. }
  199. }
  200. watch(() => props.options, (newVal, oldVal) => {
  201. // console.log('New options:', newVal);
  202. // console.log('Old options:', oldVal);
  203. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  204. gradeTerm.value = translateData(newVal);
  205. dataRecom(newVal)
  206. }, {
  207. deep: true,
  208. immediate: true
  209. });
  210. </script>
  211. <style>
  212. </style>