Browse Source

fix: bug修复;

fox
Fox-33 1 day ago
parent
commit
4002777d40
4 changed files with 43 additions and 59 deletions
  1. +19
    -7
      components/home/productSwiper.vue
  2. +3
    -44
      pages/index/index.vue
  3. +18
    -6
      pages_order/home/recommendSwiper.vue
  4. +3
    -2
      pages_order/report/test/answer.vue

+ 19
- 7
components/home/productSwiper.vue View File

@ -1,5 +1,5 @@
<template> <template>
<view class="product-swiper__view">
<view>
<swiper <swiper
class="swiper" class="swiper"
:current="current" :current="current"
@ -49,17 +49,13 @@
export default { export default {
components: { components: {
indicator, indicator,
},
props: {
autoplay: {
type: Boolean,
default: false,
},
}, },
data() { data() {
return { return {
current: 0, current: 0,
list: [], list: [],
last: null,
autoplay: true,
} }
}, },
created() { created() {
@ -85,6 +81,22 @@
}, },
onChange(e) { onChange(e) {
this.current = e.detail.current this.current = e.detail.current
const currentTime = this.$dayjs()
if (this.last) {
const diff = currentTime.diff(this.last, 'millisecond')
console.log('diff', diff, e.detail.source)
if (diff < 2500 && e.detail.source === 'autoplay') {
console.log('autoplay abnormal')
this.autoplay = false
setTimeout(() => {
console.log('autoplay restart')
this.autoplay = true
}, 3000 - diff)
}
}
this.last = currentTime
}, },
}, },
} }


+ 3
- 44
pages/index/index.vue View File

@ -6,15 +6,11 @@
</navbar> </navbar>
<view class="content"> <view class="content">
<view id="productSwiper" class="swiper">
<productSwiper :autoplay="autoplay.productSwiper"></productSwiper>
</view>
<productSwiper></productSwiper>
<view class="section"> <view class="section">
<sectionHeader title="个性推荐" desc="Personal Recommendation"></sectionHeader> <sectionHeader title="个性推荐" desc="Personal Recommendation"></sectionHeader>
<view id="recommendSwiper" class="swiper">
<recommend-swiper :autoplay="autoplay.recommendSwiper"></recommend-swiper>
</view>
<recommend-swiper></recommend-swiper>
<health-records-intro></health-records-intro> <health-records-intro></health-records-intro>
</view> </view>
@ -66,12 +62,6 @@
}, },
data() { data() {
return { return {
isMounted: false,
observer: null,
autoplay: {
productSwiper: false,
recommendSwiper: false,
},
} }
}, },
onLoad() { onLoad() {
@ -81,37 +71,7 @@
} }
}, },
onShow() {
if (this.isMounted) {
this.observeElement()
}
},
mounted() {
this.observeElement()
this.isMounted = true
},
unmounted() {
this.observer.disconnect()
},
onHide() {
this.observer.disconnect()
this.observer = null
this.autoplay.productSwiper = false
this.autoplay.recommendSwiper = false
},
methods: { methods: {
observeElement() {
this.observer = uni.createIntersectionObserver(this, { observeAll: true, thresholds: [0, 1] });
this.observer.relativeTo('.content').observe('.swiper', res => {
if (res.intersectionRatio === 0) {
this.autoplay[res.id] = false
} else if (res.intersectionRatio === 1) {
this.autoplay[res.id] = true
}
})
},
}, },
} }
</script> </script>
@ -131,10 +91,9 @@
} }
.content { .content {
// padding: 80rpx 32rpx 182rpx 32rpx;
width: 100vw; width: 100vw;
height: calc(100vh - (var(--status-bar-height) + 120rpx) - (env(safe-area-inset-bottom) + 120rpx));
padding: 70rpx 0 182rpx 0; padding: 70rpx 0 182rpx 0;
// padding-bottom: calc(env(safe-area-inset-bottom) + 120rpx + 182rpx);
box-sizing: border-box; box-sizing: border-box;
overflow-x: hidden; overflow-x: hidden;
overflow-y: auto; overflow-y: auto;


+ 18
- 6
pages_order/home/recommendSwiper.vue View File

@ -46,17 +46,13 @@
export default { export default {
components: { components: {
indicator, indicator,
},
props: {
autoplay: {
type: Boolean,
default: false,
},
}, },
data() { data() {
return { return {
current: 0, current: 0,
list: [], list: [],
last: null,
autoplay: true,
} }
}, },
created() { created() {
@ -91,6 +87,22 @@
}, },
onChange(e) { onChange(e) {
this.current = e.detail.current this.current = e.detail.current
const currentTime = this.$dayjs()
if (this.last) {
const diff = currentTime.diff(this.last, 'millisecond')
console.log('diff', diff, e.detail.source)
if (diff < 2500 && e.detail.source === 'autoplay') {
console.log('autoplay abnormal')
this.autoplay = false
setTimeout(() => {
console.log('autoplay restart')
this.autoplay = true
}, 3000 - diff)
}
}
this.last = currentTime
} }
}, },
} }


+ 3
- 2
pages_order/report/test/answer.vue View File

@ -225,7 +225,8 @@
switchQuestion(current) { switchQuestion(current) {
let { needTag } = this.questionsList[current] let { needTag } = this.questionsList[current]
if (!needTag) {
console.log('needTag length', needTag?.length)
if (!needTag?.length) {
this.current = current this.current = current
this.tabs.push(this.current) this.tabs.push(this.current)
return return
@ -299,7 +300,7 @@
answer = options.reduce((obj, option, oIdx) => { answer = options.reduce((obj, option, oIdx) => {
const { id: optionsId } = option const { id: optionsId } = option
obj[optionsId] = this.value[oIdx]
obj[optionsId] = Array.isArray(this.value) ? this.value[oIdx] : this.value
return obj return obj
}, {}) }, {})


Loading…
Cancel
Save