123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <template>
- <view>
- <view class="study-school-year" @click="clickGradeTerm">{{gradeTerm}}</view>
- <view class="ezy-study-wrap" @touchstart="onTouchStart" @touchend="onTouchEnd">
- <view class="chapter-box" @click="handleCheckCatalogue">{{options.numberStr}}</view>
- <view class="chapter-title-box">{{options.zhangName}}</view>
- <view>
-
- <view class="brand-item" v-for="(item, index) in options.jieList" :key="item.jieId"
- @click="listClick(item, index)" :class="getClass(options.jieList,index)">
- <view v-if="isVip === 'VIP'" class="brand-icon">
- {{ item.number }}
- <view v-if="item.daeFlag">
- <template v-if="growthType ==0">蛋</template>
- <template v-if="growthType ==1">小鹅</template>
- <template v-if="growthType ==2">中鹅</template>
- <template v-if="growthType ==3">大鹅</template>
- </view>
- <view class="brand-content">
- {{ item.jieName }}
- </view>
- </view>
- <view v-if="isVip !== 'VIP'">
- <view v-if="item.number ==1" class="brand-icon">{{ item.number }}</view>
- <view v-if="item.number !=1" class="brand-lock">{{ item.number }}</view>
- <view v-if="item.daeFlag">
- <template v-if="growthType ==0">蛋</template>
- <template v-if="growthType ==1">小鹅</template>
- <template v-if="growthType ==2">中鹅</template>
- <template v-if="growthType ==3">大鹅</template>
- </view>
- <view class="brand-content">
- {{ item.jieName }}
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script setup>
- import {
- reactive,
- ref,
- watch,
- getCurrentInstance,
- onMounted
- } from "vue";
- import cacheManager from "@/utils/cacheManager.js";
- import {
- toast,
- getUserIdentity
- } from "@/utils/common";
- const $emit = defineEmits(['clickGradeTerm', 'onLeft', 'onRight', 'handleCheckCatalogue', 'listClick'])
- const props = defineProps({
- options: {
- type: Object,
- },
- })
- const isVip = getUserIdentity();
- const growthType = cacheManager.get('auth').growthType;
- const gradeMapping = {
- 1: '一年级',
- 2: '二年级',
- 3: '三年级',
- 4: '四年级',
- 5: '五年级',
- 6: '六年级'
- };
- const termMapping = {
- 1: ' 数学',
- 2: ' 英语'
- };
- let startX = ref(0);
- let isSliding = ref(false);
- let endX = ref(0);
- let gradeTerm = ref('');
- function clickGradeTerm() {
- $emit('clickGradeTerm');
- }
- function listClick(data) {
- $emit('listClick', data);
- }
- function getClass (data,index){
- // 节 4个 且最后一个为单元测试
- if(data.length ==4 && data[data.length -1].jieName =='单元测试'){
- // if(data[index].jieName.length){
- // return 'class1'
- // }else{
- // return 'class2'
- // }
-
- }else{
- // if(data[index].jieName.length){
- // return 'class3'
- // }else{
- // return 'class4'
- // }
- }
- }
- function translateData(data) {
- return gradeMapping[data.nianji] + termMapping[data.cardId]
- }
- function handleCheckCatalogue() {
- $emit('handleCheckCatalogue');
- }
- function onTouchStart(event) {
- console.log(event.touches.length);
- isSliding.value = false
- if (event.touches.length === 1) {
- isSliding.value = true;
- startX.value = event.touches[0].pageX;
- } else {
- isSliding.value = false;
- event.preventDefault()
- return
- }
- }
- function onSwipeLeft(event) {
- console.log('11111');
- if (cacheManager.get('auth')) {
- $emit('onLeft');
- }
- }
- function onSwipeRight(event) {
- console.log('22222');
- if (cacheManager.get('auth')) {
- $emit('onRight');
- }
- }
- function onTouchEnd(event) {
- if (isSliding.value) {
- const distanceX = event.changedTouches[0].clientX - startX.value
- if (distanceX > 0) {
- onSwipeLeft();
- } else if (distanceX < 0) {
- onSwipeRight();
- }
- isSliding.value = false
- } else {
- console.log('error');
- }
- }
- function dataRecom(data){
- if(data&&data.jieList.length>0){
- data.jieList.some(item => {
- if (item.studyFlag == 0) {
- item.daeFlag = true;
- return true; // 返回 true 以终止 some 循环
- }
- return false;
- });
- }
- }
- watch(() => props.options, (newVal, oldVal) => {
- // console.log('New options:', newVal);
- // console.log('Old options:', oldVal);
- // 在这里可以根据新的 options 做一些操作,比如发起请求等
- gradeTerm.value = translateData(newVal);
- dataRecom(newVal)
- }, {
- deep: true,
- immediate: true
- });
- </script>
- <style>
- </style>
|