Compare commits
4
Commits
a850735d60
...
f244f14ab8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f244f14ab8 | ||
|
|
fcc506920f | ||
|
|
9161a2013c | ||
|
|
aafacbf020 |
@@ -1,21 +1,22 @@
|
||||
/**
|
||||
* TaskBonusPanel —— 「做任务换额度」任务列表面板(P0-4 / FR-BILL-03/04)。
|
||||
* TaskBonusPanel —— 「做任务换额度」任务列表面板(P0-4 / FR-BILL-03/04,T2b 闭环)。
|
||||
*
|
||||
* 供弹层/区块复用:ProfileContent 入口卡、ChatPage 耗尽面板、试穿/发型软限制
|
||||
* 耗尽面板都以 bindSheet 承载本组件。
|
||||
*
|
||||
* 纪律:
|
||||
* - 任务表本地静态(icon/名称/说明),奖励数值一律不硬编码——展示文案统一
|
||||
* 「领额度」,实际到账以 claim 响应 amount 为准;
|
||||
* - 任务表本地静态(产品方案 §3.2 定稿 4 项,invite_friend/profile_complete 已
|
||||
* 下架);desc 里的奖励数值是定稿展示文案,实际到账仍以 claim 响应 amount 为准;
|
||||
* - 文案纪律(FR-BILL-07):不出现价格/购买/会员/升级字样;
|
||||
* - 已领判定走 core/TaskBonusState(preferences meida_task_bonus 的共享读写,
|
||||
* 与报告页反馈自动 claim 互通),跨重启保留;claim 返回 40910(本周期已领)
|
||||
* 时同步标记——本地状态永远以服务端口径为准;
|
||||
* - 本迭代只接 sign_in 的真实 claim 链路;其余 4 项为「去完成」轻引导 toast,
|
||||
* 完成判定属后续迭代。
|
||||
* 与报告页反馈/分享/首测的自动 claim 互通),跨重启保留;claim 返回 40910
|
||||
* (本周期已领)时同步标记——本地状态永远以服务端口径为准;
|
||||
* - 「去完成」真实跳转:first_report → 速测落地页;report_feedback / share_report
|
||||
* → 报告链路页(无报告时给引导 toast,不报错);sign_in 点击即领。
|
||||
* first_report 在服务端已有完成报告且未领过时直接变为「领额度」走 claim。
|
||||
*/
|
||||
|
||||
import { promptAction } from '@kit.ArkUI'
|
||||
import { promptAction, router } from '@kit.ArkUI'
|
||||
import { ApiClient } from '../../core/ApiClient'
|
||||
import { ApiError } from '../../core/ApiTypes'
|
||||
import { TaskBonusState, PERIOD_DAY, PERIOD_LIFETIME } from '../../core/TaskBonusState'
|
||||
@@ -37,7 +38,17 @@ interface ClaimWire {
|
||||
remaining: number
|
||||
}
|
||||
|
||||
/** 任务定义。direct=true 表示点击即调 claim;false 为「去完成」轻引导。 */
|
||||
/** GET /api/v1/reports 列表元素(本面板只消费这两个字段)。 */
|
||||
interface ReportListItemWire {
|
||||
report_id: string
|
||||
status: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务定义。direct=true 表示点击即调 claim(签到);
|
||||
* false 为「去完成」跳转(first_report 在服务端已有完成报告时升格为可领)。
|
||||
* successToast 是领取成功的 toast 前缀,amount 取响应值拼接。
|
||||
*/
|
||||
interface TaskDef {
|
||||
key: string
|
||||
icon: string
|
||||
@@ -45,36 +56,37 @@ interface TaskDef {
|
||||
desc: string
|
||||
period: string // day / lifetime
|
||||
direct: boolean
|
||||
guide: string // direct=false 时的引导 toast 文案
|
||||
successToast: string
|
||||
}
|
||||
|
||||
/** 五项任务(task_key 与后端 TASK_BONUS_RULES_JSON 对齐)。 */
|
||||
const TASKS: TaskDef[] = [
|
||||
/** 每日任务(task_key 与后端 TASK_BONUS_RULES_JSON 定稿目录对齐)。 */
|
||||
const DAILY_TASKS: TaskDef[] = [
|
||||
{
|
||||
key: 'sign_in', icon: '✓', name: '每日签到', desc: '每天来一次,领 AI 对话额度',
|
||||
period: PERIOD_DAY, direct: true, guide: ''
|
||||
key: 'sign_in', icon: '✓', name: '每日签到', desc: '每日 · 领 10 轮 AI 对话额度',
|
||||
period: PERIOD_DAY, direct: true, successToast: '签到成功'
|
||||
},
|
||||
{
|
||||
key: 'profile_complete', icon: '☺', name: '完善画像资料', desc: '补全资料,建议更合身',
|
||||
period: PERIOD_LIFETIME, direct: false, guide: '完善资料功能即将上线'
|
||||
key: 'report_feedback', icon: '✎', name: '给报告结论打反馈', desc: '每日 · 领 2 次发型试戴额度',
|
||||
period: PERIOD_DAY, direct: false, successToast: '感谢反馈'
|
||||
},
|
||||
{
|
||||
key: 'report_feedback', icon: '✎', name: '给报告结论打反馈', desc: '告诉我们要不要调整',
|
||||
period: PERIOD_DAY, direct: false, guide: '在报告页给结论打反馈可领额度'
|
||||
},
|
||||
{
|
||||
key: 'share_report', icon: '↗', name: '分享我的报告', desc: '把形象报告分享给朋友',
|
||||
period: PERIOD_DAY, direct: false, guide: '生成报告后可分享领额度'
|
||||
},
|
||||
{
|
||||
key: 'invite_friend', icon: '♡', name: '邀请好友', desc: '邀请朋友一起用美搭',
|
||||
period: PERIOD_DAY, direct: false, guide: '邀请功能即将上线'
|
||||
key: 'share_report', icon: '↗', name: '分享我的报告', desc: '每日 · 领 3 次换装额度',
|
||||
period: PERIOD_DAY, direct: false, successToast: '感谢分享'
|
||||
}
|
||||
]
|
||||
|
||||
/** 本周期已领 / 奖励封顶 / 未知任务(与后端 errors.py 对齐)。 */
|
||||
/** 新手任务(一次性)。 */
|
||||
const NEWBIE_TASKS: TaskDef[] = [
|
||||
{
|
||||
key: 'first_report', icon: '★', name: '完成首次形象速测', desc: '一次性 · 领 1 次报告重生成额度',
|
||||
period: PERIOD_LIFETIME, direct: false, successToast: '形象速测完成'
|
||||
}
|
||||
]
|
||||
|
||||
/** 本周期已领 / 奖励封顶 / 任务未完成 / 未知任务(与后端 errors.py 对齐)。 */
|
||||
const CODE_ALREADY_CLAIMED: number = 40910
|
||||
const CODE_BONUS_CAPPED: number = 40310
|
||||
const CODE_NOT_ELIGIBLE: number = 40311
|
||||
|
||||
@Component
|
||||
export struct TaskBonusPanel {
|
||||
@@ -83,15 +95,51 @@ export struct TaskBonusPanel {
|
||||
|
||||
@State claimingKey: string = '' // 领取中的 task_key(防空点)
|
||||
@State claimsTick: number = 0 // claims 变更计数:驱动已领态重渲染
|
||||
@State firstReportReady: boolean = false // 服务端已有完成报告:first_report 可直接领
|
||||
@State latestReportId: string = '' // 报告链路跳转用(优先最新一份已完成报告)
|
||||
|
||||
aboutToAppear(): void {
|
||||
this.hydrate()
|
||||
}
|
||||
|
||||
/** 已领态由 TaskBonusState 共享(报告页反馈自动 claim 也要互通),这里只 hydrate + 触发重渲染。 */
|
||||
/** 已领态由 TaskBonusState 共享(报告页自动 claim 也要互通):hydrate + 曝光埋点 + 报告态探测。 */
|
||||
private async hydrate(): Promise<void> {
|
||||
await TaskBonusState.init()
|
||||
this.claimsTick += 1
|
||||
Tracker.track('task_bonus.panel_view')
|
||||
this.refreshReportState()
|
||||
}
|
||||
|
||||
/** 拉我的报告列表,定 first_report 可领态与报告链路跳转目标;失败静默(点击时再实时拉)。 */
|
||||
private async refreshReportState(): Promise<void> {
|
||||
try {
|
||||
const list = await ApiClient.get<ReportListItemWire[]>('/api/v1/reports')
|
||||
const succeeded: ReportListItemWire | undefined =
|
||||
list.find((r: ReportListItemWire) => r.status === 'succeeded')
|
||||
this.firstReportReady = succeeded !== undefined
|
||||
this.latestReportId = succeeded !== undefined
|
||||
? succeeded.report_id
|
||||
: (list.length > 0 ? list[0].report_id : '')
|
||||
} catch (_e) {
|
||||
// 网络失败不打扰:面板其余功能照常,「去完成」点击时再拉一次
|
||||
}
|
||||
}
|
||||
|
||||
/** 实时取最新报告 id(跳转前兜底再拉一次,hydrate 失败也能补救);无报告返回 ''。 */
|
||||
private async fetchLatestReportId(): Promise<string> {
|
||||
try {
|
||||
const list = await ApiClient.get<ReportListItemWire[]>('/api/v1/reports')
|
||||
const succeeded: ReportListItemWire | undefined =
|
||||
list.find((r: ReportListItemWire) => r.status === 'succeeded')
|
||||
const rid: string = succeeded !== undefined
|
||||
? succeeded.report_id
|
||||
: (list.length > 0 ? list[0].report_id : '')
|
||||
this.latestReportId = rid
|
||||
this.firstReportReady = succeeded !== undefined
|
||||
return rid
|
||||
} catch (_e) {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
private isClaimed(task: TaskDef): boolean {
|
||||
@@ -115,12 +163,36 @@ export struct TaskBonusPanel {
|
||||
if (this.isClaimed(task) || this.claimingKey !== '') {
|
||||
return
|
||||
}
|
||||
if (!task.direct) {
|
||||
// 「去完成」轻引导:本迭代不接真实完成判定
|
||||
this.toast(task.guide)
|
||||
Tracker.track('task_bonus.task_tap', { 'task_key': task.key })
|
||||
if (task.direct) {
|
||||
this.claim(task)
|
||||
return
|
||||
}
|
||||
this.claim(task)
|
||||
if (task.key === 'first_report') {
|
||||
if (this.firstReportReady) {
|
||||
// 服务端已有完成报告且未领过:直接领(服务端还会再校验一次 rp_report)
|
||||
this.claim(task)
|
||||
} else {
|
||||
router.pushUrl({ url: 'pages/DiagnosisLandingPage' })
|
||||
}
|
||||
return
|
||||
}
|
||||
// report_feedback / share_report:跳报告链路页(反馈在报告结果页,分享经
|
||||
// 报告结果页导出 PDF 后到预览页;ReportPdfPage 需要本地 pdfPath 无法直达)
|
||||
this.goReportChain()
|
||||
}
|
||||
|
||||
private async goReportChain(): Promise<void> {
|
||||
let rid: string = this.latestReportId
|
||||
if (rid === '') {
|
||||
rid = await this.fetchLatestReportId()
|
||||
}
|
||||
if (rid === '') {
|
||||
this.toast('先生成你的形象速测,再来反馈')
|
||||
return
|
||||
}
|
||||
const params: Record<string, Object> = { 'reportId': rid }
|
||||
router.pushUrl({ url: 'pages/ReportResultPage', params: params })
|
||||
}
|
||||
|
||||
private async claim(task: TaskDef): Promise<void> {
|
||||
@@ -129,7 +201,7 @@ export struct TaskBonusPanel {
|
||||
const req: Record<string, Object> = {}
|
||||
const d = await ApiClient.post<ClaimWire>(`/api/v1/quota/tasks/${task.key}/claim`, req)
|
||||
await this.markClaimed(task)
|
||||
this.toast(`签到成功,额度 +${d.amount}`)
|
||||
this.toast(`${task.successToast},额度 +${d.amount}`)
|
||||
Tracker.track('task_bonus.claim_result', { 'task_key': task.key, 'ok': true })
|
||||
this.onClaimed(d.quota_key)
|
||||
} catch (e) {
|
||||
@@ -139,7 +211,9 @@ export struct TaskBonusPanel {
|
||||
await this.markClaimed(task)
|
||||
this.toast('今天已经领过啦')
|
||||
} else if (err.code === CODE_BONUS_CAPPED) {
|
||||
this.toast('今日任务奖励已达上限')
|
||||
this.toast('今日任务奖励已达上限,明天再来')
|
||||
} else if (err.code === CODE_NOT_ELIGIBLE) {
|
||||
this.toast('先完成任务,再来领奖励')
|
||||
} else {
|
||||
this.toast(err.message)
|
||||
}
|
||||
@@ -157,7 +231,10 @@ export struct TaskBonusPanel {
|
||||
if (this.claimingKey === task.key) {
|
||||
return '领取中…'
|
||||
}
|
||||
return task.direct ? '领额度' : '去完成'
|
||||
if (task.direct || (task.key === 'first_report' && this.firstReportReady)) {
|
||||
return '领额度'
|
||||
}
|
||||
return '去完成'
|
||||
}
|
||||
|
||||
@Builder
|
||||
@@ -197,6 +274,15 @@ export struct TaskBonusPanel {
|
||||
.alignItems(VerticalAlign.Center)
|
||||
}
|
||||
|
||||
@Builder
|
||||
GroupHeader(title: string) {
|
||||
Text(title)
|
||||
.fontSize(13)
|
||||
.fontColor(COLOR_TEXT_SECONDARY)
|
||||
.width('100%')
|
||||
.margin({ top: 8, bottom: 2 })
|
||||
}
|
||||
|
||||
build() {
|
||||
Column({ space: 4 }) {
|
||||
Text('做任务换额度')
|
||||
@@ -205,7 +291,12 @@ export struct TaskBonusPanel {
|
||||
.fontColor(COLOR_TEXT_PRIMARY)
|
||||
.width('100%')
|
||||
.margin({ bottom: 4 })
|
||||
ForEach(TASKS, (task: TaskDef) => {
|
||||
this.GroupHeader('每日任务')
|
||||
ForEach(DAILY_TASKS, (task: TaskDef) => {
|
||||
this.TaskRow(task)
|
||||
}, (task: TaskDef) => `${task.key}_${this.isClaimed(task)}`)
|
||||
this.GroupHeader('新手任务')
|
||||
ForEach(NEWBIE_TASKS, (task: TaskDef) => {
|
||||
this.TaskRow(task)
|
||||
}, (task: TaskDef) => `${task.key}_${this.isClaimed(task)}`)
|
||||
Text('奖励以实际到账为准,额度每日重置')
|
||||
|
||||
@@ -22,7 +22,7 @@ import { COLOR_PRIMARY } from '../../core/Theme'
|
||||
const CONSENT_STORAGE_KEY: string = 'face_photo_consent_granted'
|
||||
const CONSENT_PREF_NAME: string = 'meida_face_consent'
|
||||
const CONSENT_RECORD_KEY: string = 'record'
|
||||
const CONSENT_VERSION: string = 'v1'
|
||||
const CONSENT_VERSION: string = 'v2' // v2:处理方/保存文案按本地磁盘降级路线改为属实表述(2026-09-12)
|
||||
const TEXT_PRIMARY: string = '#222222'
|
||||
const TEXT_SECONDARY: string = '#8A9099'
|
||||
const ACCENT: string = COLOR_PRIMARY
|
||||
@@ -103,6 +103,8 @@ export class FaceConsentStore {
|
||||
export struct FacePhotoConsent {
|
||||
onAgree: () => void = () => {}
|
||||
onRefuse: () => void = () => {}
|
||||
/** 用途说明行:默认试穿/发型场景口径;诊断报告等场景传入自己的文案。 */
|
||||
usageText: string = '用途:照片仅用于为你生成试穿/发型效果图,不用于识别你的身份,也不做其他用途的分析。'
|
||||
|
||||
@Builder
|
||||
ConsentLine(bullet: string, text: string) {
|
||||
@@ -128,9 +130,9 @@ export struct FacePhotoConsent {
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.fontColor(TEXT_PRIMARY)
|
||||
Column({ space: 8 }) {
|
||||
this.ConsentLine('·', '用途:照片仅用于为你生成试穿/发型效果图,不用于识别你的身份,也不做其他用途的分析。')
|
||||
this.ConsentLine('·', '处理方:照片将上传至第三方 AI 图像服务完成本次生成,不会共享给其他方。')
|
||||
this.ConsentLine('·', '保存:原图在生成完成后即删除;你保存到相册的效果图可随时自行删除。')
|
||||
this.ConsentLine('·', this.usageText)
|
||||
this.ConsentLine('·', '处理方:照片将上传至美搭的图像服务完成本次生成,不会共享给其他方。')
|
||||
this.ConsentLine('·', '保存:上传的原图不会公开展示;你保存到相册的效果图可随时自行删除。')
|
||||
}
|
||||
.width('100%')
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
|
||||
@@ -264,12 +264,6 @@ export function randomHex(len: number): string {
|
||||
return out
|
||||
}
|
||||
|
||||
/** 模拟照片对象键:report_photo/{userId}/{随机}.jpg(V1 骨架,COS 直传未接入) */
|
||||
export function buildMockPhotoKey(userId: string): string {
|
||||
const uid = userId === '' ? 'anonymous' : userId
|
||||
return `report_photo/${uid}/${randomHex(12)}.jpg`
|
||||
}
|
||||
|
||||
/** 32 维按 status 分两组:已分析(ok)与未覆盖(skipped,含 status 缺失的兜底) */
|
||||
export function splitDimensions(dims: DimensionWire[]): DimensionGroups {
|
||||
const groups: DimensionGroups = { analyzed: [], skipped: [] }
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
* - 不依赖 queueMode:官方 API 文档(0=flush)与 Codelabs(0=排队)说法
|
||||
* 互相矛盾,新朗读前显式 engine.stop() 打断,语义自持
|
||||
* - 播报状态回调 onStateChanged:页面据此复位 🔊 图标
|
||||
* - V3:speak 前 sanitizeForSpeech 净化——不念 Markdown/英文标点/表情符号
|
||||
* (中文停顿标点保留做自然停顿)
|
||||
*
|
||||
* 模型:offline 中文引擎(online: 1,系统内置);模拟器通常无此服务,须真机。
|
||||
* 日志 tag MEIDA_TTS:hdc shell hilog | grep MEIDA_TTS
|
||||
@@ -18,6 +20,18 @@ import { textToSpeech } from '@kit.CoreSpeechKit'
|
||||
const SEGMENT_MAX_CHARS: number = 400
|
||||
const SEGMENT_FALLBACK_MS: number = 150000
|
||||
|
||||
/**
|
||||
* 朗读净化(V3):剥掉会被引擎念出来的符号——Markdown 标记(**、#、- 列表符)、
|
||||
* 英文标点、表情等,只留中英文、数字与中文停顿标点(,。;:!?、……靠它们做自然停顿,
|
||||
* 引擎不会逐字念)。顾问回答被要求不写 Markdown(agent_chat v1),这里是双保险。
|
||||
*/
|
||||
function sanitizeForSpeech(text: string): string {
|
||||
return text
|
||||
.replace(/[^一-龥a-zA-Z0-9\s。,、;:!?]/g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim()
|
||||
}
|
||||
|
||||
/** 播报状态变化回调(speaking=false 表示本轮朗读完全结束或被停止)。 */
|
||||
export type TtsStateChanged = (speaking: boolean) => void
|
||||
|
||||
@@ -78,7 +92,7 @@ export class TtsEngine {
|
||||
* 由调用方决定是否提示(自动朗读静默、手动点击提示)。
|
||||
*/
|
||||
async speak(text: string): Promise<void> {
|
||||
const trimmed: string = text.trim()
|
||||
const trimmed: string = sanitizeForSpeech(text)
|
||||
if (trimmed.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -26,28 +26,30 @@ interface HairFormPart {
|
||||
const HAIR_BOUNDARY: string = '----MeidaHairForm7MA4YWxkTrZu0gW'
|
||||
|
||||
/**
|
||||
* 发型性别映射:服务端 hairstyles 接口无性别字段,60 款由缩略图视觉分类
|
||||
* (2026-09-02,男 26 / 女 34,抽检校准)。新增未知 id 返回 unknown(前端两个 Tab 都展示)。
|
||||
* 发型性别映射:服务端 hairstyles 接口无性别字段,60 款由缩略图逐张视觉分类。
|
||||
* 2026-09-11 全量重分类(男 30 / 女 30,无 unknown):缩略图按男模/女模实拍渲染,
|
||||
* 以模特呈现为准(此前 2026-09-02 版抽检不准,男/女 Tab 互串 18 款,用户反馈后重分)。
|
||||
* 新增未知 id 返回 unknown(前端两个 Tab 都展示)。
|
||||
*/
|
||||
const MALE_HAIRSTYLE_IDS: Set<string> = new Set<string>([
|
||||
'1953267161121464322', '1953267288284372994', '1953270724765720577', '1953271922151432194',
|
||||
'1953272913265467394', '1953288800932503554', '1954536242109784066', '1954536297776586754',
|
||||
'1954536402516746241', '1954536893304840194', '1954536956919848962', '1954537191729569793',
|
||||
'1980314032369082369', '1980314209322573825', '1980314290419441665', '1980314381058351106',
|
||||
'1980368588293578754', '1980413320612847618', '1980415346071609345', '1980415897056354306',
|
||||
'1981177324700549122', '1981177378714796034', '1981177477423546370', '1981177594750812162',
|
||||
'1980312945301954561', '1980314209322573825', '1980314710101499906', '1980314764421931009',
|
||||
'1980314868713299969', '1980367781510815746', '1980367800787836929', '1980367852847538177',
|
||||
'1980367968627105793', '1980368109866098690', '1980368205752082434', '1980368465631158274',
|
||||
'1980368588293578754', '1981177378714796034', '1981177477423546370', '1981177594750812162',
|
||||
'1981177742742634497', '1981177931859607554'
|
||||
])
|
||||
const FEMALE_HAIRSTYLE_IDS: Set<string> = new Set<string>([
|
||||
'1953270523594317826', '1954537022875279362', '1954537085882114050', '1954537709436706817',
|
||||
'1954537743532204034', '1954537961069780994', '1954538119216013313', '1954538156499181569',
|
||||
'1954538259330932738', '1954538335306555393', '1980312945301954561', '1980313052302843905',
|
||||
'1980313166576656385', '1980313210109337601', '1980313433502162946', '1980313576506957825',
|
||||
'1980313740403580930', '1980313819915001858', '1980314477720281090', '1980314710101499906',
|
||||
'1980314764421931009', '1980314868713299969', '1980315179934851074', '1980315238260842497',
|
||||
'1980361636742209537', '1980367742952579074', '1980367781510815746', '1980367800787836929',
|
||||
'1980367852847538177', '1980367968627105793', '1980368109866098690', '1980368205752082434',
|
||||
'1980368368847593473', '1980368465631158274'
|
||||
'1954538259330932738', '1954538335306555393', '1980313052302843905', '1980313166576656385',
|
||||
'1980313210109337601', '1980313433502162946', '1980313576506957825', '1980313740403580930',
|
||||
'1980313819915001858', '1980314032369082369', '1980314290419441665', '1980314381058351106',
|
||||
'1980314477720281090', '1980315179934851074', '1980315238260842497', '1980361636742209537',
|
||||
'1980367742952579074', '1980368368847593473', '1980413320612847618', '1980415346071609345',
|
||||
'1980415897056354306', '1981177324700549122'
|
||||
])
|
||||
|
||||
const TRYON_DOMAIN: number = 0x0200
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* UploadApi:诊断照片直传本机后端(无 COS 四件套的本地磁盘降级路线)。
|
||||
*
|
||||
* 后端 POST /api/v1/uploads/direct 收原始字节(后端仓库未引入
|
||||
* python-multipart,不收 multipart 表单;这也正好绕开真机
|
||||
* http.multiFormDataList 的 0 字节 bug):
|
||||
* - body 即图片字节(ImageCodec.toJpegBuffer 压缩后的 JPEG)
|
||||
* - Content-Type 头申报类型;scene 走 query(默认 report_photo)
|
||||
* - 响应走统一信封,data.object_key 回传给 POST /api/v1/reports
|
||||
*
|
||||
* 错误一律抛 ApiError(与 ApiClient 约定一致,UI 层只 catch ApiError)。
|
||||
* 鉴权头从 AuthStore 取;401 自动刷新不在此处做(与 TryonApi 同口径,
|
||||
* 令牌过期由下一次 ApiClient 请求兜底刷新)。
|
||||
*/
|
||||
|
||||
import http from '@ohos.net.http'
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit'
|
||||
import { ApiError } from './ApiTypes'
|
||||
import { AuthStore } from './AuthStore'
|
||||
|
||||
const UPLOAD_DOMAIN: number = 0x0201
|
||||
const UPLOAD_TAG: string = 'MEIDA_UPLOAD'
|
||||
const UPLOAD_READ_TIMEOUT_MS: number = 60000 // 压缩后单张 ~300KB,60s 覆盖弱网
|
||||
|
||||
/** POST /uploads/direct 响应的 data 段(字段名对齐后端 JSON)。 */
|
||||
export interface DirectUploadData {
|
||||
object_key?: string
|
||||
size_bytes?: number
|
||||
content_type?: string
|
||||
}
|
||||
|
||||
/** 直传响应信封(同 ApiEnvelope 形状,data 可选以防御后端缺省)。 */
|
||||
interface DirectUploadWire {
|
||||
code: number
|
||||
message: string
|
||||
data?: DirectUploadData
|
||||
hint?: string
|
||||
}
|
||||
|
||||
export class UploadApi {
|
||||
/**
|
||||
* 上传诊断照片(已压缩 JPEG 字节),返回真实 object_key。
|
||||
* 失败抛 ApiError(message/hint 用服务端信封原文,可直接展示重试)。
|
||||
*/
|
||||
static async uploadReportPhoto(imageBuf: ArrayBuffer): Promise<string> {
|
||||
const token = AuthStore.getAccessToken()
|
||||
if (token === undefined) {
|
||||
// 与 ApiClient 同一纪律:未登录直接短路,省一次必然 401 的往返
|
||||
throw new ApiError(40100, '请先登录', '登录后即可继续')
|
||||
}
|
||||
const base = await AuthStore.getBaseUrl()
|
||||
const url = `${base}/api/v1/uploads/direct?scene=report_photo`
|
||||
const client = http.createHttp()
|
||||
try {
|
||||
const header: Record<string, string> = {
|
||||
'Content-Type': 'image/jpeg',
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
hilog.info(UPLOAD_DOMAIN, UPLOAD_TAG, 'direct post %{public}s, %{public}d bytes', url, imageBuf.byteLength)
|
||||
const resp = await client.request(url, {
|
||||
method: http.RequestMethod.POST,
|
||||
header: header,
|
||||
extraData: imageBuf,
|
||||
expectDataType: http.HttpDataType.STRING,
|
||||
connectTimeout: 10000,
|
||||
readTimeout: UPLOAD_READ_TIMEOUT_MS
|
||||
})
|
||||
const bodyText: string = (resp.result ?? '') as string
|
||||
hilog.info(UPLOAD_DOMAIN, UPLOAD_TAG, 'direct resp code=%{public}d body=%{public}s',
|
||||
resp.responseCode, bodyText.substring(0, 300))
|
||||
let wire: DirectUploadWire
|
||||
try {
|
||||
wire = JSON.parse(bodyText) as DirectUploadWire
|
||||
} catch (_p) {
|
||||
// 网关/代理层错误:body 不是信封 JSON,给统一话术(对齐 ApiClient)
|
||||
throw new ApiError(50000, '服务开小差了', '请稍后重试', resp.responseCode)
|
||||
}
|
||||
const key = wire.data?.object_key ?? ''
|
||||
if (wire.code === 0 && key !== '') {
|
||||
return key
|
||||
}
|
||||
if (wire.code !== 0) {
|
||||
throw new ApiError(wire.code, wire.message, wire.hint, resp.responseCode)
|
||||
}
|
||||
// code=0 但没有 object_key:契约破损,按服务端异常处理
|
||||
throw new ApiError(50000, '照片上传结果异常', '请稍后重试', resp.responseCode)
|
||||
} catch (e) {
|
||||
if (e instanceof ApiError) {
|
||||
throw e
|
||||
}
|
||||
hilog.error(UPLOAD_DOMAIN, UPLOAD_TAG, 'direct request failed: %{public}s', String(e))
|
||||
throw new ApiError(50000, '照片上传失败,请检查网络', '请稍后重试')
|
||||
} finally {
|
||||
client.destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ interface QuotaWireResp {
|
||||
quota_key: string
|
||||
used: number
|
||||
limit_value: number
|
||||
bonus_granted: boolean
|
||||
bonus_granted: number
|
||||
remaining: number
|
||||
reset_at: string
|
||||
}
|
||||
|
||||
@@ -0,0 +1,474 @@
|
||||
/**
|
||||
* HairColorPage —— 换发色独立页(从发型设计页拆出,2026-09 按用户反馈),Phase A 直连线上服务。
|
||||
*
|
||||
* 交互:上传面部特写 → 点选发色(8 色圆点)+ 强度滑杆 → 吸底「换发色」按钮触发(5~10s)
|
||||
* → 图片区「原图/效果图」页签对比(无结果时效果图页签置灰)→ 保存相册。
|
||||
* 每次都在原图上换色(不在结果上叠加),换色效果可预期;失败保留当前图不覆盖。
|
||||
* 每日额度与发型试戴共用 hairstyle key(P0-5 合并计数)。
|
||||
*/
|
||||
|
||||
import { router } from '@kit.ArkUI'
|
||||
import { image } from '@kit.ImageKit'
|
||||
import { photoAccessHelper } from '@kit.MediaLibraryKit'
|
||||
import { fileUri } from '@kit.CoreFileKit'
|
||||
import { TryonApi } from '../core/TryonApi'
|
||||
import { ImageCodec } from '../core/ImageCodec'
|
||||
import { ApiClient } from '../core/ApiClient'
|
||||
import { ApiError } from '../core/ApiTypes'
|
||||
import { DailyLimiter } from '../core/DailyLimiter'
|
||||
import { Tracker } from '../core/Tracker'
|
||||
import { ContextHolder } from '../core/ContextHolder'
|
||||
import {
|
||||
COLOR_PRIMARY,
|
||||
COLOR_PAGE_BG,
|
||||
COLOR_TEXT_PRIMARY,
|
||||
COLOR_TEXT_SECONDARY,
|
||||
COLOR_TEXT_DISABLED,
|
||||
COLOR_DIVIDER,
|
||||
COLOR_IMAGE_BG,
|
||||
COLOR_BADGE_BG
|
||||
} from '../core/Theme'
|
||||
import { ColorDot } from '../components/f2/ColorDot'
|
||||
import { FacePhotoConsent, FaceConsentStore } from '../components/f2/FacePhotoConsent'
|
||||
import { TaskBonusPanel } from '../components/f1/TaskBonusPanel'
|
||||
|
||||
/** GET /api/v1/quota?quota_key=hairstyle 响应(与发型设计页同一配额池)。 */
|
||||
interface HairQuotaWire {
|
||||
quota_key: string
|
||||
used: number
|
||||
limit_value: number
|
||||
bonus_granted: number
|
||||
remaining: number
|
||||
reset_at: string | null
|
||||
}
|
||||
|
||||
interface PresetColor {
|
||||
name: string
|
||||
rgb: number[]
|
||||
}
|
||||
|
||||
const PRESET_COLORS: PresetColor[] = [
|
||||
{ name: '自然黑', rgb: [30, 30, 30] },
|
||||
{ name: '深棕', rgb: [74, 48, 36] },
|
||||
{ name: '栗色', rgb: [128, 70, 42] },
|
||||
{ name: '蜜茶', rgb: [156, 108, 66] },
|
||||
{ name: '亚麻', rgb: [150, 140, 130] },
|
||||
{ name: '酒红', rgb: [128, 32, 48] },
|
||||
{ name: '奶奶灰', rgb: [160, 160, 165] },
|
||||
{ name: '蓝黑', rgb: [40, 50, 70] }
|
||||
]
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct HairColorPage {
|
||||
@State photoUri: string = ''
|
||||
@State generating: boolean = false
|
||||
@State statusText: string = ''
|
||||
@State resultPm: image.PixelMap | undefined = undefined
|
||||
@State resultBase64: string = '' // 保存用它,避免二次编码
|
||||
@State imageTab: number = 0 // 图片区页签:0=原图 1=效果图(无结果时置灰)
|
||||
@State colorIdx: number = 1 // 默认深棕
|
||||
@State ratio: number = 0.9
|
||||
@State showFaceConsent: boolean = false
|
||||
// —— 每日额度(P0-5:与发型试戴共用 hairstyle key,免费档 3 次/天)——
|
||||
@State hairRemaining: number = -1 // -1=未加载(放行);≥0 为 min(服务端, 端侧) 剩余
|
||||
@State showQuotaBlocked: boolean = false
|
||||
@State showTaskPanel: boolean = false
|
||||
private consentPickCamera: boolean = false
|
||||
private imageTabs: string[] = ['原图', '效果图']
|
||||
|
||||
aboutToAppear(): void {
|
||||
this.loadHairRemaining()
|
||||
}
|
||||
|
||||
/** 额度口径与发型设计页一致:min(服务端, 端侧 DailyLimiter),拉取失败静默用端侧。 */
|
||||
private async loadHairRemaining(): Promise<void> {
|
||||
await DailyLimiter.init()
|
||||
try {
|
||||
const q = await ApiClient.get<HairQuotaWire>('/api/v1/quota?quota_key=hairstyle')
|
||||
DailyLimiter.setBonus('hairstyle', q.bonus_granted)
|
||||
this.hairRemaining = Math.min(q.remaining, DailyLimiter.remaining('hairstyle'))
|
||||
} catch (_e) {
|
||||
this.hairRemaining = DailyLimiter.remaining('hairstyle')
|
||||
}
|
||||
}
|
||||
|
||||
/** RGB 分量转两位 hex(发色圆点展示用)。 */
|
||||
private hex2(v: number): string {
|
||||
const s: string = v.toString(16)
|
||||
return s.length < 2 ? `0${s}` : s
|
||||
}
|
||||
|
||||
/** PRESET_COLORS 的 RGB 转 #RRGGBB:仅圆点展示,发色接口 rgb 传参格式不变。 */
|
||||
private colorHex(rgb: number[]): string {
|
||||
return `#${this.hex2(rgb[0])}${this.hex2(rgb[1])}${this.hex2(rgb[2])}`
|
||||
}
|
||||
|
||||
/** 上传面部特写前须单独同意(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) {
|
||||
return
|
||||
}
|
||||
this.photoUri = picked.uri
|
||||
this.resultPm = undefined
|
||||
this.resultBase64 = ''
|
||||
this.imageTab = 0
|
||||
this.statusText = ''
|
||||
} catch (e) {
|
||||
this.statusText = e instanceof ApiError ? e.message : '读取照片失败'
|
||||
}
|
||||
}
|
||||
|
||||
private onConsentAgree(): void {
|
||||
FaceConsentStore.grant()
|
||||
this.showFaceConsent = false
|
||||
this.doPickPhoto(this.consentPickCamera)
|
||||
}
|
||||
|
||||
private onConsentRefuse(): void {
|
||||
this.showFaceConsent = false
|
||||
this.statusText = '未同意照片授权,你可以先看看色板'
|
||||
}
|
||||
|
||||
/** 吸底按钮触发:在当前原图上换发色(不在结果上叠加,效果可预期)。 */
|
||||
private async applyColor(): Promise<void> {
|
||||
if (this.photoUri.length === 0 || this.generating) {
|
||||
return
|
||||
}
|
||||
// 每日额度耗尽(P0-5,与试戴合并计数同一 hairstyle key):不发请求,给出路
|
||||
if (this.hairRemaining === 0) {
|
||||
Tracker.track('haircolor.generate', { 'ok': false, 'duration_s': 0, 'blocked': true })
|
||||
this.showQuotaBlocked = true
|
||||
return
|
||||
}
|
||||
const startMs: number = Date.now()
|
||||
this.generating = true
|
||||
const c: PresetColor = PRESET_COLORS[this.colorIdx]
|
||||
this.statusText = `正在换发色(${c.name})…`
|
||||
try {
|
||||
const buf = await ImageCodec.toJpegBuffer(this.photoUri)
|
||||
const rgb: string = `[${c.rgb[0]}, ${c.rgb[1]}, ${c.rgb[2]}]`
|
||||
this.resultBase64 = await TryonApi.changeHairColor(buf, rgb, this.ratio)
|
||||
this.resultPm = await ImageCodec.base64ToPixelMap(this.resultBase64)
|
||||
this.imageTab = 1 // 成功自动切到效果图页签
|
||||
this.statusText = '换发色完成,点「原图」页签可对比'
|
||||
// 成功才计数(与试戴同一 hairstyle key,合并计算每日额度)
|
||||
DailyLimiter.tryConsume('hairstyle')
|
||||
this.hairRemaining = DailyLimiter.remaining('hairstyle')
|
||||
Tracker.track('haircolor.generate', {
|
||||
'ok': true, 'duration_s': Math.round((Date.now() - startMs) / 1000), 'blocked': false
|
||||
})
|
||||
} catch (e) {
|
||||
Tracker.track('haircolor.generate', {
|
||||
'ok': false, 'duration_s': Math.round((Date.now() - startMs) / 1000), 'blocked': false
|
||||
})
|
||||
this.statusText = e instanceof ApiError ? e.message : '换发色失败,请重试'
|
||||
} finally {
|
||||
this.generating = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 保存到相册:结果 Base64 现场写缓存文件 → 系统保存对话框(取消/失败三态文案)。 */
|
||||
private async saveResult(): Promise<void> {
|
||||
if (this.resultBase64.length === 0) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const path: string = ImageCodec.base64ToCacheFile(this.resultBase64, `haircolor_${Date.now()}.jpg`)
|
||||
this.statusText = await this.saveFileToGallery(path)
|
||||
} catch (_e) {
|
||||
this.statusText = '保存失败,请重试'
|
||||
}
|
||||
}
|
||||
|
||||
/** 系统保存对话框 → 三态文案(与发型设计页统一口径)。 */
|
||||
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 '保存失败,请重试'
|
||||
}
|
||||
}
|
||||
|
||||
/** 今日额度耗尽的引导 overlay(P0-5):不发请求,给「做任务换额度」出路。 */
|
||||
@Builder
|
||||
QuotaBlockedDialog() {
|
||||
Column() {
|
||||
Column({ space: 14 }) {
|
||||
Text('今日换发色额度已用完')
|
||||
.fontSize(17)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.fontColor(COLOR_TEXT_PRIMARY)
|
||||
Text('明天再来,或做任务多换几次')
|
||||
.fontSize(13)
|
||||
.fontColor(COLOR_TEXT_SECONDARY)
|
||||
.textAlign(TextAlign.Center)
|
||||
Row({ space: 12 }) {
|
||||
Button('知道了')
|
||||
.layoutWeight(1)
|
||||
.height(40)
|
||||
.fontSize(14)
|
||||
.backgroundColor(COLOR_IMAGE_BG)
|
||||
.fontColor(COLOR_TEXT_PRIMARY)
|
||||
.onClick(() => {
|
||||
this.showQuotaBlocked = false
|
||||
})
|
||||
Button('做任务换额度')
|
||||
.layoutWeight(1)
|
||||
.height(40)
|
||||
.fontSize(14)
|
||||
.backgroundColor(COLOR_PRIMARY)
|
||||
.onClick(() => {
|
||||
this.showQuotaBlocked = false
|
||||
this.showTaskPanel = true
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.margin({ top: 4 })
|
||||
}
|
||||
.width('82%')
|
||||
.padding(20)
|
||||
.borderRadius(16)
|
||||
.backgroundColor(Color.White)
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.backgroundColor(COLOR_BADGE_BG)
|
||||
.justifyContent(FlexAlign.Center)
|
||||
}
|
||||
|
||||
/** 「做任务换额度」半屏面板(P0-4):到账后重拉额度。 */
|
||||
@Builder
|
||||
TaskBonusSheet() {
|
||||
TaskBonusPanel({
|
||||
onClaimed: (_quotaKey: string): void => {
|
||||
this.loadHairRemaining()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
build() {
|
||||
Stack() {
|
||||
Column() {
|
||||
// 顶部标题栏
|
||||
Row() {
|
||||
Text('‹ 返回').fontSize(15).fontColor(COLOR_TEXT_SECONDARY).onClick(() => router.back())
|
||||
Text('换发色').fontSize(17).fontWeight(FontWeight.Medium).fontColor(COLOR_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() {
|
||||
ForEach(this.imageTabs, (label: string, idx: number) => {
|
||||
Text(label)
|
||||
.fontSize(13)
|
||||
.fontColor(idx === 1 && this.resultPm === undefined
|
||||
? COLOR_TEXT_DISABLED
|
||||
: (this.imageTab === idx ? Color.White : COLOR_TEXT_PRIMARY))
|
||||
.backgroundColor(this.imageTab === idx && !(idx === 1 && this.resultPm === undefined)
|
||||
? COLOR_PRIMARY
|
||||
: Color.Transparent)
|
||||
.padding({ left: 20, right: 20, top: 7, bottom: 7 })
|
||||
.borderRadius(16)
|
||||
.onClick(() => {
|
||||
if (idx === 1 && this.resultPm === undefined) {
|
||||
return // 无结果:效果图页签不响应
|
||||
}
|
||||
this.imageTab = idx
|
||||
})
|
||||
}, (label: string) => label)
|
||||
}
|
||||
.padding(2)
|
||||
.borderRadius(18)
|
||||
.backgroundColor(COLOR_IMAGE_BG)
|
||||
.alignSelf(ItemAlign.Start)
|
||||
|
||||
// 图片区(单区域):无照片=上传入口;生成中=loading;按页签显示原图/效果图
|
||||
Stack({ alignContent: Alignment.BottomStart }) {
|
||||
if (this.photoUri.length === 0) {
|
||||
Column({ space: 6 }) {
|
||||
Text('+').fontSize(28).fontColor(COLOR_TEXT_SECONDARY)
|
||||
Text('上传面部特写').fontSize(12).fontColor(COLOR_TEXT_SECONDARY)
|
||||
}
|
||||
.width('100%').height(320).justifyContent(FlexAlign.Center)
|
||||
.borderRadius(12).backgroundColor(COLOR_IMAGE_BG)
|
||||
.onClick(() => { this.pickPhoto(false) })
|
||||
} else if (this.generating) {
|
||||
Column({ space: 8 }) {
|
||||
LoadingProgress().width(36).height(36).color(COLOR_PRIMARY)
|
||||
Text('生成中…').fontSize(12).fontColor(COLOR_TEXT_SECONDARY)
|
||||
}
|
||||
.width('100%').height(320).justifyContent(FlexAlign.Center)
|
||||
.borderRadius(12).backgroundColor(COLOR_IMAGE_BG)
|
||||
} else if (this.imageTab === 1 && this.resultPm !== undefined) {
|
||||
// 顶部对齐裁切:容器定高 clip,图片只定宽按原比缩放,头顶/发型不被居中裁掉
|
||||
Column() {
|
||||
Image(this.resultPm).width('100%').objectFit(ImageFit.Cover)
|
||||
}
|
||||
.width('100%').height(320).clip(true).borderRadius(12).backgroundColor(COLOR_IMAGE_BG)
|
||||
Text('效果图')
|
||||
.fontSize(11).fontColor(Color.White)
|
||||
.padding({ left: 10, right: 10, top: 4, bottom: 4 })
|
||||
.borderRadius(12)
|
||||
.backgroundColor(COLOR_BADGE_BG)
|
||||
.margin(8)
|
||||
} else {
|
||||
// 顶部对齐裁切:同上
|
||||
Column() {
|
||||
Image(this.photoUri).width('100%').objectFit(ImageFit.Cover)
|
||||
}
|
||||
.width('100%').height(320).clip(true).borderRadius(12).backgroundColor(COLOR_IMAGE_BG)
|
||||
Text('原图')
|
||||
.fontSize(11).fontColor(Color.White)
|
||||
.padding({ left: 10, right: 10, top: 4, bottom: 4 })
|
||||
.borderRadius(12)
|
||||
.backgroundColor(COLOR_BADGE_BG)
|
||||
.margin(8)
|
||||
}
|
||||
|
||||
// 右下「今日还可换发色 N 次」胶囊(P0-5,与试戴共用额度):仅展示不参与命中
|
||||
if (this.hairRemaining >= 0 && this.photoUri.length > 0) {
|
||||
Row() {
|
||||
Text(`今日还可换发色 ${this.hairRemaining} 次`)
|
||||
.fontSize(11).fontColor(Color.White)
|
||||
.padding({ left: 10, right: 10, top: 4, bottom: 4 })
|
||||
.borderRadius(12)
|
||||
.backgroundColor(COLOR_BADGE_BG)
|
||||
}
|
||||
.width('100%').height('100%')
|
||||
.justifyContent(FlexAlign.End)
|
||||
.alignItems(VerticalAlign.Bottom)
|
||||
.padding({ right: 8, bottom: 8 })
|
||||
.hitTestBehavior(HitTestMode.None)
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
|
||||
// 入口文字链:相册/拍照 + 保存(有结果才可点)
|
||||
Row({ space: 16 }) {
|
||||
Text('相册').fontSize(12).fontColor(COLOR_PRIMARY).onClick(() => { this.pickPhoto(false) })
|
||||
Text('拍照').fontSize(12).fontColor(COLOR_PRIMARY).onClick(() => { this.pickPhoto(true) })
|
||||
Text('保存')
|
||||
.fontSize(12)
|
||||
.fontColor(this.resultPm !== undefined ? COLOR_PRIMARY : COLOR_TEXT_SECONDARY)
|
||||
.onClick(() => { this.saveResult() })
|
||||
}
|
||||
.width('100%')
|
||||
|
||||
Text('请使用本人照片,上传即确认不侵犯他人肖像权')
|
||||
.fontSize(11).fontColor(COLOR_TEXT_SECONDARY).width('100%')
|
||||
|
||||
if (this.statusText.length > 0) {
|
||||
Text(this.statusText).fontSize(12).fontColor(COLOR_TEXT_SECONDARY).width('100%')
|
||||
}
|
||||
|
||||
// 发色卡:8 色圆点+名称 + 强度滑杆(每次都在原图上换色)
|
||||
Column({ space: 12 }) {
|
||||
Text('选择发色').fontSize(14).fontWeight(FontWeight.Medium).fontColor(COLOR_TEXT_PRIMARY)
|
||||
.width('100%')
|
||||
Flex({ wrap: FlexWrap.Wrap }) {
|
||||
ForEach(PRESET_COLORS, (c: PresetColor, idx: number) => {
|
||||
Column() {
|
||||
ColorDot({
|
||||
colorHex: this.colorHex(c.rgb),
|
||||
label: c.name,
|
||||
selected: this.colorIdx === idx,
|
||||
onSelect: (): void => { this.colorIdx = idx }
|
||||
})
|
||||
}
|
||||
.margin({ right: 14, bottom: 12 })
|
||||
}, (c: PresetColor) => c.name)
|
||||
}
|
||||
.width('100%')
|
||||
Row({ space: 8 }) {
|
||||
Text('强度').fontSize(12).fontColor(COLOR_TEXT_SECONDARY)
|
||||
Slider({ value: this.ratio, min: 0, max: 1, step: 0.1 })
|
||||
.layoutWeight(1)
|
||||
.onChange((v: number) => { this.ratio = v })
|
||||
Text(this.ratio.toFixed(1)).fontSize(12).fontColor(COLOR_TEXT_SECONDARY).width(28)
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
.padding(12)
|
||||
.borderRadius(12)
|
||||
.backgroundColor(Color.White)
|
||||
|
||||
// 合并计数脚注(P0-5):与发型试戴共用 hairstyle 每日额度
|
||||
Text('换发色与发型试戴共用每日额度')
|
||||
.fontSize(11).fontColor(COLOR_TEXT_SECONDARY).width('100%')
|
||||
}
|
||||
.width('100%')
|
||||
.padding(16)
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.scrollBar(BarState.Off)
|
||||
|
||||
// 吸底「换发色」:白底条+顶分隔线,高48圆角24主色;未上传照片或生成中置灰
|
||||
Column() {
|
||||
Divider().strokeWidth(0.5).color(COLOR_DIVIDER)
|
||||
Button(this.generating ? '生成中…' : `换发色(${PRESET_COLORS[this.colorIdx].name})`)
|
||||
.width('100%')
|
||||
.height(48)
|
||||
.borderRadius(24)
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.fontColor(this.canGenerate() ? Color.White : COLOR_TEXT_DISABLED)
|
||||
.backgroundColor(this.canGenerate() ? COLOR_PRIMARY : COLOR_DIVIDER)
|
||||
.enabled(this.canGenerate())
|
||||
.onClick(() => { this.applyColor() })
|
||||
}
|
||||
.width('100%')
|
||||
.backgroundColor(Color.White)
|
||||
.padding({ left: 16, right: 16, top: 12, bottom: 12 })
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
|
||||
if (this.showFaceConsent) {
|
||||
FacePhotoConsent({
|
||||
onAgree: (): void => {
|
||||
this.onConsentAgree()
|
||||
},
|
||||
onRefuse: (): void => {
|
||||
this.onConsentRefuse()
|
||||
}
|
||||
})
|
||||
}
|
||||
if (this.showQuotaBlocked) {
|
||||
this.QuotaBlockedDialog()
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.backgroundColor(COLOR_PAGE_BG)
|
||||
.bindSheet($$this.showTaskPanel, this.TaskBonusSheet(), {
|
||||
height: '60%',
|
||||
showClose: true
|
||||
})
|
||||
}
|
||||
|
||||
/** 吸底按钮可用条件:已上传照片 + 不在生成中。 */
|
||||
private canGenerate(): boolean {
|
||||
return !this.generating && this.photoUri.length > 0
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,18 @@
|
||||
/**
|
||||
* HairDesignPage —— 发型设计(试戴 + 换发色),Phase A 直连线上服务。
|
||||
* HairDesignPage —— 发型设计(只试戴;换发色已拆到独立页 HairColorPage),Phase A 直连线上服务。
|
||||
*
|
||||
* 流程(产品方案 §2.3):上传面部特写 → 点选发型即试戴(5~10s)→ 可换发色 → 保存相册。
|
||||
* 交互(2026-09 按用户反馈重排):
|
||||
* 图片区单区域展示,顶部「原图/效果图」页签切换(无结果时效果图页签置灰不可点);
|
||||
* 点选发型只选中不生成,吸底「换发型」按钮触发试戴(5~10s)→ 成功自动切到效果图页签;
|
||||
* 保存走系统相册对话框;不再保留「上次结果」回看卡(相册留存即可)。
|
||||
* 异常口径:400 用服务端 message 原样提示;失败保留当前图不覆盖。
|
||||
* 发型库三态(#8/#18):加载中 / 空态 / 失败+重新加载。
|
||||
* 结果归宿(#18,与 #17 统一):试戴/换发色成功即落 filesDir/results/hair_last.jpg
|
||||
* (换发色后覆盖为最新版本),保存优先复用该文件,杀 App 后「上次结果」卡可回看。
|
||||
*
|
||||
* v2 视觉重排(《美搭配与美学诊断-UI规范》§4,交互全部保留):
|
||||
* 顶部双图区(原图|效果图 等宽,左下角标 COLOR_BADGE_BG,点右图切换对比);
|
||||
* 性别分栏改 Segment 组件(女生/男生);8 色发色改 ColorDot 圆点;
|
||||
* 「应用发色」移至吸底主按钮(无结果时随发色卡整体隐藏,沿用现逻辑)。
|
||||
*/
|
||||
|
||||
import { router } from '@kit.ArkUI'
|
||||
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 { ApiClient } from '../core/ApiClient'
|
||||
@@ -38,7 +32,6 @@ import {
|
||||
COLOR_ERROR
|
||||
} from '../core/Theme'
|
||||
import { Segment } from '../components/f2/Segment'
|
||||
import { ColorDot } from '../components/f2/ColorDot'
|
||||
import { FacePhotoConsent, FaceConsentStore } from '../components/f2/FacePhotoConsent'
|
||||
import { TaskBonusPanel } from '../components/f1/TaskBonusPanel'
|
||||
|
||||
@@ -52,22 +45,6 @@ interface HairQuotaWire {
|
||||
reset_at: string | null
|
||||
}
|
||||
|
||||
interface PresetColor {
|
||||
name: string
|
||||
rgb: number[]
|
||||
}
|
||||
|
||||
const PRESET_COLORS: PresetColor[] = [
|
||||
{ name: '自然黑', rgb: [30, 30, 30] },
|
||||
{ name: '深棕', rgb: [74, 48, 36] },
|
||||
{ name: '栗色', rgb: [128, 70, 42] },
|
||||
{ name: '蜜茶', rgb: [156, 108, 66] },
|
||||
{ name: '亚麻', rgb: [150, 140, 130] },
|
||||
{ name: '酒红', rgb: [128, 32, 48] },
|
||||
{ name: '奶奶灰', rgb: [160, 160, 165] },
|
||||
{ name: '蓝黑', rgb: [40, 50, 70] }
|
||||
]
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct HairDesignPage {
|
||||
@@ -79,36 +56,20 @@ struct HairDesignPage {
|
||||
@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 genderTab: string = 'female' // 发型男女分栏(female 默认:库内女款 34 / 男款 26)
|
||||
@State resultBase64: string = '' // 保存用它,避免二次编码
|
||||
@State imageTab: number = 0 // 图片区页签:0=原图 1=效果图(无结果时置灰)
|
||||
@State genderTab: string = 'female' // 发型男女分栏(female 默认:库内女款多于男款)
|
||||
@State showFaceConsent: boolean = false
|
||||
// —— 每日试戴额度(P0-5 端侧兜底:免费档 3 次/天,产品方案 §3.2;试戴与换发色合并计数)——
|
||||
// —— 每日试戴额度(P0-5 端侧兜底:免费档 3 次/天,产品方案 §3.2;与换发色共用 hairstyle key)——
|
||||
@State hairRemaining: number = -1 // -1=未加载(放行);≥0 为 min(服务端, 端侧) 剩余
|
||||
@State showQuotaBlocked: boolean = false // 额度耗尽引导 overlay
|
||||
@State showTaskPanel: boolean = false // 「做任务换额度」半屏面板
|
||||
private consentPickCamera: boolean = false // 同意后继续的拍照/相册入口
|
||||
|
||||
/** 本机结果留存路径(#18):filesDir/results(cacheDir 有系统配额会被清)。 */
|
||||
private resultStorePath(): string {
|
||||
return `${ContextHolder.get().filesDir}/results/hair_last.jpg`
|
||||
}
|
||||
private imageTabs: string[] = ['原图', '效果图']
|
||||
|
||||
aboutToAppear(): void {
|
||||
this.loadStyles()
|
||||
this.loadHairRemaining()
|
||||
// 上次结果回看(#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') {
|
||||
@@ -158,15 +119,14 @@ struct HairDesignPage {
|
||||
return out
|
||||
}
|
||||
|
||||
/** RGB 分量转两位 hex(发色圆点展示用)。 */
|
||||
private hex2(v: number): string {
|
||||
const s: string = v.toString(16)
|
||||
return s.length < 2 ? `0${s}` : s
|
||||
}
|
||||
|
||||
/** PRESET_COLORS 的 RGB 转 #RRGGBB:仅圆点展示,发色接口 rgb 传参格式不变。 */
|
||||
private colorHex(rgb: number[]): string {
|
||||
return `#${this.hex2(rgb[0])}${this.hex2(rgb[1])}${this.hex2(rgb[2])}`
|
||||
/** 当前选中的发型名(吸底按钮文案用);未选中为空串。 */
|
||||
private selectedStyleName(): string {
|
||||
for (const s of this.styles) {
|
||||
if (s.id === this.selectedStyleId) {
|
||||
return s.name
|
||||
}
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/** 上传面部特写前须单独同意(CR-01:人脸属敏感个人信息)。 */
|
||||
@@ -188,8 +148,8 @@ struct HairDesignPage {
|
||||
this.photoUri = picked.uri
|
||||
this.resultPm = undefined
|
||||
this.resultBase64 = ''
|
||||
this.resultLocalPath = ''
|
||||
this.selectedStyleId = ''
|
||||
this.imageTab = 0
|
||||
this.statusText = ''
|
||||
} catch (e) {
|
||||
this.statusText = e instanceof ApiError ? e.message : '读取照片失败'
|
||||
@@ -207,8 +167,19 @@ struct HairDesignPage {
|
||||
this.statusText = '未同意照片授权,你可以先浏览下方发型库'
|
||||
}
|
||||
|
||||
private async tryOn(style: Hairstyle): Promise<void> {
|
||||
if (this.photoUri.length === 0 || this.generating) {
|
||||
/** 吸底按钮触发:对当前选中发型发起试戴(点选网格只选中,不发请求)。 */
|
||||
private async tryOn(): Promise<void> {
|
||||
if (this.photoUri.length === 0 || this.selectedStyleId.length === 0 || this.generating) {
|
||||
return
|
||||
}
|
||||
let style: Hairstyle | undefined = undefined
|
||||
for (const s of this.styles) {
|
||||
if (s.id === this.selectedStyleId) {
|
||||
style = s
|
||||
break
|
||||
}
|
||||
}
|
||||
if (style === undefined) {
|
||||
return
|
||||
}
|
||||
// 每日额度耗尽(P0-5,与换发色合并计数):不发请求,给「做任务换额度」出路
|
||||
@@ -219,21 +190,19 @@ struct HairDesignPage {
|
||||
}
|
||||
const startMs: number = Date.now()
|
||||
this.generating = true
|
||||
this.selectedStyleId = style.id
|
||||
this.showOriginal = false
|
||||
this.statusText = `正在试戴「${style.name}」,约 5~15 秒…`
|
||||
try {
|
||||
const buf = await ImageCodec.toJpegBuffer(this.photoUri)
|
||||
this.resultBase64 = await TryonApi.changeHair(buf, style.id)
|
||||
this.resultPm = await ImageCodec.base64ToPixelMap(this.resultBase64)
|
||||
this.statusText = '试戴完成,点「对比」看原图'
|
||||
this.imageTab = 1 // 成功自动切到效果图页签
|
||||
this.statusText = '试戴完成,点「原图」页签可对比'
|
||||
// 成功才计数(失败不占额度):端侧记账 + 埋点上报
|
||||
DailyLimiter.tryConsume('hairstyle')
|
||||
this.hairRemaining = DailyLimiter.remaining('hairstyle')
|
||||
Tracker.track('hair.generate', {
|
||||
'ok': true, 'duration_s': Math.round((Date.now() - startMs) / 1000), 'blocked': false
|
||||
})
|
||||
this.persistResult()
|
||||
} catch (e) {
|
||||
Tracker.track('hair.generate', {
|
||||
'ok': false, 'duration_s': Math.round((Date.now() - startMs) / 1000), 'blocked': false
|
||||
@@ -244,68 +213,13 @@ struct HairDesignPage {
|
||||
}
|
||||
}
|
||||
|
||||
private async changeColor(): Promise<void> {
|
||||
if (this.resultBase64.length === 0 || this.generating) {
|
||||
return
|
||||
}
|
||||
// 每日额度耗尽(P0-5,与试戴合并计数同一 hairstyle key):不发请求,给出路
|
||||
if (this.hairRemaining === 0) {
|
||||
Tracker.track('hair.generate', { 'ok': false, 'duration_s': 0, 'blocked': true })
|
||||
this.showQuotaBlocked = true
|
||||
return
|
||||
}
|
||||
const startMs: number = Date.now()
|
||||
this.generating = true
|
||||
const c: PresetColor = PRESET_COLORS[this.colorIdx]
|
||||
this.statusText = `正在换发色(${c.name})…`
|
||||
try {
|
||||
const helper = new util.Base64Helper()
|
||||
const pure: string = this.resultBase64.includes(',')
|
||||
? this.resultBase64.substring(this.resultBase64.indexOf(',') + 1)
|
||||
: this.resultBase64
|
||||
// slice() 拷贝出精确长度的副本:decodeSync 返回视图,直接取 .buffer 会带尾部脏字节
|
||||
const buf = helper.decodeSync(pure).slice().buffer as ArrayBuffer
|
||||
const rgb: string = `[${c.rgb[0]}, ${c.rgb[1]}, ${c.rgb[2]}]`
|
||||
this.resultBase64 = await TryonApi.changeHairColor(buf, rgb, this.ratio)
|
||||
this.resultPm = await ImageCodec.base64ToPixelMap(this.resultBase64)
|
||||
this.statusText = '换发色完成'
|
||||
// 成功才计数(与试戴同一 hairstyle key,合并计算每日额度)
|
||||
DailyLimiter.tryConsume('hairstyle')
|
||||
this.hairRemaining = DailyLimiter.remaining('hairstyle')
|
||||
Tracker.track('hair.generate', {
|
||||
'ok': true, 'duration_s': Math.round((Date.now() - startMs) / 1000), 'blocked': false
|
||||
})
|
||||
this.persistResult() // 落盘覆盖为最新发色版本(#18 验收④)
|
||||
} catch (e) {
|
||||
Tracker.track('hair.generate', {
|
||||
'ok': false, 'duration_s': Math.round((Date.now() - startMs) / 1000), 'blocked': false
|
||||
})
|
||||
this.statusText = e instanceof ApiError ? e.message : '换发色失败,请重试'
|
||||
} finally {
|
||||
this.generating = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 结果留存(#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):优先复用本机留存文件(一次写、双用途);留存失败过的现场写缓存兜底。 */
|
||||
/** 保存到相册:结果 Base64 现场写缓存文件 → 系统保存对话框(取消/失败三态文案)。 */
|
||||
private async saveResult(): Promise<void> {
|
||||
if (this.resultBase64.length === 0) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const path: string = this.resultLocalPath.length > 0
|
||||
? this.resultLocalPath
|
||||
: ImageCodec.base64ToCacheFile(this.resultBase64, `hair_${Date.now()}.jpg`)
|
||||
const path: string = ImageCodec.base64ToCacheFile(this.resultBase64, `hair_${Date.now()}.jpg`)
|
||||
this.statusText = await this.saveFileToGallery(path)
|
||||
} catch (_e) {
|
||||
this.statusText = '保存失败,请重试'
|
||||
@@ -327,14 +241,6 @@ struct HairDesignPage {
|
||||
}
|
||||
}
|
||||
|
||||
/** 「上次结果」卡的保存(#18):直接走本机副本,不依赖网络。 */
|
||||
private async saveLastResult(): Promise<void> {
|
||||
if (this.lastLocalPath.length === 0) {
|
||||
return
|
||||
}
|
||||
this.statusText = await this.saveFileToGallery(this.lastLocalPath)
|
||||
}
|
||||
|
||||
/** 今日试戴额度耗尽的引导 overlay(P0-5):不发请求,给「做任务换额度」出路。 */
|
||||
@Builder
|
||||
QuotaBlockedDialog() {
|
||||
@@ -408,92 +314,94 @@ struct HairDesignPage {
|
||||
|
||||
Scroll() {
|
||||
Column({ space: 12 }) {
|
||||
// 顶部双图区(v2):原图 | 效果图 等宽,左下角标当前显示态,点右图切换对比
|
||||
Row({ space: 12 }) {
|
||||
// 左图:原图(无照片时为上传入口占位)
|
||||
Stack({ alignContent: Alignment.BottomStart }) {
|
||||
if (this.photoUri.length > 0) {
|
||||
Image(this.photoUri)
|
||||
.width('100%').height(240).objectFit(ImageFit.Cover).borderRadius(12)
|
||||
Text('原图')
|
||||
.fontSize(11).fontColor(Color.White)
|
||||
.padding({ left: 10, right: 10, top: 4, bottom: 4 })
|
||||
.borderRadius(12)
|
||||
.backgroundColor(COLOR_BADGE_BG)
|
||||
.margin(8)
|
||||
} else {
|
||||
Column({ space: 6 }) {
|
||||
Text('+').fontSize(28).fontColor(COLOR_TEXT_SECONDARY)
|
||||
Text('上传面部特写').fontSize(12).fontColor(COLOR_TEXT_SECONDARY)
|
||||
}
|
||||
.width('100%').height(240).justifyContent(FlexAlign.Center)
|
||||
.borderRadius(12).backgroundColor(COLOR_IMAGE_BG)
|
||||
.onClick(() => { this.pickPhoto(false) })
|
||||
}
|
||||
}
|
||||
.layoutWeight(1)
|
||||
// 图片区页签:原图 | 效果图(无结果时效果图置灰不可点)
|
||||
Row() {
|
||||
ForEach(this.imageTabs, (label: string, idx: number) => {
|
||||
Text(label)
|
||||
.fontSize(13)
|
||||
.fontColor(idx === 1 && this.resultPm === undefined
|
||||
? COLOR_TEXT_DISABLED
|
||||
: (this.imageTab === idx ? Color.White : COLOR_TEXT_PRIMARY))
|
||||
.backgroundColor(this.imageTab === idx && !(idx === 1 && this.resultPm === undefined)
|
||||
? COLOR_PRIMARY
|
||||
: Color.Transparent)
|
||||
.padding({ left: 20, right: 20, top: 7, bottom: 7 })
|
||||
.borderRadius(16)
|
||||
.onClick(() => {
|
||||
if (idx === 1 && this.resultPm === undefined) {
|
||||
return // 无结果:效果图页签不响应
|
||||
}
|
||||
this.imageTab = idx
|
||||
})
|
||||
}, (label: string) => label)
|
||||
}
|
||||
.padding(2)
|
||||
.borderRadius(18)
|
||||
.backgroundColor(COLOR_IMAGE_BG)
|
||||
.alignSelf(ItemAlign.Start)
|
||||
|
||||
// 右图:效果图(点按在 效果图/原图 间切换对比,沿用现交互)
|
||||
Stack({ alignContent: Alignment.BottomStart }) {
|
||||
if (this.generating) {
|
||||
Column({ space: 8 }) {
|
||||
LoadingProgress().width(36).height(36).color(COLOR_PRIMARY)
|
||||
Text('生成中…').fontSize(12).fontColor(COLOR_TEXT_SECONDARY)
|
||||
}
|
||||
.width('100%').height(240).justifyContent(FlexAlign.Center)
|
||||
.borderRadius(12).backgroundColor(COLOR_IMAGE_BG)
|
||||
} else if (this.resultPm !== undefined && !this.showOriginal) {
|
||||
Image(this.resultPm)
|
||||
.width('100%').height(240).objectFit(ImageFit.Cover).borderRadius(12)
|
||||
Text('效果图')
|
||||
.fontSize(11).fontColor(Color.White)
|
||||
.padding({ left: 10, right: 10, top: 4, bottom: 4 })
|
||||
.borderRadius(12)
|
||||
.backgroundColor(COLOR_BADGE_BG)
|
||||
.margin(8)
|
||||
} else if (this.showOriginal && this.photoUri.length > 0) {
|
||||
Image(this.photoUri)
|
||||
.width('100%').height(240).objectFit(ImageFit.Cover).borderRadius(12)
|
||||
Text('原图')
|
||||
.fontSize(11).fontColor(Color.White)
|
||||
.padding({ left: 10, right: 10, top: 4, bottom: 4 })
|
||||
.borderRadius(12)
|
||||
.backgroundColor(COLOR_BADGE_BG)
|
||||
.margin(8)
|
||||
} else {
|
||||
Column() {
|
||||
Text('效果图').fontSize(12).fontColor(COLOR_TEXT_SECONDARY)
|
||||
}
|
||||
.width('100%').height(240).justifyContent(FlexAlign.Center)
|
||||
.borderRadius(12).backgroundColor(COLOR_IMAGE_BG)
|
||||
// 图片区(单区域):无照片=上传入口;生成中=loading;按页签显示原图/效果图
|
||||
Stack({ alignContent: Alignment.BottomStart }) {
|
||||
if (this.photoUri.length === 0) {
|
||||
Column({ space: 6 }) {
|
||||
Text('+').fontSize(28).fontColor(COLOR_TEXT_SECONDARY)
|
||||
Text('上传面部特写').fontSize(12).fontColor(COLOR_TEXT_SECONDARY)
|
||||
}
|
||||
|
||||
// 右下「今日还可试戴 N 次」胶囊(P0-5,试戴+换发色合并计数):仅展示不参与命中
|
||||
if (this.hairRemaining >= 0) {
|
||||
Row() {
|
||||
Text(`今日还可试戴 ${this.hairRemaining} 次`)
|
||||
.fontSize(11).fontColor(Color.White)
|
||||
.padding({ left: 10, right: 10, top: 4, bottom: 4 })
|
||||
.borderRadius(12)
|
||||
.backgroundColor(COLOR_BADGE_BG)
|
||||
}
|
||||
.width('100%').height('100%')
|
||||
.justifyContent(FlexAlign.End)
|
||||
.alignItems(VerticalAlign.Bottom)
|
||||
.padding({ right: 8, bottom: 8 })
|
||||
.hitTestBehavior(HitTestMode.None)
|
||||
.width('100%').height(320).justifyContent(FlexAlign.Center)
|
||||
.borderRadius(12).backgroundColor(COLOR_IMAGE_BG)
|
||||
.onClick(() => { this.pickPhoto(false) })
|
||||
} else if (this.generating) {
|
||||
Column({ space: 8 }) {
|
||||
LoadingProgress().width(36).height(36).color(COLOR_PRIMARY)
|
||||
Text('生成中…').fontSize(12).fontColor(COLOR_TEXT_SECONDARY)
|
||||
}
|
||||
.width('100%').height(320).justifyContent(FlexAlign.Center)
|
||||
.borderRadius(12).backgroundColor(COLOR_IMAGE_BG)
|
||||
} else if (this.imageTab === 1 && this.resultPm !== undefined) {
|
||||
// 顶部对齐裁切:容器定高 clip,图片只定宽按原比缩放,头顶/发型不被居中裁掉
|
||||
Column() {
|
||||
Image(this.resultPm).width('100%').objectFit(ImageFit.Cover)
|
||||
}
|
||||
.width('100%').height(320).clip(true).borderRadius(12).backgroundColor(COLOR_IMAGE_BG)
|
||||
Text('效果图')
|
||||
.fontSize(11).fontColor(Color.White)
|
||||
.padding({ left: 10, right: 10, top: 4, bottom: 4 })
|
||||
.borderRadius(12)
|
||||
.backgroundColor(COLOR_BADGE_BG)
|
||||
.margin(8)
|
||||
} else {
|
||||
// 顶部对齐裁切:同上
|
||||
Column() {
|
||||
Image(this.photoUri).width('100%').objectFit(ImageFit.Cover)
|
||||
}
|
||||
.width('100%').height(320).clip(true).borderRadius(12).backgroundColor(COLOR_IMAGE_BG)
|
||||
Text('原图')
|
||||
.fontSize(11).fontColor(Color.White)
|
||||
.padding({ left: 10, right: 10, top: 4, bottom: 4 })
|
||||
.borderRadius(12)
|
||||
.backgroundColor(COLOR_BADGE_BG)
|
||||
.margin(8)
|
||||
}
|
||||
.layoutWeight(1)
|
||||
.onClick(() => {
|
||||
if (this.resultPm !== undefined && !this.generating) {
|
||||
this.showOriginal = !this.showOriginal
|
||||
|
||||
// 右下「今日还可试戴 N 次」胶囊(P0-5,与换发色共用额度):仅展示不参与命中
|
||||
if (this.hairRemaining >= 0 && this.photoUri.length > 0) {
|
||||
Row() {
|
||||
Text(`今日还可试戴 ${this.hairRemaining} 次`)
|
||||
.fontSize(11).fontColor(Color.White)
|
||||
.padding({ left: 10, right: 10, top: 4, bottom: 4 })
|
||||
.borderRadius(12)
|
||||
.backgroundColor(COLOR_BADGE_BG)
|
||||
}
|
||||
})
|
||||
.width('100%').height('100%')
|
||||
.justifyContent(FlexAlign.End)
|
||||
.alignItems(VerticalAlign.Bottom)
|
||||
.padding({ right: 8, bottom: 8 })
|
||||
.hitTestBehavior(HitTestMode.None)
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
|
||||
// 入口文字链(沿用):相册/拍照 + 保存(保存沿用现交互与置灰口径)
|
||||
// 入口文字链:相册/拍照 + 保存(有结果才可点)
|
||||
Row({ space: 16 }) {
|
||||
Text('相册').fontSize(12).fontColor(COLOR_PRIMARY).onClick(() => { this.pickPhoto(false) })
|
||||
Text('拍照').fontSize(12).fontColor(COLOR_PRIMARY).onClick(() => { this.pickPhoto(true) })
|
||||
@@ -511,31 +419,8 @@ struct HairDesignPage {
|
||||
Text(this.statusText).fontSize(12).fontColor(COLOR_TEXT_SECONDARY).width('100%')
|
||||
}
|
||||
|
||||
// 上次发型结果回看(#18):无本次结果时展示留存副本(保存/移除)
|
||||
if (this.lastLocalPath.length > 0 && this.resultPm === undefined) {
|
||||
Column({ space: 8 }) {
|
||||
Text('上次发型结果')
|
||||
.fontSize(13).fontWeight(FontWeight.Medium).fontColor(COLOR_TEXT_PRIMARY).width('100%')
|
||||
Image(fileUri.getUriFromPath(this.lastLocalPath))
|
||||
.width('100%').height(280).objectFit(ImageFit.Contain)
|
||||
.borderRadius(12).backgroundColor(COLOR_IMAGE_BG)
|
||||
Row({ space: 16 }) {
|
||||
Text('保存到相册').fontSize(13).fontColor(COLOR_PRIMARY)
|
||||
.onClick(() => { this.saveLastResult() })
|
||||
Text('知道了').fontSize(13).fontColor(COLOR_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(COLOR_TEXT_PRIMARY)
|
||||
// 性别分段(v2):女生/男生,映射 genderTab;unknown 款两段都展示
|
||||
// 发型网格:点选只选中(描边),吸底「换发型」按钮触发试戴
|
||||
Text('选择发型').fontSize(14).fontWeight(FontWeight.Medium).fontColor(COLOR_TEXT_PRIMARY)
|
||||
Row() {
|
||||
Segment({
|
||||
items: ['女生', '男生'],
|
||||
@@ -561,7 +446,9 @@ struct HairDesignPage {
|
||||
Text(style.name).fontSize(11).fontColor(COLOR_TEXT_PRIMARY).maxLines(1)
|
||||
}
|
||||
}
|
||||
.onClick(() => { this.tryOn(style) })
|
||||
.onClick(() => {
|
||||
this.selectedStyleId = style.id // 只选中不生成,底部按钮触发
|
||||
})
|
||||
}, (style: Hairstyle) => style.id)
|
||||
}
|
||||
.columnsTemplate('1fr 1fr 1fr')
|
||||
@@ -605,41 +492,8 @@ struct HairDesignPage {
|
||||
.padding({ top: 8, bottom: 8 })
|
||||
}
|
||||
|
||||
// 换发色卡(v2):8 色圆点+名称 + 强度滑杆;无结果整体隐藏(沿用现逻辑)
|
||||
if (this.resultPm !== undefined) {
|
||||
Column({ space: 12 }) {
|
||||
Text('换个发色').fontSize(14).fontWeight(FontWeight.Medium).fontColor(COLOR_TEXT_PRIMARY)
|
||||
.width('100%')
|
||||
Flex({ wrap: FlexWrap.Wrap }) {
|
||||
ForEach(PRESET_COLORS, (c: PresetColor, idx: number) => {
|
||||
Column() {
|
||||
ColorDot({
|
||||
colorHex: this.colorHex(c.rgb),
|
||||
label: c.name,
|
||||
selected: this.colorIdx === idx,
|
||||
onSelect: (): void => { this.colorIdx = idx }
|
||||
})
|
||||
}
|
||||
.margin({ right: 14, bottom: 12 })
|
||||
}, (c: PresetColor) => c.name)
|
||||
}
|
||||
.width('100%')
|
||||
Row({ space: 8 }) {
|
||||
Text('强度').fontSize(12).fontColor(COLOR_TEXT_SECONDARY)
|
||||
Slider({ value: this.ratio, min: 0, max: 1, step: 0.1 })
|
||||
.layoutWeight(1)
|
||||
.onChange((v: number) => { this.ratio = v })
|
||||
Text(this.ratio.toFixed(1)).fontSize(12).fontColor(COLOR_TEXT_SECONDARY).width(28)
|
||||
}
|
||||
}
|
||||
.width('100%')
|
||||
.padding(12)
|
||||
.borderRadius(12)
|
||||
.backgroundColor(Color.White)
|
||||
}
|
||||
|
||||
// 合并计数脚注(P0-5):试戴与换发色共用 hairstyle 每日额度
|
||||
Text('试戴与换发色合并计算每日额度')
|
||||
// 合并计数脚注(P0-5):试戴与换发色页共用 hairstyle 每日额度
|
||||
Text('试戴与换发色共用每日额度')
|
||||
.fontSize(11).fontColor(COLOR_TEXT_SECONDARY).width('100%')
|
||||
}
|
||||
.width('100%')
|
||||
@@ -648,26 +502,25 @@ struct HairDesignPage {
|
||||
.layoutWeight(1)
|
||||
.scrollBar(BarState.Off)
|
||||
|
||||
// 吸底「应用发色」(v2):白底条+顶分隔线,高48圆角24主色;
|
||||
// 与发色卡同条件渲染(无结果不出现),生成中置灰并显示「生成中…」
|
||||
if (this.resultPm !== undefined) {
|
||||
Column() {
|
||||
Divider().strokeWidth(0.5).color(COLOR_DIVIDER)
|
||||
Button(this.generating ? '生成中…' : '应用发色')
|
||||
.width('100%')
|
||||
.height(48)
|
||||
.borderRadius(24)
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.fontColor(this.generating || this.resultBase64.length === 0 ? COLOR_TEXT_DISABLED : Color.White)
|
||||
.backgroundColor(this.generating || this.resultBase64.length === 0 ? COLOR_DIVIDER : COLOR_PRIMARY)
|
||||
.enabled(!this.generating && this.resultBase64.length > 0)
|
||||
.onClick(() => { this.changeColor() })
|
||||
}
|
||||
.width('100%')
|
||||
.backgroundColor(Color.White)
|
||||
.padding({ left: 16, right: 16, top: 12, bottom: 12 })
|
||||
// 吸底「换发型」:白底条+顶分隔线,高48圆角24主色;未选照片/发型或生成中置灰
|
||||
Column() {
|
||||
Divider().strokeWidth(0.5).color(COLOR_DIVIDER)
|
||||
Button(this.generating
|
||||
? '生成中…'
|
||||
: (this.selectedStyleName().length > 0 ? `试戴「${this.selectedStyleName()}」` : '换发型'))
|
||||
.width('100%')
|
||||
.height(48)
|
||||
.borderRadius(24)
|
||||
.fontSize(16)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.fontColor(this.canGenerate() ? Color.White : COLOR_TEXT_DISABLED)
|
||||
.backgroundColor(this.canGenerate() ? COLOR_PRIMARY : COLOR_DIVIDER)
|
||||
.enabled(this.canGenerate())
|
||||
.onClick(() => { this.tryOn() })
|
||||
}
|
||||
.width('100%')
|
||||
.backgroundColor(Color.White)
|
||||
.padding({ left: 16, right: 16, top: 12, bottom: 12 })
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
@@ -694,4 +547,9 @@ struct HairDesignPage {
|
||||
showClose: true
|
||||
})
|
||||
}
|
||||
|
||||
/** 吸底按钮可用条件:已上传照片 + 已选发型 + 不在生成中。 */
|
||||
private canGenerate(): boolean {
|
||||
return !this.generating && this.photoUri.length > 0 && this.selectedStyleId.length > 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ struct HomePage {
|
||||
.alignItems(VerticalAlign.Center)
|
||||
}
|
||||
|
||||
/** Tab1 首页:问候区 + 两张功能入口卡 + 今日额度小卡。 */
|
||||
/** Tab1 首页:问候区 + 功能入口卡 + 今日额度小卡。 */
|
||||
@Builder
|
||||
HomeTab() {
|
||||
Scroll() {
|
||||
@@ -188,7 +188,8 @@ struct HomePage {
|
||||
|
||||
this.EntryCard('美学诊断', '个人形象风格分析报告', '▣', ACCENT, 'pages/DiagnosisLandingPage', 'diagnosis')
|
||||
this.EntryCard('美搭配', '我的衣橱,换装试穿', '◈', '#E8912D', 'pages/FittingRoomPage', 'fitting')
|
||||
this.EntryCard('发型设计', '60 款发型试戴,还能换发色', '✂', '#2DB38E', 'pages/HairDesignPage', 'hair')
|
||||
this.EntryCard('发型设计', '60 款发型,点选试戴', '✂', '#2DB38E', 'pages/HairDesignPage', 'hair')
|
||||
this.EntryCard('换发色', '8 种发色,一键换着看', '◐', '#8E5BD3', 'pages/HairColorPage', 'haircolor')
|
||||
this.EntryCard('AI 穿搭顾问', '对话式穿搭建议,随时问', '✦', ACCENT_AI, 'pages/ChatPage', 'chat')
|
||||
if (this.quotaNetError) {
|
||||
// P0-6:额度拉取遇网络错误——横幅换占配额卡位置,重试可恢复
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
/**
|
||||
* ReportCreatePage —— 报告创建(F3):问卷六字段 + 模拟照片键 + 提交 + 任务轮询。
|
||||
* ReportCreatePage —— 报告创建(F3):必选照片 + 问卷六字段 + 提交 + 任务轮询。
|
||||
*
|
||||
* 流程:
|
||||
* 1) 问卷表单(性别/身高/体重/生日/核心诉求多选/心理风格九型),提交前前端校验;
|
||||
* 1) 个人照片(必选,正面全身照):先走 FacePhotoConsent 人脸单独授权(CR-01),
|
||||
* 再相册/拍照;提交时先上传(POST /uploads/direct,本地磁盘降级路线)
|
||||
* 拿真实 object_key,再建报告——模拟键已被服务端存在性校验封死
|
||||
* 2) 问卷表单(性别/身高/体重/生日/核心诉求多选/心理风格九型),提交前前端校验;
|
||||
* 身高/体重为滚轮选择器(showTextPickerDialog),不提供键盘输入
|
||||
* 2) 照片键为模拟:V1 骨架 COS 直传未接入,留空自动生成 report_photo/{userId}/{随机}.jpg
|
||||
* 3) POST /api/v1/reports(request_key 随机 hex;任务 FAILED 后重试换新 key,
|
||||
* 服务端幂等重放不过滤状态,沿用旧 key 只会重放回原失败任务)
|
||||
* 4) 40920(本期已生成)→ 页内对话框:可跳最近一次报告(AppStorage 记录,
|
||||
@@ -17,14 +19,15 @@
|
||||
import { router, componentUtils } from '@kit.ArkUI'
|
||||
import { ApiClient } from '../core/ApiClient'
|
||||
import { ApiError } from '../core/ApiTypes'
|
||||
import { AuthStore } from '../core/AuthStore'
|
||||
import { ImageCodec } from '../core/ImageCodec'
|
||||
import { UploadApi } from '../core/UploadApi'
|
||||
import { Tracker } from '../core/Tracker'
|
||||
import { COLOR_PRIMARY, COLOR_TEXT_SECONDARY } from '../core/Theme'
|
||||
import { TaskPollingPanel } from '../components/f3/TaskPollingPanel'
|
||||
import { FacePhotoConsent, FaceConsentStore } from '../components/f2/FacePhotoConsent'
|
||||
import {
|
||||
ReportCreateResp,
|
||||
ReportListItemWire,
|
||||
buildMockPhotoKey,
|
||||
formatDate,
|
||||
randomHex
|
||||
} from '../components/f3/ReportTypes'
|
||||
@@ -79,7 +82,10 @@ struct ReportCreatePage {
|
||||
@State birthday: Date = new Date(2000, 0, 15)
|
||||
@State coreGoals: string[] = []
|
||||
@State psychStyle: string = ''
|
||||
@State photoKeyInput: string = ''
|
||||
@State photoUri: string = '' // 已选照片(媒体 URI);空 = 未选,提交必校验
|
||||
@State photoErr: string = ''
|
||||
@State showFaceConsent: boolean = false
|
||||
@State showPhotoSource: boolean = false
|
||||
@State genderErr: string = ''
|
||||
@State heightErr: string = ''
|
||||
@State weightErr: string = ''
|
||||
@@ -130,6 +136,10 @@ struct ReportCreatePage {
|
||||
|
||||
private validateForm(): boolean {
|
||||
let ok = true
|
||||
this.photoErr = this.photoUri === '' ? '请上传个人照片' : ''
|
||||
if (this.photoErr !== '') {
|
||||
ok = false
|
||||
}
|
||||
this.genderErr = this.gender === '' ? '请选择性别' : ''
|
||||
if (this.genderErr !== '') {
|
||||
ok = false
|
||||
@@ -208,6 +218,44 @@ struct ReportCreatePage {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 照片入口:人脸属敏感个人信息,上传前须单独同意(CR-01 / FR-ACC-08);
|
||||
* 已授权则直接弹来源选择(相册/拍照)。
|
||||
*/
|
||||
private onPhotoTap(): void {
|
||||
this.photoErr = ''
|
||||
if (!FaceConsentStore.isGranted()) {
|
||||
this.showFaceConsent = true
|
||||
return
|
||||
}
|
||||
this.showPhotoSource = true
|
||||
}
|
||||
|
||||
private onConsentAgree(): void {
|
||||
FaceConsentStore.grant()
|
||||
this.showFaceConsent = false
|
||||
this.showPhotoSource = true
|
||||
}
|
||||
|
||||
private onConsentRefuse(): void {
|
||||
this.showFaceConsent = false
|
||||
this.photoErr = '需同意照片授权后才能上传'
|
||||
}
|
||||
|
||||
private async doPickPhoto(fromCamera: boolean): Promise<void> {
|
||||
this.showPhotoSource = false
|
||||
try {
|
||||
const picked = fromCamera ? await ImageCodec.takePhoto() : await ImageCodec.pickFromGallery()
|
||||
if (picked === undefined) {
|
||||
return // 用户取消:保持原状
|
||||
}
|
||||
this.photoUri = picked.uri
|
||||
this.photoErr = ''
|
||||
} catch (e) {
|
||||
this.photoErr = e instanceof ApiError ? e.message : '读取照片失败,请重试'
|
||||
}
|
||||
}
|
||||
|
||||
private onSubmitTap(): void {
|
||||
if (this.submitting) {
|
||||
return
|
||||
@@ -247,6 +295,9 @@ struct ReportCreatePage {
|
||||
|
||||
private missingLabels(): string[] {
|
||||
const labels: string[] = []
|
||||
if (this.photoErr !== '') {
|
||||
labels.push('个人照片')
|
||||
}
|
||||
if (this.genderErr !== '') {
|
||||
labels.push('性别')
|
||||
}
|
||||
@@ -267,7 +318,9 @@ struct ReportCreatePage {
|
||||
|
||||
private scrollToFirstError(): void {
|
||||
let firstId = ''
|
||||
if (this.genderErr !== '') {
|
||||
if (this.photoErr !== '') {
|
||||
firstId = 'field_photo'
|
||||
} else if (this.genderErr !== '') {
|
||||
firstId = 'field_gender'
|
||||
} else if (this.heightErr !== '' || this.weightErr !== '') {
|
||||
firstId = 'field_height'
|
||||
@@ -310,8 +363,21 @@ struct ReportCreatePage {
|
||||
'psych_style': this.psychStyle
|
||||
}
|
||||
const qObj: Object = questionnaire
|
||||
const photoInput = this.photoKeyInput.trim()
|
||||
const photoKey = photoInput !== '' ? photoInput : buildMockPhotoKey(AuthStore.getUserId() ?? 'anonymous')
|
||||
// 先上传照片拿真实 object_key(本机后端磁盘直传),成功后再建报告;
|
||||
// 上传失败不扣报告额度(服务端存在性校验也挡在配额预扣之前)。
|
||||
let photoKey: string = ''
|
||||
try {
|
||||
const jpegBuf = await ImageCodec.toJpegBuffer(this.photoUri)
|
||||
photoKey = await UploadApi.uploadReportPhoto(jpegBuf)
|
||||
} catch (e) {
|
||||
this.submitting = false
|
||||
if (e instanceof ApiError) {
|
||||
this.submitError = e.hint !== undefined ? `${e.message}(${e.hint})` : e.message
|
||||
} else {
|
||||
this.submitError = '照片处理失败,请重试'
|
||||
}
|
||||
return
|
||||
}
|
||||
const req: Record<string, Object> = {
|
||||
'questionnaire': qObj,
|
||||
'photo_object_key': photoKey,
|
||||
@@ -447,7 +513,7 @@ struct ReportCreatePage {
|
||||
.fontSize(20)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.fontColor('#333333')
|
||||
Text('填写 6 项基础信息,约 1~3 分钟生成 32 维报告')
|
||||
Text('上传 1 张正面全身照 + 填写 6 项基础信息,约 1~3 分钟生成 32 维报告')
|
||||
.fontSize(12)
|
||||
.fontColor('#999999')
|
||||
}
|
||||
@@ -455,6 +521,65 @@ struct ReportCreatePage {
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
.padding({ top: 4, bottom: 4 })
|
||||
|
||||
Column({ space: 14 }) {
|
||||
Text('个人照片')
|
||||
.fontSize(15)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.fontColor('#333333')
|
||||
Column({ space: 8 }) {
|
||||
this.FieldLabel({ label: '正面全身照', err: this.photoErr, required: true })
|
||||
if (this.photoUri === '') {
|
||||
Column({ space: 6 }) {
|
||||
Text('+')
|
||||
.fontSize(28)
|
||||
.fontColor('#999999')
|
||||
Text('上传个人照片')
|
||||
.fontSize(13)
|
||||
.fontColor('#999999')
|
||||
}
|
||||
.width('100%')
|
||||
.height(140)
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.backgroundColor('#F5F6F8')
|
||||
.borderRadius(10)
|
||||
.border({ width: 1, color: '#DDDDDD', style: BorderStyle.Dashed })
|
||||
.onClick(() => {
|
||||
this.onPhotoTap()
|
||||
})
|
||||
} else {
|
||||
Stack() {
|
||||
Image(this.photoUri)
|
||||
.width('100%')
|
||||
.height(220)
|
||||
.objectFit(ImageFit.Cover)
|
||||
.borderRadius(10)
|
||||
Text('重选')
|
||||
.fontSize(12)
|
||||
.fontColor('#FFFFFF')
|
||||
.padding({ left: 12, right: 12, top: 5, bottom: 5 })
|
||||
.backgroundColor('#80000000')
|
||||
.borderRadius(12)
|
||||
.margin(8)
|
||||
.onClick(() => {
|
||||
this.onPhotoTap()
|
||||
})
|
||||
}
|
||||
.alignContent(Alignment.BottomEnd)
|
||||
}
|
||||
Text('请用本人正面全身照:正面站立、双手自然下垂、纯色背景、自然光,头到脚完整入镜')
|
||||
.fontSize(11)
|
||||
.fontColor('#999999')
|
||||
}
|
||||
.width('100%')
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
}
|
||||
.width('100%')
|
||||
.padding(16)
|
||||
.borderRadius(14)
|
||||
.backgroundColor('#FFFFFF')
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
.id('field_photo')
|
||||
|
||||
Column({ space: 14 }) {
|
||||
Text('基础信息')
|
||||
.fontSize(15)
|
||||
@@ -623,23 +748,6 @@ struct ReportCreatePage {
|
||||
.borderRadius(14)
|
||||
.backgroundColor('#FFFFFF')
|
||||
|
||||
// 照片区(#6):上传能力未开放,只做预告;对象键输入框对用户隐藏
|
||||
// (后端本就自动生成 report_photo/{userId}/{随机}.jpg,输入无用户价值)
|
||||
Column({ space: 8 }) {
|
||||
Text('照片(选填)')
|
||||
.fontSize(15)
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.fontColor('#333333')
|
||||
Text('上传照片可以让报告更准,即将开放')
|
||||
.fontSize(11)
|
||||
.fontColor('#999999')
|
||||
}
|
||||
.width('100%')
|
||||
.padding(16)
|
||||
.borderRadius(14)
|
||||
.backgroundColor('#FFFFFF')
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
|
||||
if (this.formSummary !== '') {
|
||||
Text(this.formSummary)
|
||||
.fontSize(13)
|
||||
@@ -862,6 +970,50 @@ struct ReportCreatePage {
|
||||
.backgroundColor('#FFFFFF')
|
||||
}
|
||||
|
||||
/** 照片来源选择(相册/拍照):授权通过后弹出。 */
|
||||
@Builder
|
||||
PhotoSourceDialog() {
|
||||
Column({ space: 14 }) {
|
||||
Text('上传个人照片')
|
||||
.fontSize(17)
|
||||
.fontWeight(FontWeight.Bold)
|
||||
.fontColor('#333333')
|
||||
Text('请上传本人正面全身照,照片仅用于本次形象诊断')
|
||||
.fontSize(13)
|
||||
.fontColor('#666666')
|
||||
.textAlign(TextAlign.Center)
|
||||
Button('相册选择')
|
||||
.width('100%')
|
||||
.height(42)
|
||||
.fontSize(15)
|
||||
.backgroundColor(COLOR_PRIMARY)
|
||||
.onClick(() => {
|
||||
this.doPickPhoto(false)
|
||||
})
|
||||
Button('拍照')
|
||||
.width('100%')
|
||||
.height(42)
|
||||
.fontSize(15)
|
||||
.backgroundColor(COLOR_PRIMARY)
|
||||
.onClick(() => {
|
||||
this.doPickPhoto(true)
|
||||
})
|
||||
Button('取消')
|
||||
.width('100%')
|
||||
.height(42)
|
||||
.fontSize(14)
|
||||
.backgroundColor('#F3F4F6')
|
||||
.fontColor('#666666')
|
||||
.onClick(() => {
|
||||
this.showPhotoSource = false
|
||||
})
|
||||
}
|
||||
.width('82%')
|
||||
.padding(20)
|
||||
.borderRadius(16)
|
||||
.backgroundColor('#FFFFFF')
|
||||
}
|
||||
|
||||
build() {
|
||||
Stack() {
|
||||
Column() {
|
||||
@@ -877,6 +1029,28 @@ struct ReportCreatePage {
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
|
||||
if (this.showFaceConsent) {
|
||||
FacePhotoConsent({
|
||||
usageText: '用途:照片仅用于为你生成形象诊断报告,不用于识别你的身份,也不做其他用途的分析。',
|
||||
onAgree: (): void => {
|
||||
this.onConsentAgree()
|
||||
},
|
||||
onRefuse: (): void => {
|
||||
this.onConsentRefuse()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (this.showPhotoSource) {
|
||||
Column() {
|
||||
this.PhotoSourceDialog()
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
.backgroundColor('#66000000')
|
||||
.justifyContent(FlexAlign.Center)
|
||||
}
|
||||
|
||||
if (this.showDupDialog) {
|
||||
Column() {
|
||||
this.DupDialog()
|
||||
|
||||
@@ -20,11 +20,27 @@ import { common } from '@kit.AbilityKit'
|
||||
import { picker, fileUri } from '@kit.CoreFileKit'
|
||||
import fs from '@ohos.file.fs'
|
||||
import { ContextHolder } from '../core/ContextHolder'
|
||||
import { ApiClient } from '../core/ApiClient'
|
||||
import { ApiError } from '../core/ApiTypes'
|
||||
import { TaskBonusState, PERIOD_DAY } from '../core/TaskBonusState'
|
||||
import { Tracker } from '../core/Tracker'
|
||||
import { COLOR_PRIMARY, COLOR_TEXT_SECONDARY } from '../core/Theme'
|
||||
|
||||
const PAGE_BG: string = '#F5F6F8'
|
||||
const TEXT_PRIMARY: string = '#222222'
|
||||
|
||||
/** POST /quota/tasks/share_report/claim 响应(share_report 任务闭环,T2b)。 */
|
||||
interface ClaimWire {
|
||||
task_key: string
|
||||
quota_key: string
|
||||
amount: number
|
||||
bonus_granted: number
|
||||
remaining: number
|
||||
}
|
||||
|
||||
/** 本周期已领(与后端 errors.py 对齐)。 */
|
||||
const CODE_ALREADY_CLAIMED: number = 40910
|
||||
|
||||
interface PdfRouteParams {
|
||||
pdfPath?: string
|
||||
title?: string
|
||||
@@ -100,13 +116,35 @@ struct ReportPdfPage {
|
||||
previewMode: systemShare.SharePreviewMode.DEFAULT
|
||||
}
|
||||
await controller.show(ContextHolder.get() as common.UIAbilityContext, opts)
|
||||
// 面板正常收起(含用户主动取消):不打扰,不提示
|
||||
// 面板正常收起(含用户主动取消):不打扰,不提示。
|
||||
// share_report 任务闭环(T2b):调起成功即视为完成(端侧自报,内测水位,
|
||||
// 产品方案 §3.2 决策理由 4);埋点 + 静默 claim 互不阻断。
|
||||
Tracker.track('report.share_invoke')
|
||||
this.claimShareBonus()
|
||||
} catch (e) {
|
||||
console.error(`PDF share failed: ${(e as Error).message}`)
|
||||
this.setActionText('分享失败,请重试')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* share_report 任务真实闭环:奖励到账提示;已领(40910)静默但同步已领态,
|
||||
* 其他失败静默——分享动作本身已完成,不拿奖励失败打扰用户。
|
||||
*/
|
||||
private async claimShareBonus(): Promise<void> {
|
||||
try {
|
||||
const req: Record<string, Object> = {}
|
||||
const d = await ApiClient.post<ClaimWire>('/api/v1/quota/tasks/share_report/claim', req)
|
||||
await TaskBonusState.markClaimed('share_report', PERIOD_DAY)
|
||||
this.setActionText(`感谢分享,额度 +${d.amount}`)
|
||||
} catch (e) {
|
||||
if (e instanceof ApiError && e.code === CODE_ALREADY_CLAIMED) {
|
||||
// 今日已领:静默不打扰,但同步已领态(任务面板显示一致)
|
||||
await TaskBonusState.markClaimed('share_report', PERIOD_DAY)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async saveAs(): Promise<void> {
|
||||
try {
|
||||
const docPicker = new picker.DocumentViewPicker(ContextHolder.get())
|
||||
|
||||
@@ -23,7 +23,7 @@ import { ApiClient } from '../core/ApiClient'
|
||||
import { ApiError, isAuthError } from '../core/ApiTypes'
|
||||
import { AuthStore } from '../core/AuthStore'
|
||||
import { ContextHolder } from '../core/ContextHolder'
|
||||
import { TaskBonusState, PERIOD_DAY } from '../core/TaskBonusState'
|
||||
import { TaskBonusState, PERIOD_DAY, PERIOD_LIFETIME } from '../core/TaskBonusState'
|
||||
import { Tracker } from '../core/Tracker'
|
||||
import { COLOR_PRIMARY, COLOR_TEXT_SECONDARY } from '../core/Theme'
|
||||
import request from '@ohos.request'
|
||||
@@ -52,7 +52,7 @@ interface QuotaWireResp {
|
||||
quota_key: string
|
||||
used: number
|
||||
limit_value: number
|
||||
bonus_granted: boolean
|
||||
bonus_granted: number
|
||||
remaining: number
|
||||
reset_at: string
|
||||
}
|
||||
@@ -189,6 +189,9 @@ struct ReportResultPage {
|
||||
if (this.statusRaw === 'SUCCEEDED') {
|
||||
// 反馈回显 + report_feedback 任务闭环的数据源(T-P3-21)
|
||||
this.loadFeedback()
|
||||
// first_report 任务闭环(T2b):报告成功展示的入口路径上静默 claim
|
||||
// (lifetime 周期,后端幂等;领过则 40910 静默同步已领态)
|
||||
this.claimFirstReport()
|
||||
// 预约留资卡(T-P3-22):卡片渲染即曝光埋点,每进入结果页只打一次
|
||||
if (!this.cardViewTracked) {
|
||||
this.cardViewTracked = true
|
||||
@@ -447,6 +450,25 @@ struct ReportResultPage {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* first_report 任务真实闭环(T2b):报告成功展示即完成首次速测,静默 claim;
|
||||
* 已领(40910,含 lifetime 重复进页)静默同步已领态,其他失败静默——
|
||||
* 报告展示是主流程,奖励失败不打扰。
|
||||
*/
|
||||
private async claimFirstReport(): Promise<void> {
|
||||
try {
|
||||
const req: Record<string, Object> = {}
|
||||
const d = await ApiClient.post<ClaimWire>('/api/v1/quota/tasks/first_report/claim', req)
|
||||
await TaskBonusState.markClaimed('first_report', PERIOD_LIFETIME)
|
||||
this.toast(`形象速测完成,额度 +${d.amount}`)
|
||||
} catch (e) {
|
||||
if (e instanceof ApiError && e.code === CODE_ALREADY_CLAIMED) {
|
||||
await TaskBonusState.markClaimed('first_report', PERIOD_LIFETIME)
|
||||
}
|
||||
// 其他失败静默
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 全面报告预约留资卡(T-P3-22) ====================
|
||||
|
||||
/** 拉预约态决定按钮;失败保持未预约态(用户可点击,服务端幂等兜底)。 */
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"pages/LlmTestPage",
|
||||
"pages/TryonPage",
|
||||
"pages/HairDesignPage",
|
||||
"pages/HairColorPage",
|
||||
"pages/ReportPdfPage",
|
||||
"pages/FittingRoomPage",
|
||||
"pages/DiagnosisLandingPage",
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
# T2b · 任务换额度:端侧闭环与完成判定
|
||||
|
||||
> 对应任务:`T-P1-26` 收尾件之二(T2 的后续迭代)| 需求:`FR-BILL-03`、`FR-BILL-04`、`FR-BILL-07` | 跨端任务:后端(meida_backend)+ 端侧(app/)
|
||||
> 先读《README.md(协作规程)》与《README-FE批次.md》,遵守全部纪律。
|
||||
> 产品定稿依据:产品方案 §3.2「任务奖励额度的获取方式」(2026-09-11 定稿表与决策理由)。
|
||||
|
||||
## 1. 目标
|
||||
|
||||
把「做任务换额度」从「只有签到能真领」补齐为完整闭环:
|
||||
|
||||
1. 任务目录按产品定稿落地(4 项上线 + `invite_friend` 下架),奖励数值由占位值 1 改为定稿值;
|
||||
2. 有服务端可信信号的任务(`report_feedback` / `first_report`)在 claim 时做完成校验,无凭据拒绝;
|
||||
3. 端侧面板从「toast 占位」升级为真实「去完成」跳转 + 完成点自动 claim;
|
||||
4. 全程遵守 `FR-BILL-07`:文案不出现价格/购买/会员/升级字样。
|
||||
|
||||
## 2. 现状事实(2026-09-11 读码核实)
|
||||
|
||||
### 后端(meida_backend)
|
||||
|
||||
- ✅ `POST /quota/tasks/{task_key}/claim` 已实现(T2):幂等(`bl_ledger.idempotency_key` 快捷路径 + 唯一约束并发兜底)、封顶(`grant_bonus` 对 `task_bonus_max`)、配置化(`TASK_BONUS_RULES_JSON`)、错误码 40410/40910/40310 文案合规。见 `apps/api/routers/quota.py:65`、`packages/billing/service.py:306`、`packages/domain/billing/quota.py:146`。
|
||||
- ✅ 配额种子与产品方案 §3.2 对齐(`migrations/versions/0003_align_quota_with_product_ssot.py`):`agent_chat` 10/10/40、`tryon` 3/3/8、`hairstyle` 3/2/6、`hd_export` 1/0/3、`report_basic` 终身 1、`report_regen` 月 1/1/2。
|
||||
- ❌ **claim 不做任何完成凭据校验**:任何登录用户对任何 task_key 直接 POST 即领。`report_feedback`(`rp_feedback` 表)与 `first_report`(`rp_report` 表)明明有可信信号却没用上。
|
||||
- ❌ `task_bonus_rules` 默认值(`packages/shared/config.py:136`)amount 全是占位值 1,且映射与 §3.2 总量对不上:换装最多 +2/日(表定 +3)、发型 0(表定 +2)、对话 +2(表定 +10)。
|
||||
- ❌ 无任务目录下发接口——V1 决定端侧静态表,不做。
|
||||
- 事实备注:`rp_share` 表已建结构但无路由(models.py 注释「V1 只建结构」);`POST /events/batch` 无事件白名单(事件字典待 TD-23)。
|
||||
|
||||
### 端侧(app/entry/src/main/ets/)
|
||||
|
||||
- ✅ `components/f1/TaskBonusPanel.ets`:五项静态任务、已领态走 `core/TaskBonusState.ets`(preferences `meida_task_bonus`,跨重启)、40910 同步已领态、文案合规;已挂载 5 处(`ProfileContent` / `ChatPage` / `FittingRoomPage` / `HairDesignPage` / `HairColorPage`)。
|
||||
- ✅ 真实闭环已有两条:`sign_in` 点击即 claim(面板内);`report_feedback` 在报告页反馈提交成功后静默自动 claim(`ReportResultPage.ets:435`)。
|
||||
- ✅ `DailyLimiter.setBonus` 已把 `bonus_granted` 计入试穿/试戴当日上限;`ChatPage` 对话额度服务端口径(remaining 含 bonus)。
|
||||
- ❌ 其余 3 项任务是 toast 占位(「即将上线」),无「去完成」跳转。
|
||||
- ❌ `share_report` 无联动:`ReportPdfPage.ets:90` 已有 Share Kit `systemShare` 分享 PDF,但分享动作与 claim 之间没有凭据、没有联动。
|
||||
- ❌ 报告生成成功处无 `first_report` claim 联动。
|
||||
- ❌ 面板不展示每项的奖励数值与周期(任务表纪律是"数值不硬编码",定稿后可写入展示文案,到账仍以 claim 响应为准)。
|
||||
- 🐞 `ChatPage.ets:36` `QuotaWireResp.bonus_granted` 类型误写为 `boolean`(后端返回 number;该字段暂未消费,本迭代顺手修正)。
|
||||
|
||||
### 判定与埋点
|
||||
|
||||
- ✅ 埋点链路通:`Tracker` → `POST /events/batch` → `ob_event`(整批 fail-close 校验)。
|
||||
- ❌ 任务完成事件目前只有 `task_bonus.claim_result`;无面板曝光、任务点击、分享调起事件。
|
||||
- 产品决策(已写进 §3.2):**埋点只作观测,不作发放凭据**——埋点本身可伪造且有 20 条/30s 节流延迟,拿它做校验是自欺。
|
||||
|
||||
## 3. V1 任务目录(产品定稿,2026-09-11)
|
||||
|
||||
| task_key | 名称 | quota_key | amount | claim_period | 完成判定 | 状态 |
|
||||
|----------|------|-----------|--------|--------------|---------|------|
|
||||
| `sign_in` | 每日签到 | `agent_chat` | **10** | `day` | 点击签到即完成,无额外校验 | 上 |
|
||||
| `report_feedback` | 给报告结论打反馈 | `hairstyle` | **2** | `day` | 服务端校验当日 `rp_feedback` 存在 | 上 |
|
||||
| `share_report` | 分享我的报告 | `tryon` | **3** | `day` | 端侧自报,无服务端校验(内测水位) | 上 |
|
||||
| `first_report` | 完成首次形象速测 | `report_regen` | **1** | `lifetime` | 服务端校验 `rp_report` 存在已完成报告 | 上 |
|
||||
| `invite_friend` | 邀请好友 | — | — | — | 无可信信号 | **下架**(env 不下发该键) |
|
||||
|
||||
变更点:删除 `profile_complete`(资料维护 `FR-ACC-06` V1 未实现,无可信信号),新增 `first_report`;`report_feedback` 由 `report_regen` 改挂 `hairstyle`(理由见产品方案 §3.2 决策理由第 3 条)。
|
||||
|
||||
## 4. 实现要点
|
||||
|
||||
### 后端(worktree 纪律见《README.md》)
|
||||
|
||||
允许改动:`packages/billing/service.py`、`packages/billing/repo.py`(如需)、`packages/billing/schemas.py`(如需)、测试新文件。
|
||||
|
||||
1. **B1 · 定稿数值走 env**:部署/本地 `.env` 的 `TASK_BONUS_RULES_JSON` 改为:
|
||||
```json
|
||||
{
|
||||
"sign_in": {"quota_key": "agent_chat", "amount": 10, "claim_period": "day"},
|
||||
"report_feedback": {"quota_key": "hairstyle", "amount": 2, "claim_period": "day"},
|
||||
"share_report": {"quota_key": "tryon", "amount": 3, "claim_period": "day"},
|
||||
"first_report": {"quota_key": "report_regen", "amount": 1, "claim_period": "lifetime"}
|
||||
}
|
||||
```
|
||||
不含 `invite_friend`——不下发即下架(claim 返回 40410「任务不存在或暂未开放」),这是配置化设计的红利,不要为它写分支代码。
|
||||
⚠️ `config.py` 的默认值是占位且**禁改**;在提交信息里写明「默认值与定稿不一致,建议协调提交同步默认值与 `.env.example`」,由协调者统一处理。
|
||||
2. **B2 · claim 完成校验钩子**:`BillingService.claim_task_bonus` 在解析规则后、幂等快捷路径**之前**,按 task_key 执行完成校验(映射写死在 service 内即可,不做配置化):
|
||||
- `report_feedback`:`rp_feedback` 存在 `user_id` 匹配且 `created_at` 落在当日(UTC+8,与 `period_key` 同时区口径)的行;
|
||||
- `first_report`:`rp_report` 存在 `user_id` 匹配且状态为已完成的行;
|
||||
- `sign_in` / `share_report`:**不校验**,写注释说明产品决策(签到行为本身即任务;分享内测期自报,`hard_cap` 兜底,见 §3.2 决策理由 4)。
|
||||
- 校验不过 → `AppError(ErrorCode.TASK_BONUS_NOT_ELIGIBLE)`。**该错误码尚不存在**(建议 40311,meta「先完成任务,再来领奖励」)——`errors.py` 禁改,在提交信息中列出需求,由协调提交统一加;本地开发可先在 service 里 `raise AppError(...)` 引用占位并在提交信息标注。
|
||||
3. **B3 · 幂等与封顶语义不变**:40910/40310 路径、`delta=0` 流水口径不动;校验逻辑不得影响既有测试。
|
||||
|
||||
### 端侧(纯 Windows,构建门禁见《README-FE批次.md》§1)
|
||||
|
||||
允许改动:`components/f1/TaskBonusPanel.ets`、`pages/ReportResultPage.ets`、`pages/ReportPdfPage.ets`、`pages/ChatPage.ets`(仅 B 端 wire 类型修正)。其余页面如需挂回调点,在提交信息里说明。
|
||||
|
||||
1. **E1 · 面板任务表更新为定稿 4 项**:删 `invite_friend`;`profile_complete` 替换为 `first_report`(名称「完成首次形象速测」);每项 desc 写清奖励内容(如「领 10 轮 AI 对话额度」「领 2 次发型试戴额度」)并标注周期(「每日」/「一次性」)。到账数值仍以 claim 响应 `amount` 为准,desc 只是展示。
|
||||
2. **E2 · 「去完成」真实跳转**(`router.pushUrl`,禁止 import 页面):
|
||||
- `first_report` → `pages/DiagnosisLandingPage`;进入面板时若已可领(服务端已有报告且未领过)则按钮直接为「领额度」走 claim;
|
||||
- `report_feedback` → 报告结果页(带 `reportId` 参数);无报告时 toast「先生成你的形象速测,再来反馈」;
|
||||
- `share_report` → `pages/ReportPdfPage`(分享入口所在页);无报告时同上引导;
|
||||
- `sign_in` 保持点击即领。
|
||||
3. **E3 · 完成点自动 claim**(与既有 `claimReportFeedback` 同款静默闭环:成功 toast 到账、40910 静默同步已领态、其他失败静默):
|
||||
- `ReportPdfPage.share()` 调起系统分享面板成功后:静默 claim `share_report` + `TaskBonusState.markClaimed('share_report', PERIOD_DAY)` + `Tracker.track('report.share_invoke', ...)`;
|
||||
- 报告生成任务成功(`ReportResultPage` 展示 SUCCEEDED 结果的入口路径):静默 claim `first_report` + `markClaimed`。
|
||||
4. **E4 · 状态与文案**:见 §5,逐字遵守。
|
||||
5. **E5 · 埋点补齐**(事件名字面量、props 只放低维枚举/数值):`task_bonus.panel_view`、`task_bonus.task_tap`(props: `task_key`)、`report.share_invoke`、`task_bonus.claim_result`(已有,保留)。
|
||||
6. **E6 · 修正** `ChatPage.ets:36` `bonus_granted: boolean` → `number`。
|
||||
|
||||
## 5. UX 与文案规格(FR-BILL-07,逐字遵守)
|
||||
|
||||
**面板信息架构**:标题「做任务换额度」;分组一「每日任务」(签到 / 打反馈 / 分享报告);分组二「新手任务」(完成首次形象速测);底部说明保留「奖励以实际到账为准,额度每日重置」。
|
||||
|
||||
**按钮五态**:
|
||||
|
||||
| 状态 | 文案 |
|
||||
|------|------|
|
||||
| 可领取(签到 / 已满足条件) | 「领额度」 |
|
||||
| 需跳转完成 | 「去完成」 |
|
||||
| 领取中 | 「领取中…」 |
|
||||
| 已领(日周期) | 「今日已领」 |
|
||||
| 已领(终身) | 「已领取」 |
|
||||
|
||||
**toast**:
|
||||
|
||||
| 场景 | 文案 |
|
||||
|------|------|
|
||||
| 领取成功 | 「签到成功,额度 +{amount}」/「感谢反馈,额度 +{amount}」(amount 取响应值,不硬编码) |
|
||||
| 40910 本周期已领 | 「今天已经领过啦」 |
|
||||
| 40310 奖励封顶 | 「今日任务奖励已达上限,明天再来」 |
|
||||
| 40311 未完成 | 「先完成任务,再来领奖励」 |
|
||||
| 无报告时去做反馈/分享 | 「先生成你的形象速测,再来反馈」 |
|
||||
|
||||
**红线**:全部新增文案不得出现价格、购买、会员、升级、充值等字样(`FR-BILL-07`);额度耗尽入口文案维持「今日额度已用完,明天再来,或做个任务多换几次」口径。
|
||||
|
||||
## 6. 测试要求
|
||||
|
||||
### 后端
|
||||
|
||||
- 单测:校验钩子纯逻辑(若抽纯函数)覆盖有/无凭据两分支。
|
||||
- 集成测试新文件 `tests/integration/test_task_bonus_eligibility.py`(允许跑,`MEIDA_RUN_INTEGRATION=1`):
|
||||
1. 无报告用户 claim `first_report` → 40311;创建报告完成后 → 200 且 `bonus_granted`=1;
|
||||
2. 无反馈 claim `report_feedback` → 40311;提交一条反馈后 → 200 且发型 `bonus_granted`=2;
|
||||
3. `sign_in` claim → 200,`agent_chat` `bonus_granted`=10;当日再 claim → 40910;
|
||||
4. `invite_friend`(不在 env)→ 40410;
|
||||
5. 40311 与 40310 路径均**不写流水**(查 `bl_ledger` 无新行)。
|
||||
- 提交前全绿:`ruff check` / `ruff format --check` / `mypy`(范围同 T2)/ `lint-imports` / `pytest -q`。
|
||||
|
||||
### 端侧
|
||||
|
||||
- 构建门禁(唯一验收命令,见《README-FE批次.md》§1)`BUILD SUCCESSFUL`;
|
||||
- ArkTS 严格模式铁律(README-FE批次 §3)逐条遵守:显式泛型、具名 wire interface、throw 只抛 ApiError。
|
||||
|
||||
## 7. 禁改清单(通用禁改之外)
|
||||
|
||||
- 后端:`packages/shared/config.py`、`packages/shared/errors.py`、`packages/shared/models.py`、`migrations/**`、`apps/api/routers/events.py`、`packages/analytics/**`。新错误码与默认值同步**只写进提交信息**,由协调者处理。
|
||||
- 端侧:`core/**`(含 `TaskBonusState.ets`、`Tracker.ets`、`DailyLimiter.ets`——本迭代需求已够,不要顺手扩展)、`module.json5`、`main_pages.json`、resources、`oh-package*.json5`。
|
||||
- 不改配额种子数值、不动 `grant_bonus` 语义、不改既有测试断言语义。
|
||||
|
||||
## 8. 验收标准(按组,每条可验收)
|
||||
|
||||
### 后端
|
||||
|
||||
1. 四个 task_key 按 §3 定稿数值 claim 成功,响应 `amount` 与定稿一致;`invite_friend` 返回 40410。
|
||||
2. 无凭据 claim `report_feedback` / `first_report` 返回 40311 且无流水;有凭据后 claim 成功。
|
||||
3. 重复 claim 40910、封顶 40310 行为与 T2 验收一致,无回归(既有 `test_task_bonus.py` 全绿)。
|
||||
4. 后端检查全绿(§6)。
|
||||
|
||||
### 端侧
|
||||
|
||||
5. 面板只展示 4 项定稿任务,奖励文案、周期标注、五态按钮与 §5 一致。
|
||||
6. 三项「去完成」跳转可达目标页;无报告场景给引导 toast 而非报错。
|
||||
7. 分享调起成功、报告生成成功两处自动 claim 生效,面板已领态同步(含杀进程重启后)。
|
||||
8. `ChatPage` wire 类型修正后构建绿;埋点新增事件在 `ob_event` 可见。
|
||||
|
||||
### 联调
|
||||
|
||||
9. 全链路走查(真机或模拟器连本地后端):签到 → 对话额度卡 +10;报告页打反馈 → 发型当日上限 +2(`DailyLimiter` 生效);PDF 页分享 → 换装当日上限 +3;完成首次速测 → 重生成额度 +1(个人中心额度卡可见)。
|
||||
10. 异常路径走查:同日重复领取 →「今天已经领过啦」;未打反馈直接在面板点领取(若 UI 可达)→「先完成任务,再来领奖励」。
|
||||
11. 文案红线检查:任务面板、toast、额度耗尽提示全文检索无「价格/购买/会员/升级/充值/¥」字样。
|
||||
|
||||
## 9. 提交信息
|
||||
|
||||
后端:
|
||||
|
||||
```
|
||||
feat(billing): task bonus final rules + eligibility check (T2b)
|
||||
|
||||
TASK_BONUS_RULES_JSON 定稿(签到+10对话/反馈+2发型/分享+3换装/首测+1重生成,
|
||||
invite_friend 下架);report_feedback/first_report claim 前完成校验(rp_feedback/
|
||||
rp_report 可信信号),sign_in/share_report 不校验(产品决策见产品方案 §3.2)。
|
||||
|
||||
偏差说明:TASK_BONUS_NOT_ELIGIBLE(40311) 错误码与 config.py 默认值同步需协调提交;
|
||||
<其余偏差写这里,无则写"无">
|
||||
```
|
||||
|
||||
端侧:
|
||||
|
||||
```
|
||||
feat(f1): task bonus panel final catalog + auto-claim hooks (T2b)
|
||||
|
||||
面板 4 项定稿任务与「去完成」真实跳转;分享调起/报告生成成功自动 claim;
|
||||
新增 panel_view/task_tap/share_invoke 埋点;修正 ChatPage bonus_granted 类型。
|
||||
|
||||
偏差说明:<如有写在这里,无则写"无">
|
||||
```
|
||||
@@ -464,7 +464,25 @@ V1 无付费、无会员、无点数购买,**所有注册用户使用同一套
|
||||
2. **按设备维度计量**(设备指纹 + 匿名 ID),因此**必然可以被清数据绕过**。这是可接受的:游客额度极小,绕过的收益低于用户重装 App 的成本,不值得为它上强风控。
|
||||
3. **额度用尽必须是"引导登录"而非"静默失败"** —— 这是游客模式唯一的转化时机,做成一个报错就白费了。
|
||||
|
||||
**任务奖励额度的获取方式**(全部不涉及金钱):每日签到、完善画像资料、给报告结论打反馈、邀请好友、分享报告长图。
|
||||
**任务奖励额度的获取方式**(全部不涉及金钱)。V1 任务目录已于 **2026-09-11 定稿**(原为占位;研发任务书见《[开发任务包/T2b-任务换额度-端侧闭环](./开发任务包/T2b-任务换额度-端侧闭环.md)》):
|
||||
|
||||
| 任务 | task_key | 奖励 | 领取周期 | 完成判定 | 内测期状态 |
|
||||
|------|----------|------|---------|---------|-----------|
|
||||
| 每日签到 | `sign_in` | AI 对话 **+10 轮** | 每日 | 点击签到即完成(登录态 + 服务端日幂等),行为本身即任务 | ✅ 上 |
|
||||
| 给报告结论打反馈 | `report_feedback` | 发型/发色 **+2 次** | 每日 | **服务端可信**:当日 `rp_feedback` 存在本人记录 | ✅ 上 |
|
||||
| 分享我的报告 | `share_report` | 换装 **+3 次** | 每日 | **端侧自报**:调起系统分享面板即算完成,埋点观测 | ✅ 上(自报水位) |
|
||||
| 完成首次形象速测 | `first_report` | 报告重生成 **+1 次** | 终身一次 | **服务端可信**:`rp_report` 存在本人已完成报告 | ✅ 上(替代原「完善画像资料」) |
|
||||
| ~~邀请好友~~ | `invite_friend` | — | — | 无可信信号(无邀请码/回流链路) | ❌ **内测期下架**,V2 有邀请链路后重评 |
|
||||
|
||||
**数值决策理由(2026-09-11)**:
|
||||
|
||||
1. **与配额种子精确对齐**:四个任务的奖励合计恰好等于 `bl_quota_rule.task_bonus_max`(对话 10 / 换装 3 / 发型 2 / 重生成 1),只需改 `TASK_BONUS_RULES_JSON` 配置即生效,**不动配额种子、不发版**(`FR-BILL-04`)。
|
||||
2. **签到独得对话 +10**:Agent 单轮成本最低(≤¥0.05),签到让对话额度翻倍(10→20 轮/日)是最直接的日活钩子;物理上限 `hard_cap` 40 不变,§5.2.1 成本模型不受影响。
|
||||
3. **反馈奖发型 +2/日**(改掉原配置「反馈奖重生成 +1」):反馈是每日可重复行为,而重生成月封顶 1 次——原配置下用户当月第 2 天起再反馈必撞 40310,等于白做。且反馈数据是结论认同率/修正率指标(`FR-RPT-19`)的唯一数据来源,值得用高频日奖励驱动。
|
||||
4. **分享只能端侧自报,内测期接受**:Share Kit 系统分享无「实际发送成功」回调,内测期不做服务端事件校验(埋点本身可伪造且批上报有节流,做校验是自欺)。刷满收益被 `hard_cap` 8 锁死,已含在 §5.2.1 物理上限成本模型内,**零增量成本风险**;埋点观测滥用率,内测后复评。
|
||||
5. **邀请好友直接砍**:无邀请码与回流链路,任何形态都只能纯自报且无观测锚点,上了等于无条件每日 +1 换装。
|
||||
6. **「完善画像资料」改造为「完成首次形象速测」**:资料维护功能(`FR-ACC-06`)V1 未实现,无可信信号;完成速测是产品核心漏斗(报告是画像生产者),服务端有 `rp_report` 记录可校验,语义闭环「觉得不准,本月可重来一次」。
|
||||
7. 主表「报告重新生成 +1 次/月」在内测期由 `first_report` **一次性**兑现;月度循环获取途径等 V2 任务体系扩展时再补。
|
||||
|
||||
**三条不可违反的设计纪律**:
|
||||
|
||||
|
||||
+1
-1
Submodule meida_backend updated: 7bcbb8d40b...a1d0171fc5
Reference in New Issue
Block a user