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
@@ -1,6 +1,10 @@
import { request } from '../../utils/request'
import { ClothesItem } from '../../types/models'
import { ProcessStatus } from '../../utils/config'
import { logger } from '../../utils/logger'
// 日志模块名
const LOG = 'clothes-detail'
const ATTRS = [
{ key: 'category_main', label: '大类', type: 'text' },
@@ -44,9 +48,11 @@ Page({
onLoad(query: Record<string, string>) {
const uuid = query.uuid || ''
logger.debug(LOG, 'onLoad, uuid=', uuid)
this.setData({ uuid })
if (!uuid) {
// uuid 缺失时不请求不轮询,否则会停在空白页且无法退出
logger.warn(LOG, 'onLoad 缺少 uuid 参数')
this.setData({ loading: false, notFound: true })
return
}
@@ -55,13 +61,22 @@ Page({
},
onBackWardrobe() {
wx.switchTab({ url: '/pages/wardrobe/wardrobe' })
wx.switchTab({
url: '/pages/wardrobe/wardrobe',
fail: (e) => logger.warn(LOG, 'switchTab 衣橱失败, err=', e && e.errMsg),
})
},
fetchDetail(): Promise<void> {
return request<ClothesItem>({ url: `/clothes/${this.data.uuid}` })
.then((detail) => this.setData({ detail, loading: false }))
.catch(() => this.setData({ loading: false }))
.then((detail) => {
logger.debug(LOG, '详情加载成功, 处理状态=', detail && detail.image_process_status)
this.setData({ detail, loading: false })
})
.catch((e: any) => {
logger.warn(LOG, '详情加载失败, code=', e && e.code)
this.setData({ loading: false })
})
},
pollStatus() {
@@ -77,17 +92,20 @@ Page({
if (status === ProcessStatus.SUCCESS) {
// 成功:先拉最新详情,再切换为详情视图,避免空属性闪烁
this.clearTimer()
logger.info(LOG, 'AI 处理完成')
this.fetchDetail().then(() => this.setData({ imageStatus: status, step: 2 }))
} else if (status === ProcessStatus.FAILED) {
this.clearTimer()
logger.warn(LOG, 'AI 识别失败, 原因=', res.fail_reason)
this.setData({ imageStatus: status, failReason: res.fail_reason || '识别失败' })
} else {
this.setData({ imageStatus: status, step: statusToStep(status) })
}
})
.catch(() => {})
.catch((e: any) => logger.warn(LOG, '状态轮询失败, code=', e && e.code))
if (count >= 120) {
this.clearTimer()
logger.warn(LOG, '状态轮询超时(240s),停止轮询')
}
}, 2000)
},
@@ -178,11 +196,12 @@ Page({
request({ url: `/clothes/${this.data.uuid}`, method: 'PUT', data: body })
.then(() => {
logger.info(LOG, '衣物信息保存成功')
wx.showToast({ title: '已保存', icon: 'success' })
this.setData({ editMode: false })
this.fetchDetail()
})
.catch(() => {})
.catch((e: any) => logger.warn(LOG, '衣物信息保存失败, code=', e && e.code))
},
onDelete() {
@@ -197,11 +216,19 @@ Page({
if (!res.confirm) return
request({ url: `/clothes/${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),
})
},
})