shuxue.vue 2.9 KB

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