|
|
@@ -14,6 +14,14 @@ const skelet = ref(true)
|
|
|
const navActiveTab = ref('all')
|
|
|
const scrollViewId = ref()
|
|
|
const orderStatusActive = ref('all')
|
|
|
+
|
|
|
+const orderCache = new Map<string, Api.xsbOrderList[]>()
|
|
|
+
|
|
|
+const tabLastPageMap = new Map<string, boolean>()
|
|
|
+function getCacheKey() {
|
|
|
+ return `${navActiveTab.value}-${orderStatusActive.value}`
|
|
|
+}
|
|
|
+
|
|
|
const { data: orderList, isLastPage, page, reload } = usePagination((pageNum, pageSize) => Apis.xsb.orderList({
|
|
|
data: {
|
|
|
businessType: unref(navActiveTab) === 'all' ? '' : unref(navActiveTab),
|
|
|
@@ -28,28 +36,69 @@ const { data: orderList, isLastPage, page, reload } = usePagination((pageNum, pa
|
|
|
initialData: [],
|
|
|
data: res => res.data?.list,
|
|
|
append: true,
|
|
|
-}).onSuccess(() => skelet.value = false)
|
|
|
+}).onSuccess(() => {
|
|
|
+ skelet.value = false
|
|
|
+ const key = getCacheKey()
|
|
|
+ orderCache.set(key, [...orderList.value])
|
|
|
+ setTimeout(() => {
|
|
|
+ tabLastPageMap.set(key, isLastPage.value)
|
|
|
+ }, 100)
|
|
|
+})
|
|
|
|
|
|
+function loadTab() {
|
|
|
+ const key = getCacheKey()
|
|
|
+ if (orderCache.has(key)) {
|
|
|
+ orderList.value = orderCache.get(key)!
|
|
|
+ skelet.value = false
|
|
|
+ uni.pageScrollTo({ scrollTop: 0, duration: 0 })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ tabLastPageMap.delete(key)
|
|
|
+ skelet.value = true
|
|
|
+ orderList.value = []
|
|
|
+ reload()
|
|
|
+ }
|
|
|
+}
|
|
|
+onLoad((options: any) => {
|
|
|
+ if (options.status) {
|
|
|
+ orderStatusActive.value = options.status
|
|
|
+ }
|
|
|
+})
|
|
|
function handleChangeTypeNav(value: string) {
|
|
|
- skelet.value = true
|
|
|
navActiveTab.value = value
|
|
|
scrollViewId.value = null
|
|
|
- orderList.value = []
|
|
|
+ orderStatusActive.value = 'all'
|
|
|
nextTick(() => scrollViewId.value = value)
|
|
|
- reload()
|
|
|
+ loadTab()
|
|
|
}
|
|
|
+
|
|
|
onShow(() => {
|
|
|
- // orderList.value = []
|
|
|
+ // 页面重新显示:清除当前 tab 的所有状态,强制刷新
|
|
|
+ const key = getCacheKey()
|
|
|
+ orderCache.delete(key)
|
|
|
+ tabLastPageMap.delete(key)
|
|
|
reload()
|
|
|
})
|
|
|
+
|
|
|
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++
|
|
|
}
|
|
|
})
|
|
|
function handleChangeStatus(value: string) {
|
|
|
- skelet.value = true
|
|
|
orderStatusActive.value = value
|
|
|
+ loadTab()
|
|
|
+}
|
|
|
+
|
|
|
+// 子组件触发刷新时,清除当前 tab 的所有状态再重新加载
|
|
|
+function handleRefresh() {
|
|
|
+ const key = getCacheKey()
|
|
|
+ orderCache.delete(key)
|
|
|
+ tabLastPageMap.delete(key)
|
|
|
+ skelet.value = true
|
|
|
orderList.value = []
|
|
|
reload()
|
|
|
}
|
|
|
@@ -134,7 +183,7 @@ function handleChangeStatus(value: string) {
|
|
|
<template v-for="item in orderList" :key="item.orderNumber">
|
|
|
<OrderRenderer
|
|
|
:order-list="item"
|
|
|
- @refresh="reload"
|
|
|
+ @refresh="handleRefresh"
|
|
|
/>
|
|
|
</template>
|
|
|
<StatusTip v-if="!orderList.length" tip="暂无内容" />
|