shuxue.vue 6.1 KB

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