feat(app): 五轮产品评审迭代 35 项修复(报告域/对话/试衣发型/照片链/合规)

报告域:
- 报告 Tab 列表接入 GET /reports(重启可找回);重新生成采纳新 report_id
- 任务状态前后端大小写归一——轮询完成检测与「导出 PDF」按钮首次真正可达
- FAILED 重试换新幂等键;导出→重生成→再导出幂等冲突死路修复
- PDF 下载前 unlink 可重入;预览页常驻挂载+失败态重试;分享/另存文案拆分

对话页:
- 「内容由 AI 生成」常驻标识(CR-05)+ 快捷问题 chips + 额度 0 置灰与恢复时间
- 发送失败回填输入+重试+request_key 幂等;40301 额度同步

试衣间/发型设计:
- 人脸照片知情同意弹窗(preferences 持久化+版本+「我的」撤回入口)
- 生成期防中断(keepScreenOn/返回挽留/取消出口/genSeq 防串扰)
- 结果转存 filesDir/results:杀 App 回看、飞行模式离线保存、保存三态文案
- R4N1 照片输入链修复:裁除 describe 挂起载体、选图/拍照超时兜底、
  openSource URI 直建失败回退 fd 口径(R5N2)
- @Builder 改 $$ 对象传参修复槽位预览不刷新(R5N1);发型列表三态

全局:
- 会话过期四处「重新登录」出路;UTC 时间显示归正(差 8h)
- 10 处技术黑话清理;主色统一 Theme.ets;配额卡 4 张真实消耗集
- 登录页内测口径;f2 ErrorView/LoadingView 换用;调试入口 debug 守卫

