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
+31 -11
View File
@@ -1,6 +1,8 @@
import { request, redirectToLogin } from '../../utils/request'
import * as auth from '../../utils/auth'
import { PagedResult, ClosetShareItem } from '../../types/models'
import { ShareStatus, ShareType } from '../../utils/config'
import { normalizePaged, mergePaged, hasMorePaged } from '../../utils/paged'
Page({
data: {
@@ -11,6 +13,7 @@ Page({
activeTab: 0, // 0 我的分享 1 分享给我的
list: [] as ClosetShareItem[],
loading: true,
loadingMore: false,
page: 1,
pageSize: 20,
hasMore: true,
@@ -44,35 +47,49 @@ 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) {
const url = this.data.activeTab === 0 ? '/closet-share' : '/closet-share/received'
// 请求序号:切 tab 时旧响应可能后到,序号不匹配直接丢弃
const seq = ((this as any).reqSeq || 0) + 1
;(this as any).reqSeq = seq
if (page > 1) this.setData({ loadingMore: true })
request<PagedResult<ClosetShareItem>>({ url, data: { page, page_size: this.data.pageSize } })
.then((res) => {
const list = res.list.map((it) => this.decorate(it))
const merged = page === 1 ? list : this.data.list.concat(list)
if ((this as any).reqSeq !== seq) return
const { list: raw, total } = normalizePaged<ClosetShareItem>(res)
const list = raw.map((it) => this.decorate(it))
const merged = mergePaged(this.data.list, list, 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 })
})
},
decorate(it: ClosetShareItem) {
const now = Math.floor(Date.now() / 1000)
let status = it.status
if (status === 1 && it.expire_time > 0 && it.expire_time < now) status = 3
if (status === ShareStatus.NORMAL && it.expire_time > 0 && it.expire_time < now) {
status = ShareStatus.EXPIRED
}
let expireText = '长期有效'
if (status === 2) expireText = '已取消'
else if (status === 3) expireText = '已过期'
else if (status === 4) expireText = '已封禁'
if (status === ShareStatus.CANCELLED) expireText = '已取消'
else if (status === ShareStatus.EXPIRED) expireText = '已过期'
else if (status === ShareStatus.BANNED) expireText = '已封禁'
else if (it.expire_time > 0) {
const days = Math.ceil((it.expire_time - now) / 86400)
expireText = days > 0 ? `${days} 天后过期` : '已过期'
@@ -82,8 +99,11 @@ Page({
...it,
_status: status,
_expireText: expireText,
_typeText: it.share_type === 1 ? '部分衣物' : '全量衣橱',
_invalid: status === 2 || status === 3 || status === 4,
_typeText: it.share_type === ShareType.PARTIAL ? '部分衣物' : '全量衣橱',
_invalid:
status === ShareStatus.CANCELLED ||
status === ShareStatus.EXPIRED ||
status === ShareStatus.BANNED,
}
},
@@ -52,7 +52,7 @@
<view class="tag tag-gray share-type">{{item._typeText}}</view>
<view class="share-expire">{{item._expireText}}</view>
</view>
<view wx:if="{{item._invalid}}" class="share-badge">{{item._status === 2 ? '已取消' : '已过期'}}</view>
<view wx:if="{{item._invalid}}" class="share-badge">{{item._status === 2 ? '已取消' : (item._status === 4 ? '已封禁' : '已过期')}}</view>
</view>
</view>
</scroll-view>