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
+36 -7
View File
@@ -1,6 +1,10 @@
import { request } from '../../utils/request'
import { OutfitItem, ClothesItem, PagedResult } from '../../types/models'
import { normalizePaged, hasMorePaged } from '../../utils/paged'
import { logger } from '../../utils/logger'
// 日志模块名
const LOG = 'outfit-edit'
const CATEGORIES = [
{ name: '全部', value: '' },
@@ -36,6 +40,7 @@ Page({
onLoad(query: Record<string, string>) {
const uuid = query.uuid || ''
logger.debug(LOG, 'onLoad, uuid=', uuid, '编辑态=', !!uuid)
if (uuid) {
this.setData({ uuid, isEdit: true })
this.fetchOutfit(uuid)
@@ -50,7 +55,8 @@ Page({
uuids.map(async (id) => {
try {
return await request<ClothesItem>({ url: `/clothes/${id}`, showError: false })
} catch (e) {
} catch (e: any) {
logger.warn(LOG, '单品详情拉取失败, uuid=', id, 'code=', e && e.code)
return { clothes_uuid: id } as ClothesItem
}
})
@@ -67,7 +73,9 @@ Page({
selectedUuids: uuids,
selectedItems: clothes,
})
} catch (e) {}
} catch (e: any) {
logger.warn(LOG, '穿搭详情加载失败, code=', e && e.code)
}
},
// 已选衣物快照:跨分类切换时列表只保留当前分类,快照保留全部已选项
@@ -109,6 +117,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,
@@ -122,8 +131,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 })
})
},
@@ -151,6 +161,7 @@ Page({
return
}
if (uuids.length >= 10) {
logger.debug(LOG, '已选 10 件,达到上限')
wx.showToast({ title: '最多选择 10 件衣物', icon: 'none' })
return
}
@@ -202,11 +213,21 @@ Page({
: request({ url: '/outfit', method: 'POST', data: body })
req
.then(() => {
logger.info(LOG, '穿搭保存成功, 编辑态=', this.data.isEdit, '件数=', body.items.length)
this.setData({ saving: false })
wx.showToast({ title: '已保存', icon: 'success' })
setTimeout(() => wx.navigateBack(), 500)
setTimeout(
() =>
wx.navigateBack({
fail: (e) => logger.warn(LOG, 'navigateBack 失败, err=', e && e.errMsg),
}),
500,
)
})
.catch((e: any) => {
logger.warn(LOG, '穿搭保存失败, code=', e && e.code)
this.setData({ saving: false })
})
.catch(() => this.setData({ saving: false }))
},
onDelete() {
@@ -219,11 +240,19 @@ Page({
if (!res.confirm) return
request({ url: `/outfit/${this.data.uuid}`, method: 'DELETE' })
.then(() => {
logger.info(LOG, '穿搭删除成功')
wx.showToast({ title: '已删除', icon: 'success' })
setTimeout(() => wx.navigateBack(), 500)
setTimeout(
() =>
wx.navigateBack({
fail: (e) => logger.warn(LOG, 'navigateBack 失败, err=', e && e.errMsg),
}),
500,
)
})
.catch(() => {})
.catch((e: any) => logger.warn(LOG, '穿搭删除失败, code=', e && e.code))
},
fail: (e) => logger.warn(LOG, '删除弹窗失败, err=', e && e.errMsg),
})
},
})