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>
<view class="product-swiper__view">
<view>
<swiper
class="swiper"
:current="current"
@ -49,17 +49,13 @@
export default {
components: {
indicator,
},
props: {
autoplay: {
type: Boolean,
default: false,
},
},
data() {
return {
current: 0,
list: [],
last: null,
autoplay: true,
}
},
created() {
@ -85,6 +81,22 @@
},
onChange(e) {
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>
<view class="content">
<view id="productSwiper" class="swiper">
<productSwiper :autoplay="autoplay.productSwiper"></productSwiper>
</view>
<productSwiper></productSwiper>
<view class="section">
<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>
</view>
@ -66,12 +62,6 @@
},
data() {
return {
isMounted: false,
observer: null,
autoplay: {
productSwiper: false,
recommendSwiper: false,
},
}
},
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: {
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>
@ -131,10 +91,9 @@
}
.content {
// padding: 80rpx 32rpx 182rpx 32rpx;
width: 100vw;
height: calc(100vh - (var(--status-bar-height) + 120rpx) - (env(safe-area-inset-bottom) + 120rpx));
padding: 70rpx 0 182rpx 0;
// padding-bottom: calc(env(safe-area-inset-bottom) + 120rpx + 182rpx);
box-sizing: border-box;
overflow-x: hidden;
overflow-y: auto;


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

@ -46,17 +46,13 @@
export default {
components: {
indicator,
},
props: {
autoplay: {
type: Boolean,
default: false,
},
},
data() {
return {
current: 0,
list: [],
last: null,
autoplay: true,
}
},
created() {
@ -91,6 +87,22 @@
},
onChange(e) {
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) {
let { needTag } = this.questionsList[current]
if (!needTag) {
console.log('needTag length', needTag?.length)
if (!needTag?.length) {
this.current = current
this.tabs.push(this.current)
return
@ -299,7 +300,7 @@
answer = options.reduce((obj, option, oIdx) => {
const { id: optionsId } = option
obj[optionsId] = this.value[oIdx]
obj[optionsId] = Array.isArray(this.value) ? this.value[oIdx] : this.value
return obj
}, {})


Loading…
Cancel
Save