This commit is contained in:
2026-09-13 02:28:46 +08:00
parent df5492a48a
commit 42f9530a59
27 changed files with 979 additions and 149 deletions
@@ -2,6 +2,10 @@ import { request } from '../../utils/request'
import { ClothesItem, PagedResult, UserInfo } from '../../types/models'
import { STORAGE_KEYS } from '../../utils/config'
import { normalizePaged, hasMorePaged } from '../../utils/paged'
import { logger } from '../../utils/logger'
// 日志模块名
const LOG = 'closet-share-create'
const CATEGORIES = [
{ name: '全部', value: '' },
@@ -55,10 +59,11 @@ Page({
// 头像为带时间戳的签名 URL,缓存可能过期,实时刷新并回写缓存。
request<UserInfo>({ url: '/user/info', showError: false })
.then((user) => {
logger.debug(LOG, '用户信息加载成功')
wx.setStorageSync(STORAGE_KEYS.USER_INFO, user)
this.setData({ nickname: user.username || '微信用户', avatar: user.avatar || '' })
})
.catch(() => {})
.catch((e: any) => logger.warn(LOG, '用户信息加载失败(用缓存兜底), code=', e && e.code))
},
selectPartial() {
@@ -91,6 +96,7 @@ Page({
.then((res) => {
if ((this as any).reqSeq !== seq) return
const { list: raw, total } = normalizePaged<ClothesItem>(res)
logger.debug(LOG, '衣物列表加载成功, 分类=', cat || '全部', 'page=', page, '条数=', raw && raw.length)
const list = raw.map((it) => ({
...it,
_selected: this.data.selectedUuids.indexOf(it.clothes_uuid) >= 0,
@@ -104,8 +110,9 @@ Page({
hasMore: hasMorePaged(merged, total, PAGE_SIZE),
})
})
.catch(() => {
.catch((e: any) => {
if ((this as any).reqSeq !== seq) return
logger.warn(LOG, '衣物列表加载失败, page=', page, 'code=', e && e.code)
this.setData({ selectLoading: false, loadingMore: false })
})
},
@@ -168,15 +175,26 @@ Page({
// 提交加锁:连点会重复创建分享、重复扣额度
this.setData({ submitting: true })
request<{ share_uuid: string }>({ url: '/closet-share', method: 'POST', data: body })
.then((res) => this.setData({ shareUuid: res.share_uuid, view: 'success', submitting: false }))
.catch(() => this.setData({ submitting: false }))
.then((res) => {
logger.info(LOG, '分享创建成功, uuid=', res.share_uuid)
this.setData({ shareUuid: res.share_uuid, view: 'success', submitting: false })
})
.catch((e: any) => {
logger.warn(LOG, '分享创建失败, code=', e && e.code)
this.setData({ submitting: false })
})
},
onViewShare() {
wx.redirectTo({ url: `/pages/closet-share-detail/closet-share-detail?uuid=${this.data.shareUuid}` })
wx.redirectTo({
url: `/pages/closet-share-detail/closet-share-detail?uuid=${this.data.shareUuid}`,
fail: (e) => logger.warn(LOG, 'redirectTo 分享详情失败, err=', e && e.errMsg),
})
},
onDone() {
wx.navigateBack()
wx.navigateBack({
fail: (e) => logger.warn(LOG, 'navigateBack 失败, err=', e && e.errMsg),
})
},
})