|
@@ -15,8 +15,9 @@ const navActiveTab = ref('all')
|
|
|
const scrollViewId = ref()
|
|
const scrollViewId = ref()
|
|
|
const orderStatusActive = ref('all')
|
|
const orderStatusActive = ref('all')
|
|
|
|
|
|
|
|
-// 缓存各 tab 的数据,key = `${navActiveTab}-${orderStatusActive}`
|
|
|
|
|
const orderCache = new Map<string, Api.xsbOrderList[]>()
|
|
const orderCache = new Map<string, Api.xsbOrderList[]>()
|
|
|
|
|
+
|
|
|
|
|
+const tabLastPageMap = new Map<string, boolean>()
|
|
|
function getCacheKey() {
|
|
function getCacheKey() {
|
|
|
return `${navActiveTab.value}-${orderStatusActive.value}`
|
|
return `${navActiveTab.value}-${orderStatusActive.value}`
|
|
|
}
|
|
}
|
|
@@ -37,8 +38,11 @@ const { data: orderList, isLastPage, page, reload } = usePagination((pageNum, pa
|
|
|
append: true,
|
|
append: true,
|
|
|
}).onSuccess(() => {
|
|
}).onSuccess(() => {
|
|
|
skelet.value = false
|
|
skelet.value = false
|
|
|
- // 数据加载完成后写入缓存(含分页追加的情况)
|
|
|
|
|
- orderCache.set(getCacheKey(), [...orderList.value])
|
|
|
|
|
|
|
+ const key = getCacheKey()
|
|
|
|
|
+ orderCache.set(key, [...orderList.value])
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ tabLastPageMap.set(key, isLastPage.value)
|
|
|
|
|
+ }, 100)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
function loadTab() {
|
|
function loadTab() {
|
|
@@ -46,8 +50,10 @@ function loadTab() {
|
|
|
if (orderCache.has(key)) {
|
|
if (orderCache.has(key)) {
|
|
|
orderList.value = orderCache.get(key)!
|
|
orderList.value = orderCache.get(key)!
|
|
|
skelet.value = false
|
|
skelet.value = false
|
|
|
|
|
+ uni.pageScrollTo({ scrollTop: 0, duration: 0 })
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
|
|
+ tabLastPageMap.delete(key)
|
|
|
skelet.value = true
|
|
skelet.value = true
|
|
|
orderList.value = []
|
|
orderList.value = []
|
|
|
reload()
|
|
reload()
|
|
@@ -67,13 +73,18 @@ function handleChangeTypeNav(value: string) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
onShow(() => {
|
|
onShow(() => {
|
|
|
- // 每次页面显示时刷新当前 tab(清除旧缓存保证数据最新)
|
|
|
|
|
- orderCache.delete(getCacheKey())
|
|
|
|
|
- orderList.value = []
|
|
|
|
|
|
|
+ // 页面重新显示:清除当前 tab 的所有状态,强制刷新
|
|
|
|
|
+ const key = getCacheKey()
|
|
|
|
|
+ orderCache.delete(key)
|
|
|
|
|
+ tabLastPageMap.delete(key)
|
|
|
reload()
|
|
reload()
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
onReachBottom(() => {
|
|
onReachBottom(() => {
|
|
|
- if (!isLastPage.value) {
|
|
|
|
|
|
|
+ const key = getCacheKey()
|
|
|
|
|
+ // 优先使用 per-tab 的 isLastPage,避免从其他 tab 继承错误状态
|
|
|
|
|
+ const tabIsLast = tabLastPageMap.has(key) ? tabLastPageMap.get(key) : isLastPage.value
|
|
|
|
|
+ if (!tabIsLast) {
|
|
|
page.value++
|
|
page.value++
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
@@ -82,9 +93,11 @@ function handleChangeStatus(value: string) {
|
|
|
loadTab()
|
|
loadTab()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 子组件触发刷新时,清除当前 tab 缓存再重新加载
|
|
|
|
|
|
|
+// 子组件触发刷新时,清除当前 tab 的所有状态再重新加载
|
|
|
function handleRefresh() {
|
|
function handleRefresh() {
|
|
|
- orderCache.delete(getCacheKey())
|
|
|
|
|
|
|
+ const key = getCacheKey()
|
|
|
|
|
+ orderCache.delete(key)
|
|
|
|
|
+ tabLastPageMap.delete(key)
|
|
|
skelet.value = true
|
|
skelet.value = true
|
|
|
orderList.value = []
|
|
orderList.value = []
|
|
|
reload()
|
|
reload()
|