fix: 一次调用两次分页问题
This commit is contained in:
@@ -15,12 +15,12 @@ SHOPRO_VERSION=v2.4.1
|
||||
#SHOPRO_DEV_BASE_URL=http://192.168.101.58:48090
|
||||
|
||||
# 服务器
|
||||
SHOPRO_DEV_BASE_URL=http://www.qflyqzy.net:48090
|
||||
# SHOPRO_DEV_BASE_URL=http://www.qflyqzy.net:48090
|
||||
|
||||
# SHOPRO_DEV_BASE_URL=https://www.qflyqzy.net/yg-api
|
||||
|
||||
# 伟伟
|
||||
# SHOPRO_DEV_BASE_URL=http://192.168.1.12:48090
|
||||
SHOPRO_DEV_BASE_URL=http://192.168.1.12:48090
|
||||
|
||||
# 测试环境
|
||||
# SHOPRO_DEV_BASE_URL=https://yougoutest.api.riananyoumu.com
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import sheep from '@/sheep';
|
||||
import { earningsPage } from '@/sheep/api/ai/index';
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
},
|
||||
interval: {
|
||||
type: Number,
|
||||
default: 5000,
|
||||
default: 10000,
|
||||
},
|
||||
duration: {
|
||||
type: Number,
|
||||
@@ -81,6 +81,8 @@
|
||||
const total = ref(0);
|
||||
const pagesMap = ref({});
|
||||
const loadingMap = ref({});
|
||||
const PREFETCH_ADVANCE_MS = 800;
|
||||
let prefetchTimer = null;
|
||||
|
||||
const normalizeSize = (val, def) => {
|
||||
const n = Math.floor(Number(val));
|
||||
@@ -155,14 +157,35 @@
|
||||
return p;
|
||||
};
|
||||
|
||||
const clearPrefetch = () => {
|
||||
if (prefetchTimer) {
|
||||
clearTimeout(prefetchTimer);
|
||||
prefetchTimer = null;
|
||||
}
|
||||
};
|
||||
|
||||
const schedulePrefetchNext = (immediate = false) => {
|
||||
clearPrefetch();
|
||||
if (!props.active) return;
|
||||
if (!autoplay.value) return;
|
||||
const delay = immediate ? 0 : Math.max(0, interval.value - PREFETCH_ADVANCE_MS);
|
||||
prefetchTimer = setTimeout(() => {
|
||||
const nextPageNo = normalizePageNo(currentPageIndex.value + 2);
|
||||
ensurePageLoaded(nextPageNo, true);
|
||||
}, delay);
|
||||
};
|
||||
|
||||
const onSwiperChange = (e) => {
|
||||
const next = Number(e?.detail?.current);
|
||||
if (!Number.isFinite(next)) return;
|
||||
currentPageIndex.value = next;
|
||||
const currentPageNo = next + 1;
|
||||
ensurePageLoaded(currentPageNo, true);
|
||||
ensurePageLoaded(currentPageNo + 1);
|
||||
ensurePageLoaded(currentPageNo + 2);
|
||||
const currentPageNo = normalizePageNo(next + 1);
|
||||
const key = String(currentPageNo);
|
||||
if (!pagesMap.value[key] && !loadingMap.value[key]) {
|
||||
ensurePageLoaded(currentPageNo, true).finally(() => schedulePrefetchNext(false));
|
||||
return;
|
||||
}
|
||||
schedulePrefetchNext(false);
|
||||
};
|
||||
|
||||
const clampProgress = (val) => {
|
||||
@@ -198,7 +221,7 @@
|
||||
pagesMap.value = {};
|
||||
loadingMap.value = {};
|
||||
await ensurePageLoaded(1, true);
|
||||
ensurePageLoaded(2);
|
||||
schedulePrefetchNext(true);
|
||||
};
|
||||
|
||||
watch(
|
||||
@@ -221,6 +244,10 @@
|
||||
onMounted(() => {
|
||||
if (props.active) reset();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
clearPrefetch();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
Reference in New Issue
Block a user