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://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=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
|
# SHOPRO_DEV_BASE_URL=https://yougoutest.api.riananyoumu.com
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, onMounted, ref, watch } from 'vue';
|
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
import { earningsPage } from '@/sheep/api/ai/index';
|
import { earningsPage } from '@/sheep/api/ai/index';
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
},
|
},
|
||||||
interval: {
|
interval: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 5000,
|
default: 10000,
|
||||||
},
|
},
|
||||||
duration: {
|
duration: {
|
||||||
type: Number,
|
type: Number,
|
||||||
@@ -81,6 +81,8 @@
|
|||||||
const total = ref(0);
|
const total = ref(0);
|
||||||
const pagesMap = ref({});
|
const pagesMap = ref({});
|
||||||
const loadingMap = ref({});
|
const loadingMap = ref({});
|
||||||
|
const PREFETCH_ADVANCE_MS = 800;
|
||||||
|
let prefetchTimer = null;
|
||||||
|
|
||||||
const normalizeSize = (val, def) => {
|
const normalizeSize = (val, def) => {
|
||||||
const n = Math.floor(Number(val));
|
const n = Math.floor(Number(val));
|
||||||
@@ -155,14 +157,35 @@
|
|||||||
return p;
|
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 onSwiperChange = (e) => {
|
||||||
const next = Number(e?.detail?.current);
|
const next = Number(e?.detail?.current);
|
||||||
if (!Number.isFinite(next)) return;
|
if (!Number.isFinite(next)) return;
|
||||||
currentPageIndex.value = next;
|
currentPageIndex.value = next;
|
||||||
const currentPageNo = next + 1;
|
const currentPageNo = normalizePageNo(next + 1);
|
||||||
ensurePageLoaded(currentPageNo, true);
|
const key = String(currentPageNo);
|
||||||
ensurePageLoaded(currentPageNo + 1);
|
if (!pagesMap.value[key] && !loadingMap.value[key]) {
|
||||||
ensurePageLoaded(currentPageNo + 2);
|
ensurePageLoaded(currentPageNo, true).finally(() => schedulePrefetchNext(false));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
schedulePrefetchNext(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const clampProgress = (val) => {
|
const clampProgress = (val) => {
|
||||||
@@ -198,7 +221,7 @@
|
|||||||
pagesMap.value = {};
|
pagesMap.value = {};
|
||||||
loadingMap.value = {};
|
loadingMap.value = {};
|
||||||
await ensurePageLoaded(1, true);
|
await ensurePageLoaded(1, true);
|
||||||
ensurePageLoaded(2);
|
schedulePrefetchNext(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
@@ -221,6 +244,10 @@
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (props.active) reset();
|
if (props.active) reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
clearPrefetch();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|||||||
Reference in New Issue
Block a user