shuxue.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 from "@/utils/cacheManager.js";
  38. const $emit = defineEmits(['clickGradeTerm', 'onLeft', 'onRight', 'handleCheckCatalogue'])
  39. const props = defineProps({
  40. options: {
  41. type: Object,
  42. },
  43. })
  44. const gradeMapping = {
  45. 1: '一年级',
  46. 2: '二年级',
  47. 3: '三年级',
  48. 4: '四年级',
  49. 5: '五年级',
  50. 6: '六年级'
  51. };
  52. const termMapping = {
  53. 1: '数学',
  54. 2: '英语'
  55. };
  56. let startX = ref(0);
  57. let isSliding = ref(false);
  58. let endX = ref(0);
  59. let gradeTerm = ref('');
  60. function clickGradeTerm() {
  61. $emit('clickGradeTerm');
  62. }
  63. function translateData(data) {
  64. return gradeMapping[data.nianji] + termMapping[data.cardId]
  65. }
  66. function handleCheckCatalogue() {
  67. $emit('handleCheckCatalogue');
  68. }
  69. function onTouchStart(event) {
  70. console.log(event.touches.length);
  71. isSliding.value = false
  72. if (event.touches.length === 1) {
  73. isSliding.value = true;
  74. startX.value = event.touches[0].pageX;
  75. } else {
  76. isSliding.value = false;
  77. event.preventDefault()
  78. return
  79. }
  80. }
  81. function onSwipeLeft(event) {
  82. console.log('11111');
  83. if (cacheManager.get('auth')) {
  84. $emit('onLeft');
  85. }
  86. }
  87. function onSwipeRight(event) {
  88. console.log('22222');
  89. if (cacheManager.get('auth')) {
  90. $emit('onRight');
  91. }
  92. }
  93. function onTouchEnd(event) {
  94. if (isSliding.value) {
  95. const distanceX = event.changedTouches[0].clientX - startX.value
  96. if (distanceX > 0) {
  97. onSwipeLeft();
  98. } else if (distanceX < 0) {
  99. onSwipeRight();
  100. }
  101. isSliding.value = false
  102. } else {
  103. console.log('error');
  104. }
  105. }
  106. watch(() => props.options, (newVal, oldVal) => {
  107. console.log('New options:', newVal);
  108. console.log('Old options:', oldVal);
  109. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  110. gradeTerm.value = translateData(newVal);
  111. }, {
  112. deep: true,
  113. immediate: true
  114. });
  115. </script>
  116. <style>
  117. </style>