shuxue.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view>
  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 class="chapter-title-box">{{options.zhangName}}</view>
  7. <view>
  8. <view class="brand-item" v-for="(item, index) in options.jieList" :key="item.jieId"
  9. @click="listClick(item, index)" :class="{ 'brand-active': index === 0 }">
  10. <view class="brand-icon">
  11. <template v-if="item.vipFlag">{{ index + 1 }}</template>
  12. <template v-else-if="index === 0">1</template>
  13. </view>
  14. <view class="brand-lock" v-if="item.vipFlag==0 && index !== 0"></view>
  15. <view class="brand-growth">
  16. <template v-if="item.vipFlag ==1">
  17. <template v-if="item.growth === 0">蛋</template>
  18. <template v-else-if="item.growth === 10">小鹅</template>
  19. <template v-else-if="item.growth === 20">中鹅</template>
  20. <template v-else-if="item.growth === 50">大鹅</template>
  21. </template>
  22. </view>
  23. <view class="brand-content">{{ item.jieName }}</view>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script setup>
  30. import {
  31. reactive,
  32. ref,
  33. watch,
  34. getCurrentInstance,
  35. onMounted
  36. } from "vue";
  37. import cacheManager ,{useXuekeNianji}from "@/utils/cacheManager.js";
  38. const {
  39. updateXueke,
  40. getXueke
  41. } = useXuekeNianji();
  42. const $emit = defineEmits(['clickGradeTerm', 'onLeft', 'onRight', 'handleCheckCatalogue'])
  43. const props = defineProps({
  44. options: {
  45. type: Object,
  46. },
  47. })
  48. const gradeMapping = {
  49. 1: '一年级',
  50. 2: '二年级',
  51. 3: '三年级',
  52. 4: '四年级',
  53. 5: '五年级',
  54. 6: '六年级'
  55. };
  56. const termMapping = {
  57. 1: '数学',
  58. 2: '英语'
  59. };
  60. let startX = ref(0);
  61. let isSliding = ref(false);
  62. let endX = ref(0);
  63. let gradeTerm = ref('');
  64. function clickGradeTerm() {
  65. $emit('clickGradeTerm');
  66. }
  67. function translateData(data) {
  68. return gradeMapping[data.nianji] + termMapping[data.cardId]
  69. }
  70. function handleCheckCatalogue() {
  71. $emit('handleCheckCatalogue');
  72. }
  73. function onTouchStart(event) {
  74. console.log(event.touches.length);
  75. isSliding.value = false
  76. if (event.touches.length === 1) {
  77. isSliding.value = true;
  78. startX.value = event.touches[0].pageX;
  79. } else {
  80. isSliding.value = false;
  81. event.preventDefault()
  82. return
  83. }
  84. }
  85. function onSwipeLeft(event) {
  86. console.log('11111');
  87. if (cacheManager.get('auth')) {
  88. $emit('onLeft');
  89. }
  90. }
  91. function onSwipeRight(event) {
  92. console.log('22222');
  93. if (cacheManager.get('auth')) {
  94. $emit('onRight');
  95. }
  96. }
  97. function onTouchEnd(event) {
  98. if (isSliding.value) {
  99. const distanceX = event.changedTouches[0].clientX - startX.value
  100. if (distanceX > 0) {
  101. onSwipeLeft();
  102. } else if (distanceX < 0) {
  103. onSwipeRight();
  104. }
  105. isSliding.value = false
  106. } else {
  107. console.log('error');
  108. }
  109. }
  110. watch(() => props.options, (newVal, oldVal) => {
  111. console.log('New options:', newVal);
  112. console.log('Old options:', oldVal);
  113. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  114. gradeTerm.value = translateData(newVal);
  115. }, {
  116. deep: true,
  117. immediate: true
  118. });
  119. </script>
  120. <style>
  121. </style>