shuxue.vue 3.0 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. $emit('clickGradeTerm');
  61. }
  62. function translateData(data) {
  63. return gradeMapping[data.nianji] + termMapping[data.cardId]
  64. }
  65. function handleCheckCatalogue() {
  66. $emit('handleCheckCatalogue');
  67. }
  68. function onTouchStart(event) {
  69. console.log(event.touches.length);
  70. isSliding.value = false
  71. if (event.touches.length === 1) {
  72. isSliding.value = true;
  73. startX.value = event.touches[0].pageX;
  74. } else {
  75. isSliding.value = false;
  76. event.preventDefault()
  77. return
  78. }
  79. }
  80. function onSwipeLeft(event) {
  81. console.log('11111');
  82. $emit('onLeft');
  83. }
  84. function onSwipeRight(event) {
  85. console.log('22222');
  86. $emit('onRight');
  87. }
  88. function onTouchEnd(event) {
  89. if (isSliding.value) {
  90. const distanceX = event.changedTouches[0].clientX - startX.value
  91. if (distanceX > 0) {
  92. onSwipeLeft();
  93. } else if (distanceX < 0) {
  94. onSwipeRight();
  95. }
  96. isSliding.value = false
  97. } else {
  98. console.log('error');
  99. }
  100. }
  101. watch(() => props.options, (newVal, oldVal) => {
  102. console.log('New options:', newVal);
  103. console.log('Old options:', oldVal);
  104. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  105. gradeTerm.value = translateData(newVal);
  106. }, {
  107. deep: true,
  108. immediate: true
  109. });
  110. </script>
  111. <style>
  112. </style>