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
+23 -4
View File
@@ -1,5 +1,9 @@
import { request } from '../../utils/request'
import { AiRecommendResult, ClothesItem } from '../../types/models'
import { logger } from '../../utils/logger'
// 日志模块名
const LOG = 'ai-recommend'
Page({
data: {
@@ -46,6 +50,7 @@ Page({
success: (res) => {
if (res.confirm) this.doGenerate(sceneType, scene)
},
fail: (e) => logger.debug(LOG, '取消生成确认, err=', e && e.errMsg),
})
},
@@ -58,11 +63,13 @@ Page({
request<AiRecommendResult>({ url: '/ai-recommend', method: 'POST', data: body, showError: false })
.then(async (res) => {
logger.info(LOG, 'AI 推荐生成成功, 单品数=', res.outfit_item && res.outfit_item.length)
const clothes = await Promise.all(
res.outfit_item.map(async (it) => {
try {
return await request<ClothesItem>({ url: `/clothes/${it.clothes_uuid}`, showError: false })
} catch (e) {
} catch (e: any) {
logger.warn(LOG, '单品详情拉取失败, uuid=', it.clothes_uuid, 'code=', e && e.code)
return { clothes_uuid: it.clothes_uuid } as ClothesItem
}
})
@@ -72,6 +79,7 @@ Page({
.catch((e: any) => {
this.setData({ generating: false })
const code = e && e.code
logger.warn(LOG, 'AI 推荐生成失败, code=', code)
if (code === 90400) {
this.setData({ state: 'empty' })
} else if (code === 90401) {
@@ -93,8 +101,14 @@ Page({
confirmText: '去购买',
cancelText: '取消',
success: (res) => {
if (res.confirm) wx.navigateTo({ url: '/pages/mall/mall' })
if (res.confirm) {
wx.navigateTo({
url: '/pages/mall/mall',
fail: (e) => logger.warn(LOG, 'navigateTo 商城失败, err=', e && e.errMsg),
})
}
},
fail: (e) => logger.warn(LOG, '额度弹窗失败, err=', e && e.errMsg),
})
},
@@ -106,14 +120,16 @@ Page({
data: { outfit_uuid: this.data.result.outfit_uuid },
})
.then(() => {
logger.info(LOG, 'AI 穿搭保存成功')
wx.showToast({ title: '已保存到我的穿搭', icon: 'success' })
setTimeout(() => {
wx.redirectTo({
url: `/pages/outfit-detail/outfit-detail?uuid=${this.data.result!.outfit_uuid}&owner=1`,
fail: (e) => logger.warn(LOG, 'redirectTo 穿搭详情失败, err=', e && e.errMsg),
})
}, 500)
})
.catch(() => {})
.catch((e: any) => logger.warn(LOG, 'AI 穿搭保存失败, code=', e && e.code))
},
onReroll() {
@@ -121,6 +137,9 @@ Page({
},
onGoUpload() {
wx.navigateTo({ url: '/pages/upload/upload' })
wx.navigateTo({
url: '/pages/upload/upload',
fail: (e) => logger.warn(LOG, 'navigateTo 上传页失败, err=', e && e.errMsg),
})
},
})