门禁:App 构建 BUILD SUCCESSFUL;后端 576 单测绿(子仓 00ef56b);
28 项静态检查 PASS;真机 PDF 全链/照片送达/零崩溃验证通过
This commit is contained in:
xsl
2026-08-30 23:17:11 +08:00
parent 9e5ce14bce
commit 0b5d151e50
24 changed files with 2151 additions and 426 deletions
+181 -25
View File
@@ -3,6 +3,9 @@
*
* 流程(产品方案 §2.3):上传面部特写 → 点选发型即试戴(5~10s)→ 可换发色 → 保存相册。
* 异常口径:400 用服务端 message 原样提示;失败保留当前图不覆盖。
* 发型库三态(#8/#18):加载中 / 空态 / 失败+重新加载。
* 结果归宿(#18,与 #17 统一):试戴/换发色成功即落 filesDir/results/hair_last.jpg
* (换发色后覆盖为最新版本),保存优先复用该文件,杀 App 后「上次结果」卡可回看。
*/
import { router } from '@kit.ArkUI'
@@ -10,10 +13,13 @@ import { image } from '@kit.ImageKit'
import { util } from '@kit.ArkTS'
import { photoAccessHelper } from '@kit.MediaLibraryKit'
import { fileUri } from '@kit.CoreFileKit'
import fs from '@ohos.file.fs'
import { TryonApi, Hairstyle } from '../core/TryonApi'
import { ImageCodec } from '../core/ImageCodec'
import { ApiError } from '../core/ApiTypes'
import { ContextHolder } from '../core/ContextHolder'
import { COLOR_PRIMARY } from '../core/Theme'
import { FacePhotoConsent, FaceConsentStore } from '../components/f2/FacePhotoConsent'
interface PresetColor {
name: string
@@ -32,7 +38,7 @@ const PRESET_COLORS: PresetColor[] = [
]
const PAGE_BG: string = '#F5F6F8'
const ACCENT: string = '#FF5A79'
const ACCENT: string = COLOR_PRIMARY
const TEXT_PRIMARY: string = '#222222'
const TEXT_SECONDARY: string = '#8A9099'
@@ -42,17 +48,35 @@ struct HairDesignPage {
@State photoUri: string = ''
@State styles: Hairstyle[] = []
@State listError: string = ''
@State listLoaded: boolean = false // 列表三态(#18):false=加载中,true 后看空/错误
@State selectedStyleId: string = ''
@State generating: boolean = false
@State statusText: string = ''
@State resultPm: image.PixelMap | undefined = undefined
@State resultBase64: string = '' // 换发色/保存都用它,避免二次编码
@State resultLocalPath: string = '' // 本机留存副本(#18):保存优先复用
@State lastLocalPath: string = '' // 「上次结果」卡数据源(aboutToAppear 回看,#18)
@State showOriginal: boolean = false
@State colorIdx: number = 1
@State ratio: number = 0.9
@State showFaceConsent: boolean = false
private consentPickCamera: boolean = false // 同意后继续的拍照/相册入口
/** 本机结果留存路径(#18):filesDir/results(cacheDir 有系统配额会被清)。 */
private resultStorePath(): string {
return `${ContextHolder.get().filesDir}/results/hair_last.jpg`
}
aboutToAppear(): void {
this.loadStyles()
// 上次结果回看(#18):沙盒留存最近一次发型结果,杀 App/重启不丢
try {
if (fs.accessSync(this.resultStorePath())) {
this.lastLocalPath = this.resultStorePath()
}
} catch (_e) {
// 目录不存在等:视为无上次结果
}
// 预留:Agent 联动(V2)预选发型,见产品方案 §7
const params = router.getParams() as Record<string, Object> | undefined
if (params !== undefined && typeof params['hairstyle_id'] === 'string') {
@@ -61,14 +85,29 @@ struct HairDesignPage {
}
private async loadStyles(): Promise<void> {
this.listError = ''
this.listLoaded = false
try {
this.styles = await TryonApi.listHairstyles()
} catch (e) {
this.styles = []
this.listError = e instanceof ApiError ? e.message : '发型列表加载失败'
} finally {
this.listLoaded = true
}
}
private async pickPhoto(fromCamera: boolean): Promise<void> {
/** 上传面部特写前须单独同意(CR-01:人脸属敏感个人信息)。 */
private pickPhoto(fromCamera: boolean): void {
if (!FaceConsentStore.isGranted()) {
this.consentPickCamera = fromCamera
this.showFaceConsent = true
return
}
this.doPickPhoto(fromCamera)
}
private async doPickPhoto(fromCamera: boolean): Promise<void> {
try {
const picked = fromCamera ? await ImageCodec.takePhoto() : await ImageCodec.pickFromGallery()
if (picked === undefined) {
@@ -77,6 +116,7 @@ struct HairDesignPage {
this.photoUri = picked.uri
this.resultPm = undefined
this.resultBase64 = ''
this.resultLocalPath = ''
this.selectedStyleId = ''
this.statusText = ''
} catch (e) {
@@ -84,6 +124,17 @@ struct HairDesignPage {
}
}
private onConsentAgree(): void {
FaceConsentStore.grant()
this.showFaceConsent = false
this.doPickPhoto(this.consentPickCamera)
}
private onConsentRefuse(): void {
this.showFaceConsent = false
this.statusText = '未同意照片授权,你可以先浏览下方发型库'
}
private async tryOn(style: Hairstyle): Promise<void> {
if (this.photoUri.length === 0 || this.generating) {
return
@@ -97,6 +148,7 @@ struct HairDesignPage {
this.resultBase64 = await TryonApi.changeHair(buf, style.id)
this.resultPm = await ImageCodec.base64ToPixelMap(this.resultBase64)
this.statusText = '试戴完成,点「对比」看原图'
this.persistResult()
} catch (e) {
this.statusText = e instanceof ApiError ? `${e.message}${e.hint ? ':' + e.hint : ''}` : '生成失败,请重试'
} finally {
@@ -121,6 +173,7 @@ struct HairDesignPage {
this.resultBase64 = await TryonApi.changeHairColor(buf, rgb, this.ratio)
this.resultPm = await ImageCodec.base64ToPixelMap(this.resultBase64)
this.statusText = '换发色完成'
this.persistResult() // 落盘覆盖为最新发色版本(#18 验收④)
} catch (e) {
this.statusText = e instanceof ApiError ? e.message : '换发色失败,请重试'
} finally {
@@ -128,35 +181,70 @@ struct HairDesignPage {
}
}
/** 结果留存(#18):当前结果 Base64 落 filesDir/results/hair_last.jpg;失败不阻断展示。 */
private persistResult(): void {
try {
const path: string = ImageCodec.base64ToPersistFile(this.resultBase64, 'hair_last.jpg')
this.resultLocalPath = path
this.lastLocalPath = path
} catch (_e) {
this.resultLocalPath = '' // 落盘失败:保存时走 base64 现场写缓存兜底
}
}
/** 保存到相册(#18):优先复用本机留存文件(一次写、双用途);留存失败过的现场写缓存兜底。 */
private async saveResult(): Promise<void> {
if (this.resultBase64.length === 0) {
return
}
try {
const path: string = ImageCodec.base64ToCacheFile(this.resultBase64, `hair_${Date.now()}.jpg`)
const helper = photoAccessHelper.getPhotoAccessHelper(ContextHolder.get())
const cfg: photoAccessHelper.PhotoCreationConfig = { fileNameExtension: 'jpg', photoType: photoAccessHelper.PhotoType.IMAGE }
await helper.showAssetsCreationDialog([fileUri.getUriFromPath(path)], [cfg])
this.statusText = '已保存到相册'
} catch {
this.statusText = '已取消保存'
const path: string = this.resultLocalPath.length > 0
? this.resultLocalPath
: ImageCodec.base64ToCacheFile(this.resultBase64, `hair_${Date.now()}.jpg`)
this.statusText = await this.saveFileToGallery(path)
} catch (_e) {
this.statusText = '保存失败,请重试'
}
}
build() {
Column() {
// 顶部标题栏
Row() {
Text('‹ 返回').fontSize(15).fontColor(TEXT_SECONDARY).onClick(() => router.back())
Text('发型设计').fontSize(17).fontWeight(FontWeight.Medium).fontColor(TEXT_PRIMARY)
Text('').width(48)
}
.width('100%')
.padding({ left: 16, right: 16, top: 12, bottom: 12 })
.justifyContent(FlexAlign.SpaceBetween)
.backgroundColor(Color.White)
/**
* 系统保存对话框 → 三态文案(#17/#18 统一口径):
* 返回 URI 列表非空=已保存;空数组=用户取消;抛异常=保存失败(磁盘满等不再谎报成取消)。
*/
private async saveFileToGallery(path: string): Promise<string> {
try {
const helper = photoAccessHelper.getPhotoAccessHelper(ContextHolder.get())
const cfg: photoAccessHelper.PhotoCreationConfig = { fileNameExtension: 'jpg', photoType: photoAccessHelper.PhotoType.IMAGE }
const uris: Array<string> = await helper.showAssetsCreationDialog([fileUri.getUriFromPath(path)], [cfg])
return uris.length > 0 ? '已保存到相册' : '已取消保存'
} catch (_e) {
return '保存失败,请重试'
}
}
Scroll() {
/** 「上次结果」卡的保存(#18):直接走本机副本,不依赖网络。 */
private async saveLastResult(): Promise<void> {
if (this.lastLocalPath.length === 0) {
return
}
this.statusText = await this.saveFileToGallery(this.lastLocalPath)
}
build() {
Stack() {
Column() {
// 顶部标题栏
Row() {
Text('‹ 返回').fontSize(15).fontColor(TEXT_SECONDARY).onClick(() => router.back())
Text('发型设计').fontSize(17).fontWeight(FontWeight.Medium).fontColor(TEXT_PRIMARY)
Text('').width(48)
}
.width('100%')
.padding({ left: 16, right: 16, top: 12, bottom: 12 })
.justifyContent(FlexAlign.SpaceBetween)
.backgroundColor(Color.White)
Scroll() {
Column({ space: 12 }) {
// 照片区:左原图 / 右结果
Row({ space: 12 }) {
@@ -202,7 +290,7 @@ struct HairDesignPage {
.borderRadius(12).backgroundColor('#EDEFF3')
}
Row({ space: 8 }) {
Text('对比')
Text(this.showOriginal ? '看效果' : '对比')
.fontSize(12)
.fontColor(this.resultPm !== undefined ? ACCENT : TEXT_SECONDARY)
.onClick(() => {
@@ -227,6 +315,28 @@ struct HairDesignPage {
Text(this.statusText).fontSize(12).fontColor(TEXT_SECONDARY).width('100%')
}
// 上次发型结果回看(#18):无本次结果时展示留存副本(保存/移除)
if (this.lastLocalPath.length > 0 && this.resultPm === undefined) {
Column({ space: 8 }) {
Text('上次发型结果')
.fontSize(13).fontWeight(FontWeight.Medium).fontColor(TEXT_PRIMARY).width('100%')
Image(fileUri.getUriFromPath(this.lastLocalPath))
.width('100%').height(280).objectFit(ImageFit.Contain)
.borderRadius(12).backgroundColor('#EDEFF3')
Row({ space: 16 }) {
Text('保存到相册').fontSize(13).fontColor(ACCENT)
.onClick(() => { this.saveLastResult() })
Text('知道了').fontSize(13).fontColor(TEXT_SECONDARY)
.onClick(() => { this.lastLocalPath = '' })
}
.width('100%').justifyContent(FlexAlign.Center)
}
.width('100%')
.padding(12)
.borderRadius(12)
.backgroundColor(Color.White)
}
// 发型网格
Text('选择发型(点选即试戴)').fontSize(14).fontWeight(FontWeight.Medium).fontColor(TEXT_PRIMARY)
if (this.styles.length > 0) {
@@ -250,9 +360,41 @@ struct HairDesignPage {
.columnsGap(8)
.rowsGap(8)
.width('100%')
} else if (this.listError.length > 0) {
// 失败态(#8/#18):错误文案 + 重新加载出口
Column({ space: 8 }) {
Text(this.listError).fontSize(12).fontColor('#C0392B')
Text('重新加载')
.fontSize(13).fontColor(ACCENT)
.padding({ left: 16, right: 16, top: 6, bottom: 6 })
.borderRadius(14).backgroundColor(Color.White)
.onClick(() => { this.loadStyles() })
}
.width('100%')
.alignItems(HorizontalAlign.Center)
.padding({ top: 8, bottom: 8 })
} else if (this.listLoaded) {
// 空态(#18):加载成功但无上架发型
Column({ space: 8 }) {
Text('发型暂未上架,稍后再试').fontSize(12).fontColor(TEXT_SECONDARY)
Text('重新加载')
.fontSize(13).fontColor(ACCENT)
.padding({ left: 16, right: 16, top: 6, bottom: 6 })
.borderRadius(14).backgroundColor(Color.White)
.onClick(() => { this.loadStyles() })
}
.width('100%')
.alignItems(HorizontalAlign.Center)
.padding({ top: 8, bottom: 8 })
} else {
Text(this.listError.length > 0 ? this.listError : '发型加载中…')
.fontSize(12).fontColor(TEXT_SECONDARY)
// 加载中(#18):不再让空列表永远停在「加载中」
Row({ space: 8 }) {
LoadingProgress().width(18).height(18).color(ACCENT)
Text('发型加载中…').fontSize(12).fontColor(TEXT_SECONDARY)
}
.width('100%')
.justifyContent(FlexAlign.Center)
.padding({ top: 8, bottom: 8 })
}
// 换发色(有结果才可用)
@@ -296,6 +438,20 @@ struct HairDesignPage {
}
.layoutWeight(1)
.scrollBar(BarState.Off)
}
.width('100%')
.height('100%')
if (this.showFaceConsent) {
FacePhotoConsent({
onAgree: (): void => {
this.onConsentAgree()
},
onRefuse: (): void => {
this.onConsentRefuse()
}
})
}
}
.width('100%')
.height('100%')