This commit is contained in:
2026-09-13 01:51:09 +08:00
parent b1a664a768
commit afd0973ce5
32 changed files with 935 additions and 171 deletions
+22 -8
View File
@@ -1,7 +1,8 @@
import { request, redirectToLogin } from '../../utils/request'
import * as auth from '../../utils/auth'
import { PagedResult, OutfitItem } from '../../types/models'
import { OutfitSource, IsPublic } from '../../utils/config'
import { OutfitSource, IsPublic, STORAGE_KEYS } from '../../utils/config'
import { normalizePaged, mergePaged, hasMorePaged } from '../../utils/paged'
Page({
data: {
@@ -9,6 +10,7 @@ Page({
list: [] as OutfitItem[],
loading: true,
refreshing: false,
loadingMore: false,
page: 1,
pageSize: 20,
hasMore: true,
@@ -21,9 +23,9 @@ Page({
redirectToLogin()
return
}
const openCollect = wx.getStorageSync('zt_open_collect')
const openCollect = wx.getStorageSync(STORAGE_KEYS.OPEN_COLLECT)
if (openCollect) {
wx.removeStorageSync('zt_open_collect')
wx.removeStorageSync(STORAGE_KEYS.OPEN_COLLECT)
if (this.data.activeTab !== 1) {
this.setData({ activeTab: 1, list: [], loading: true })
}
@@ -54,25 +56,37 @@ Page({
},
onReachBottom() {
if (!this.data.hasMore || this.data.loading) return
if (!this.data.hasMore || this.data.loading || this.data.loadingMore) return
this.fetchList(this.data.page + 1)
},
fetchList(page: number): Promise<void> {
const isCollect = this.data.activeTab === 1
const url = isCollect ? '/collect' : '/outfit'
const seq = ((this as any).reqSeq || 0) + 1
;(this as any).reqSeq = seq
if (page > 1) this.setData({ loadingMore: true })
return request<PagedResult<OutfitItem>>({ url, data: { page, page_size: this.data.pageSize } })
.then(async (res) => {
const items = await this.decorateList(res.list)
const merged = page === 1 ? items : this.data.list.concat(items)
const { list: raw, total } = normalizePaged<OutfitItem>(res)
const items = await this.decorateList(raw)
// decorateList 是异步的,期间可能已切换 tab:序号不匹配则丢弃
if ((this as any).reqSeq !== seq) return
const merged = mergePaged(this.data.list, items, page === 1)
this.setData({
list: merged,
hasMore: merged.length < res.total,
hasMore: hasMorePaged(merged, total, this.data.pageSize),
loading: false,
loadingMore: false,
page,
})
})
.catch(() => this.setData({ loading: false }))
.catch(() => {
if ((this as any).reqSeq !== seq) return
this.setData({ loading: false, loadingMore: false })
})
},
decorateList(list: OutfitItem[]): Promise<OutfitItem[]> {