feat: 支持退出后补告衣物处理结果
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar",
|
||||
"clothes-card": "/components/clothes-card/clothes-card",
|
||||
"empty-state": "/components/empty-state/empty-state"
|
||||
"empty-state": "/components/empty-state/empty-state",
|
||||
"v2-overlay": "/components/v2-overlay/index"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import * as auth from '../../utils/auth'
|
||||
import { PagedResult, ClothesItem, QuotaItem } from '../../types/models'
|
||||
import { QuotaType } from '../../utils/config'
|
||||
import { normalizePaged, mergePaged, hasMorePaged } from '../../utils/paged'
|
||||
import { clothesStatusFlag } from '../../utils/clothes-status'
|
||||
import { resolvePendingClothes } from '../../utils/pending-clothes'
|
||||
import { setTabBarSelected } from '../../utils/tabbar'
|
||||
import { navScroll } from '../../utils/nav'
|
||||
import { logger } from '../../utils/logger'
|
||||
@@ -35,6 +37,14 @@ Page({
|
||||
hasMore: true,
|
||||
// 滚动收缩:由 utils/nav.ts 的共享 handler 驱动
|
||||
navScrolled: false,
|
||||
// 「上传后退出小程序」的失败结果回归告知(v2 玻璃弹窗)
|
||||
failVisible: false,
|
||||
failText: '',
|
||||
failUuid: '',
|
||||
failButtons: [
|
||||
{ text: '知道了', value: '' },
|
||||
{ text: '查看衣物', value: 'ok', type: 'main' },
|
||||
],
|
||||
},
|
||||
|
||||
// scroll-view 滚动 → 导航收缩为玻璃小标题
|
||||
@@ -47,6 +57,8 @@ Page({
|
||||
redirectToLogin()
|
||||
return
|
||||
}
|
||||
// 核对「上传后退出小程序」的衣物最终处理结果(pending 为空时零请求)
|
||||
this.resolvePending()
|
||||
// 首帧渲染未结束就 setData 会触发「Expected updated data but get first rendering data」,
|
||||
// 整个 webview 渲染失败,用户视觉上仍看到上一个页面(从 login switchTab 过来时表现为
|
||||
// "卡在登录页")。把首次 onShow 的刷新延迟到下一帧,规避首帧冲突。
|
||||
@@ -96,11 +108,11 @@ Page({
|
||||
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,
|
||||
_statusText: !it.category_main && !it.processed_image ? 'AI 处理中' : '',
|
||||
_statusType: 'plain',
|
||||
}))
|
||||
// 状态标识收敛到 clothes-status:处理中(玻璃)/ 处理失败(实心)/ 无
|
||||
const list = raw.map((it) => {
|
||||
const flag = clothesStatusFlag(it)
|
||||
return { ...it, _statusText: flag.text, _statusType: flag.type }
|
||||
})
|
||||
const merged = mergePaged(this.data.list, list, page === 1)
|
||||
this.setData({
|
||||
list: merged,
|
||||
@@ -128,6 +140,49 @@ Page({
|
||||
.catch((e: any) => logger.warn(LOG, '额度加载失败(静默降级), code=', e && e.code))
|
||||
},
|
||||
|
||||
// 核对待处理衣物:成功静默、失败弹窗告知;有终结态时重刷列表对齐状态
|
||||
resolvePending() {
|
||||
if ((this as any).resolvingPending) return
|
||||
;(this as any).resolvingPending = true
|
||||
resolvePendingClothes()
|
||||
.then((res) => {
|
||||
if (!res.finished.length && !res.failed.length) return
|
||||
logger.info(LOG, '待核对衣物已终结, 成功=', res.finished.length, '失败=', res.failed.length)
|
||||
if (res.failed.length) this.showFailModal(res.failed)
|
||||
this.refresh()
|
||||
})
|
||||
.catch((e: any) => logger.warn(LOG, '待核对衣物解析异常, code=', e && e.code))
|
||||
.finally(() => {
|
||||
;(this as any).resolvingPending = false
|
||||
})
|
||||
},
|
||||
|
||||
showFailModal(failed: Array<{ uuid: string; reason: string }>) {
|
||||
const first = (failed[0] || ({} as { uuid: string; reason: string })) as {
|
||||
uuid: string
|
||||
reason: string
|
||||
}
|
||||
const content =
|
||||
failed.length === 1
|
||||
? `1 件衣物识别失败:${first.reason},额度已自动退回`
|
||||
: `${failed.length} 件衣物识别失败,额度已自动退回,可进入详情查看原因`
|
||||
this.setData({ failVisible: true, failText: content, failUuid: first.uuid || '' })
|
||||
},
|
||||
|
||||
onFailCancel() {
|
||||
this.setData({ failVisible: false })
|
||||
},
|
||||
|
||||
onFailConfirm(e: WechatMiniprogram.CustomEvent) {
|
||||
const uuid = this.data.failUuid
|
||||
this.setData({ failVisible: false })
|
||||
if (e.detail.value !== 'ok' || !uuid) return
|
||||
wx.navigateTo({
|
||||
url: `/pages/clothes-detail/clothes-detail?uuid=${uuid}`,
|
||||
fail: (err) => logger.warn(LOG, 'navigateTo 衣物详情失败, err=', err && err.errMsg),
|
||||
})
|
||||
},
|
||||
|
||||
onCategoryTap(e: WechatMiniprogram.TouchEvent) {
|
||||
const index = Number(e.currentTarget.dataset.index)
|
||||
if (index === this.data.activeCategory) return
|
||||
|
||||
@@ -70,4 +70,15 @@
|
||||
<view class="fab" bindtap="onUpload">
|
||||
<view class="icon icon-plus"></view>
|
||||
</view>
|
||||
|
||||
<!-- 处理失败提示:「上传后退出小程序」的失败结果回归告知 -->
|
||||
<v2-overlay
|
||||
visible="{{failVisible}}"
|
||||
type="modal"
|
||||
title="AI 识别失败"
|
||||
content="{{failText}}"
|
||||
buttons="{{failButtons}}"
|
||||
bind:confirm="onFailConfirm"
|
||||
bind:cancel="onFailCancel"
|
||||
/>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user