Commit b9d3c7e9 by 胡悦

fix(prelearning, sop-material-preview): 统一数据格式并修复滚动条视觉问题

1.  预学习模块对齐:将`profile.needs`字段从字符串调整为字符串数组,与`objections`保持一致格式,更新前后端契约定义、后端数据归一化逻辑、前端Mock数据、DemandCard组件及相关测试用例
2.  修复SOP素材预览页滚动条问题:添加页面专属class作为作用域边界,新增全局样式隐藏对应页面的浏览器原生滚动条,同时保留滚动能力且不影响其他应用入口
3.  其他优化:移除预学习模块多余的控制台日志,补充前端tsconfig的node类型依赖,更新AGENTS.md文档补充OpenSpec归档流程,新增OpenSpec归档校验脚本
1 parent a6b7ec9a
Showing 26 changed files with 483 additions and 51 deletions
......@@ -51,7 +51,7 @@
- `@fixbug + <change name> + 描述内容`:如果用户明确指定对应的 OpenSpec change,则直接修改该 change 下受影响的 OpenSpec artifacts 与 `tasks.md`;如果未指定,则先检查是否已有对应 OpenSpec,若没有则创建新的 change,若已有则先更新受影响的 OpenSpec artifacts 与 `tasks.md`。用户确认文档后,再进入代码修改,不直接改代码。
- OpenSpec 锁定规范:创建 `openspec/changes/<change-name>/`,按顺序完成 `proposal.md`、`design.md`、`specs/.../spec.md`、`tasks.md`;常用命令:`openspec status --change "<change-name>" --json`、`openspec instructions <artifact> --change "<change-name>" --json`、`openspec validate "<change-name>" --strict`。
- Superpowers 执行编码、测试、验证:按 OpenSpec tasks 和实施计划用 TDD 实现,运行类型检查、测试、构建和必要的浏览器验证;常用命令:`npm run typecheck`、`npm test`、`npm run build`。
- OpenSpec 归档:确认代码、测试、规范对齐后归档;常用命令:`openspec archive "<change-name>"`。
- OpenSpec 归档:确认代码、测试、规范对齐,并先运行 `node scripts/check-openspec-archive-ready.mjs --project workspace/<project>` 通过后归档;常用命令:`openspec archive "<change-name>"`。
### Agent 自检基线
......@@ -78,6 +78,7 @@
- 完成前必须运行真实验证命令。
- 任何 Agent 不得只用“已自检通过”替代真实命令、OpenSpec strict 校验、浏览器/API/集成验证或明确的用户确认;需要命令型门禁时,以 Exit Code 为准。
- 代码、测试、规范未对齐前,不归档。
- 归档前必须运行 `node scripts/check-openspec-archive-ready.mjs --project workspace/<project>`;只有 `stage=READY_TO_ARCHIVE`、`review_completed=true`、`validation_completed=true`、`last_validation.result=PASS`、OpenSpec strict 校验与 status 均通过时,才允许执行 `openspec archive`。
- 需求确认前,不写业务实现代码。
- 当前阶段结束并准备开启下一阶段前,必须进行阶段产物核对:需求分析阶段检查 `workspace/<project>/docs/requirements/` 或对应需求文档;架构阶段检查 ADR 草案、架构说明或需同步 OpenSpec 的约束;OpenSpec 阶段检查 `proposal.md`、`design.md`、`specs/.../spec.md`、`tasks.md` 和 strict 校验结果;实现、Review、验证阶段检查对应交接、测试和验证报告。缺失时先补齐当前阶段产物,不得直接推进。
- 所有会修改系统行为的 bug 修复,必须先对齐对应的 OpenSpec:如果用户已明确指定 change name,则直接更新该 change 下相关 artifacts 和 `tasks.md`;如果未指定,则按原流程判断,没有对应 change 时先创建新的 change,已有对应 change 时先更新相关 artifacts 和 `tasks.md`。在用户确认文档前,不直接修改代码。
......
#!/usr/bin/env node
import { existsSync, readFileSync } from 'node:fs';
import path from 'node:path';
import { spawnSync } from 'node:child_process';
const args = process.argv.slice(2);
function readFlag(name) {
const index = args.indexOf(name);
if (index === -1) {
return undefined;
}
return args[index + 1];
}
function fail(message) {
console.error(`Archive gate failed: ${message}`);
process.exit(1);
}
function info(message) {
console.log(`Archive gate: ${message}`);
}
const projectArg = readFlag('--project');
const stateArg = readFlag('--state');
const changeArg = readFlag('--change');
const repoRoot = path.resolve(import.meta.dirname, '..');
if (!projectArg && !stateArg) {
fail('pass --project workspace/<project> or --state path/to/.workflow-state.json');
}
const statePath = path.resolve(repoRoot, stateArg ?? path.join(projectArg, '.workflow-state.json'));
if (!existsSync(statePath)) {
fail(`state file not found: ${path.relative(repoRoot, statePath)}`);
}
let state;
try {
state = JSON.parse(readFileSync(statePath, 'utf8'));
} catch (error) {
fail(`state file is not valid JSON: ${error.message}`);
}
const project = projectArg ?? state.project;
const change = changeArg ?? state.change;
if (!project) {
fail('state.project is missing; pass --project explicitly');
}
if (!change) {
fail('state.change is missing; pass --change explicitly');
}
if (changeArg && state.change && changeArg !== state.change) {
fail(`--change ${changeArg} does not match state.change ${state.change}`);
}
if (state.stage !== 'READY_TO_ARCHIVE') {
fail(`stage must be READY_TO_ARCHIVE, got ${state.stage ?? 'missing'}`);
}
const gates = state.gates ?? {};
if (gates.review_completed !== true) {
fail('gates.review_completed must be true');
}
if (gates.validation_completed !== true) {
fail('gates.validation_completed must be true');
}
if (gates.openspec_locked !== true) {
fail('gates.openspec_locked must be true');
}
if (state.last_validation?.result !== 'PASS') {
fail('last_validation.result must be PASS');
}
if (!Array.isArray(state.last_validation?.commands) || state.last_validation.commands.length === 0) {
fail('last_validation.commands must record the fresh verification commands');
}
const projectCwd = path.resolve(repoRoot, project);
if (!existsSync(projectCwd)) {
fail(`project directory not found: ${project}`);
}
const changeDir = path.join(projectCwd, 'openspec', 'changes', change);
if (!existsSync(changeDir)) {
fail(`OpenSpec change directory not found: ${path.relative(repoRoot, changeDir)}`);
}
function commandBin() {
const rtk = spawnSync('rtk', ['--version'], { cwd: repoRoot, encoding: 'utf8' });
return rtk.error ? 'openspec' : 'rtk';
}
function runOpenSpec(subArgs) {
const bin = commandBin();
const commandArgs = bin === 'rtk' ? ['openspec', ...subArgs] : subArgs;
const result = spawnSync(bin, commandArgs, {
cwd: projectCwd,
encoding: 'utf8',
});
if (result.error) {
fail(`failed to run ${bin}: ${result.error.message}`);
}
if (result.status !== 0) {
const output = `${result.stdout ?? ''}${result.stderr ?? ''}`.trim();
fail(`${bin} ${commandArgs.join(' ')} exited ${result.status}${output ? `\n${output}` : ''}`);
}
return result.stdout ?? '';
}
function parseJsonFromOutput(output) {
const start = output.indexOf('{');
const end = output.lastIndexOf('}');
if (start === -1 || end === -1 || end < start) {
fail('openspec status did not return a JSON object');
}
try {
return JSON.parse(output.slice(start, end + 1));
} catch (error) {
fail(`failed to parse openspec status JSON: ${error.message}`);
}
}
info(`checking ${project} / ${change}`);
runOpenSpec(['validate', change, '--strict']);
const status = parseJsonFromOutput(runOpenSpec(['status', '--change', change, '--json']));
if (status.changeName !== change) {
fail(`openspec status changeName mismatch: ${status.changeName ?? 'missing'}`);
}
if (status.isComplete !== true) {
fail('openspec status isComplete must be true');
}
info('ready to archive');
{
"stage": "ARCHIVED",
"project": "workspace/single-pages",
"change": "add-prelearning-script-view",
"change": "align-prelearning-needs-array",
"current_agent": "openspec-agent",
"last_handoff": "2026-06-26 已复核并归档 `add-prelearning-script-view`。该 change 的任务、需求和代码已逐项核对;前端预学习测试、前后端 typecheck/build、后端预学习测试与 `openspec validate add-prelearning-script-view --strict` 均通过。因长期 `prelearning-script-view` spec 已吸收该 change 及后续增量,本次归档使用 `--skip-specs` 仅收口历史遗留 active change。",
"last_handoff": "2026-06-29 `align-prelearning-needs-array` 已按 Review -> QA -> archive 顺序完成。归档前守卫通过,OpenSpec archive 成功,change 已归档为 `workspace/single-pages/openspec/changes/archive/2026-06-29-align-prelearning-needs-array`;长期 specs 已更新并通过 `openspec validate --specs --strict`。",
"gates": {
"requirements_boundary_confirmed": true,
"architecture_confirmed": true,
"openspec_locked": true,
"user_confirmed_openspec": true,
"implementation_started": true,
"review_completed": true,
"validation_completed": true
},
"last_validation": {
"commands": [
"cd workspace/single-pages/front && rtk npm run test -- src/apps/prelearning/app.test.tsx",
"cd workspace/single-pages/front && rtk npm run typecheck",
"cd workspace/single-pages/front && rtk npm run build",
"cd workspace/single-pages/backend && rtk npm run test -- src/routes/prelearning.test.ts",
"cd workspace/single-pages/front && rtk npm run test -- src/apps/prelearning/app.test.tsx",
"cd workspace/single-pages/backend && rtk npm run typecheck",
"cd workspace/single-pages/backend && rtk npm run build",
"cd workspace/single-pages && rtk openspec validate add-prelearning-script-view --strict",
"cd workspace/single-pages && rtk openspec archive add-prelearning-script-view --yes --skip-specs"
"cd workspace/single-pages/front && rtk npm run typecheck",
"cd workspace/single-pages && rtk openspec validate align-prelearning-needs-array --strict",
"cd /Users/yuehu/Desktop/work/ai-workflow && rtk git diff --check",
"cd workspace/single-pages && rtk openspec status --change align-prelearning-needs-array --json",
"cd /Users/yuehu/Desktop/work/ai-workflow && rtk node scripts/check-openspec-archive-ready.mjs --project workspace/single-pages",
"cd workspace/single-pages && rtk openspec archive align-prelearning-needs-array --yes",
"cd workspace/single-pages && rtk openspec list",
"cd workspace/single-pages && rtk openspec validate --specs --strict"
],
"result": "PASS",
"notes": "2026-06-26 前端预学习测试 29/29、后端预学习测试 24/24、前后端 typecheck 与 build 均通过;`openspec validate add-prelearning-script-view --strict` 返回 valid。由于长期 `prelearning-script-view` spec 已在后续变更中持续扩展并保留最新事实源,本次使用 `openspec archive add-prelearning-script-view --yes --skip-specs` 收口历史遗留 active change;strict 校验/归档输出中的 PostHog telemetry DNS 提示不影响 Exit Code。"
"notes": "代码 Review 通过,未发现阻塞 QA 的问题。后端预学习测试 24 passed;前端预学习测试 30 passed;前后端 typecheck 通过;OpenSpec strict 通过;git diff --check 通过;OpenSpec status isComplete=true;归档前守卫通过;OpenSpec archive 成功归档为 2026-06-29-align-prelearning-needs-array;openspec list 显示 No active changes found;openspec validate --specs --strict 显示 6 passed, 0 failed。OpenSpec 命令输出中的 PostHog DNS 报错为遥测刷新失败,命令退出码为 0。用户已于 2026-06-29 确认浏览器页面验证通过。"
},
"updated_at": "2026-06-26T14:20:00+08:00"
"updated_at": "2026-06-29T18:15:00+08:00"
}
......@@ -178,7 +178,7 @@ export interface PrelearningProfile {
family: string;
behavior: string;
objections: string[];
needs: string;
needs: string[];
includes: string[];
}
......
......@@ -144,12 +144,20 @@ function normalizeTextArray(value: unknown): string[] {
.filter((item) => item.length > 0);
}
function normalizeTextList(value: unknown): string {
function normalizeTextSegments(value: unknown): string[] {
if (Array.isArray(value)) {
return normalizeTextArray(value).join(';');
return normalizeTextArray(value);
}
return normalizeText(value);
const text = normalizeText(value);
if (text.length === 0) {
return [];
}
return text
.split(/[;;\n,]+/)
.map((item) => item.trim())
.filter((item) => item.length > 0);
}
function isRecord(value: unknown): value is Record<string, unknown> {
......@@ -350,7 +358,7 @@ function normalizeProfile(rawProfile: Record<string, unknown>): PrelearningProfi
family: normalizeText(rawProfile.family),
behavior: normalizeText(rawProfile.behavior),
objections: normalizeTextArray(rawProfile.objections),
needs: normalizeTextList(rawProfile.needs),
needs: normalizeTextSegments(rawProfile.needs),
includes: normalizeTextArray(rawProfile.includes),
};
}
......
......@@ -565,7 +565,7 @@ describe('prelearning route', () => {
family: '三口之家',
behavior: '谨慎比较',
objections: ['价格偏高'],
needs: '想要省心通勤;关注雨天行车安全',
needs: ['想要省心通勤', '关注雨天行车安全'],
},
gameSteps: [
{
......@@ -647,7 +647,7 @@ describe('prelearning route', () => {
family: '三口之家',
behavior: '谨慎比较',
objections: ['价格偏高'],
needs: '想要省心通勤',
needs: '想要省心通勤;关注雨天行车安全,希望服务省心',
includes: ['延保'],
},
gameSteps: [],
......@@ -678,6 +678,11 @@ describe('prelearning route', () => {
expect(response.statusCode).toBe(200);
expect(response.json().script.profile.name).toBe('李先生');
expect(response.json().script.profile.car).toBe('A6');
expect(response.json().script.profile.needs).toEqual([
'想要省心通勤',
'关注雨天行车安全',
'希望服务省心',
]);
await app.close();
});
......@@ -1235,7 +1240,7 @@ describe('prelearning route', () => {
name: '',
type: '',
objections: [],
needs: '',
needs: [],
},
gameSteps: [],
},
......@@ -1343,7 +1348,7 @@ describe('prelearning route', () => {
type: '家庭用户',
car: 'A6',
job: '公司职员',
needs: '想要省心通勤',
needs: ['想要省心通勤'],
includes: ['延保'],
},
},
......
......@@ -87,7 +87,7 @@ export interface PrelearningProfile {
family: string;
behavior: string;
objections: string[];
needs: string;
needs: string[];
includes: string[];
}
......
<!doctype html>
<html lang="zh-CN">
<html lang="zh-CN" class="sop-material-preview-page">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SOP 素材展示/预览</title>
</head>
<body class="bg-slate-50 text-slate-900">
<body class="sop-material-preview-page bg-slate-50 text-slate-900">
<div id="root"></div>
<script type="module" src="/src/apps/sop-material-preview/main.tsx"></script>
</body>
......
......@@ -101,8 +101,6 @@ export async function fetchPrelearningAction(
export async function fetchPrelearningBuriedPoint(
payload: PrelearningBuriedPointPayload,
): Promise<PrelearningBuriedPointResponse> {
console.log('[prelearning h5] buried point request payload:', payload);
const response = await fetch(backendApiPath('/api/prelearning/buried-point'), {
method: 'POST',
headers: {
......
......@@ -324,7 +324,7 @@ describe('PrelearningApp', () => {
family: '',
behavior: '',
objections: [],
needs: '',
needs: [],
};
responseBody.script.gameSteps = [];
mockSuccessfulFetch(responseBody);
......@@ -349,6 +349,33 @@ describe('PrelearningApp', () => {
expect(screen.queryByText('实战案例解析')).not.toBeInTheDocument();
});
it('renders profile needs as array items without splitting punctuation inside an item', async () => {
const responseBody = createMockPrelearningResponse(VALID_PAYLOAD);
responseBody.script.profile.needs = [
'需要系统界面简洁且符合操作直觉(如单行展示、自动截断)',
'确保财务与采购数据流转的准确性(如备注带入财务订单、规格关联成本)',
'满足管理层(张总)对特定功能模块(如6万元预算内的功能定制)的交付要求',
];
mockSuccessfulFetch(responseBody);
render(<PrelearningApp />);
await waitFor(() => {
expect(window.initPrelearningSession).toBeTypeOf('function');
});
await act(async () => {
window.initPrelearningSession?.(VALID_PAYLOAD);
});
const sidebarScroll = screen.getByTestId('prelearning-sidebar-scroll');
expect(within(sidebarScroll).getByText(responseBody.script.profile.needs[0])).toBeInTheDocument();
expect(within(sidebarScroll).getByText(responseBody.script.profile.needs[1])).toBeInTheDocument();
expect(within(sidebarScroll).getByText(responseBody.script.profile.needs[2])).toBeInTheDocument();
expect(within(sidebarScroll).queryByText('自动截断)')).not.toBeInTheDocument();
expect(within(sidebarScroll).queryByText('规格关联成本)')).not.toBeInTheDocument();
});
it('renders the page title in the app header slot without h5 navigation controls', async () => {
const responseBody = createMockPrelearningResponse(VALID_PAYLOAD);
mockSuccessfulFetch(responseBody);
......@@ -456,7 +483,7 @@ describe('PrelearningApp', () => {
name: '陈雨泽',
type: '雨季通勤',
objections: ['担心雨天视线', '想知道隔热效果'],
needs: '雨季通勤安全;希望隔热更舒服',
needs: ['雨季通勤安全', '希望隔热更舒服'],
};
mockInitAndActionFetch(initResponse, nextResponse);
......
......@@ -356,22 +356,9 @@ async function safeSendBuriedPoint(
payload: PrelearningBuriedPointPayload,
): Promise<void> {
try {
console.log('[prelearning h5] send buried point payload:', payload);
console.log('[prelearning h5] send buried point payload json:', JSON.stringify(payload));
window.__PRELEARNING_DEBUG_BURIED_POINT__?.(payload);
await fetchPrelearningBuriedPoint(payload);
} catch (error) {
console.warn('[prelearning h5] buried point failed:', payload, error);
console.warn('[prelearning h5] buried point failed json:', JSON.stringify({
payload,
error: error instanceof PrelearningRequestError
? {
code: error.code,
message: error.message,
details: error.details,
}
: String(error),
}));
} catch {
// 埋点失败不阻塞主流程,后端会负责记录失败或可重试线索。
}
}
......@@ -1116,9 +1103,8 @@ function ObjectionCard({ items }: { items: string[] }) {
);
}
function DemandCard({ text }: { text: string }) {
const pieces = text
.split(/[;;、]/)
function DemandCard({ items }: { items: string[] }) {
const pieces = items
.map((item) => item.trim())
.filter(Boolean);
......@@ -1393,7 +1379,6 @@ export function PrelearningApp() {
type: COMPLETE_ACTIVITY_MESSAGE_TYPE,
payload,
};
console.log('[prelearning h5] post completeActivity to app:', message);
const sent = postMessageToApp(message);
if (sent) {
......@@ -1657,7 +1642,6 @@ export function PrelearningApp() {
const previousInitializer = window.initPrelearningSession;
const previousBackIntercepted = window.onPrelearnBackIntercepted;
window.initPrelearningSession = (payload: PrelearningInitPayload) => {
console.log('[prelearning h5] received initPrelearningSession payload:', payload);
void runInitialization(payload, 'bridge', false);
};
window.onPrelearnBackIntercepted = () => {
......@@ -1711,7 +1695,6 @@ export function PrelearningApp() {
return;
}
console.log('[prelearning h5] received postMessage init payload:', payload);
void runInitialization(payload, 'bridge', false);
};
......@@ -1766,7 +1749,7 @@ export function PrelearningApp() {
<CustomerCard data={state.data} />
<ProductCard data={state.data} />
<ObjectionCard items={toArray(state.data.script.profile.objections)} />
<DemandCard text={state.data.script.profile.needs} />
<DemandCard items={state.data.script.profile.needs} />
</div>
</aside>
......
......@@ -81,8 +81,8 @@ export function createMockPrelearningResponse(payload: PrelearningInitPayload):
behavior: '重视品质与长期价值',
objections: ['价格有点高', '朋友推荐了其他品牌', '担心施工影响质保'],
needs: isPackage
? '刚提车需要整车保护;关注施工品质和售后质保;希望价格透明、服务省心'
: '想先了解商品效果',
? ['刚提车需要整车保护', '关注施工品质和售后质保', '希望价格透明、服务省心']
: ['想先了解商品效果'],
includes: ['延长保修', '施工质保'],
},
gameSteps: [
......
import { readFileSync } from 'node:fs';
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
......@@ -58,6 +60,20 @@ describe('SopMaterialPreviewApp', () => {
expect(document.querySelector('video')).toHaveAttribute('src', 'https://cdn.example.com/two.mp4');
});
it('scopes scrollbar hiding styles to the SOP material preview entry only', () => {
const html = readFileSync(`${process.cwd()}/sop-material-preview.html`, 'utf8');
const css = readFileSync(`${process.cwd()}/src/styles/index.css`, 'utf8');
expect(html).toContain('class="sop-material-preview-page"');
expect(css).toContain('html.sop-material-preview-page');
expect(css).toContain('body.sop-material-preview-page');
expect(css).toContain('scrollbar-width: none');
expect(css).toContain('-ms-overflow-style: none');
expect(css).toContain('::-webkit-scrollbar');
expect(css).not.toContain('html::-webkit-scrollbar');
expect(css).not.toContain('body::-webkit-scrollbar');
});
it('passes task tracking query parameters to the backend actionId request', async () => {
history.replaceState(
{},
......
......@@ -11,3 +11,16 @@ body,
body {
margin: 0;
}
html.sop-material-preview-page,
body.sop-material-preview-page {
-ms-overflow-style: none;
scrollbar-width: none;
}
html.sop-material-preview-page::-webkit-scrollbar,
body.sop-material-preview-page::-webkit-scrollbar {
display: none;
width: 0;
height: 0;
}
......@@ -24,7 +24,7 @@
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"types": ["vitest/globals", "@testing-library/jest-dom"]
"types": ["vitest/globals", "@testing-library/jest-dom", "node"]
},
"include": [
"src",
......
## Context
当前预学习长期 spec 明确写过“当 `script_json.profile.needs` 为字符串数组时,后端按中文分号拼接为字符串返回”。这使 `needs` 与同一画像对象里的 `objections` 在响应结构上不一致。用户反馈期望两者数据格式一致,且截图显示真实返回中 `objections` 已是数组,`needs` 是字符串。
## Decisions
1. `PrelearningProfile.needs` 调整为 `string[]`。
2. `objections` 继续保持 `string[]`,本 change 不改变其字段来源和展示语义。
3. 后端不再把数组型 `needs` 拼接为字符串;数组输入应按清洗后的数组直接返回。
4. 为避免历史数据中 `needs` 已被写成单字符串导致页面空白,后端对字符串输入做温和拆分,支持中文分号、英文分号、换行和逗号。
5. 前端 `DemandCard` 或等价组件接收数组并渲染需求项;若没有有效项,保持现有空态/不展示行为。
## Non-Goals
- 不调整 `script.profile.name/type/car/job/family/behavior/includes` 的字段来源。
- 不恢复旧字段 `demand`,也不新增兼容别名。
- 不改变页面布局、颜色、按钮、阅读门禁、学习动作、埋点或 APP bridge 行为。
- 不改变数据库表结构。
## Risks and Mitigations
- 风险:调用方若已按字符串读取 `profile.needs`,会受到契约变更影响。
- 缓解:前后端共享 contracts 同步更新,并用前后端回归测试覆盖初始化、动作响应和 mock。
- 风险:历史单字符串数据分隔符不统一。
- 缓解:后端字符串兼容拆分覆盖常见分隔符,未命中分隔符时作为单项数组返回。
## Validation
- 运行后端预学习路由测试,覆盖数组输入保持数组、字符串输入拆分为数组。
- 运行前端预学习测试,覆盖页面从 `needs: string[]` 渲染需求场景。
- 运行前后端类型检查。
- 运行 `openspec validate align-prelearning-needs-array --strict`。
## Why
预学习页面的客户画像中,`needs` 和 `objections` 都来自 `script_json.profile`,业务含义也都是多条标签类信息。但当前长期 spec、前后端 contracts 和后端归一化逻辑把 `objections` 返回为字符串数组,却把 `needs` 在数组输入时按中文分号拼接成字符串返回,导致接口响应结构不一致,也让 `prelearning.html` 调试和后续联调容易误判字段口径。
本 change 用于纠正预学习画像契约:`profile.needs` 应与 `profile.objections` 保持同类数据格式,统一返回字符串数组。
## What Changes
- 预学习初始化和学习动作返回的 `script.profile.needs` 从字符串调整为字符串数组。
- 后端解析 `script_json.profile.needs` 时:
- 若原始值为字符串数组,保留去空白后的非空项并按原顺序返回数组。
- 若原始值为字符串,按中文分号、英文分号、换行或逗号拆分为非空字符串数组,兼容历史单字符串数据。
- 若原始值缺失或无有效内容,返回空数组。
- 前后端共享契约、mock、页面展示和测试同步使用 `needs: string[]`。
- 页面展示需求场景时继续保持现有视觉语义,只从数组中渲染有效需求项,不恢复或读取旧 `demand` 字段。
## Capabilities
### Modified Capabilities
- `prelearning-script-view`: 调整客户画像 `needs` 的接口契约和渲染输入格式,使其与 `objections` 一致。
## Impact
- 后端:`workspace/single-pages/backend` 预学习渲染模型归一化与相关测试。
- 前端:`workspace/single-pages/front` contracts、mock、预学习页面需求展示和相关测试。
- OpenSpec:更新 `prelearning-script-view` 对 `script.profile.needs` 的长期契约。
## MODIFIED Requirements
### Requirement: 后端返回稳定的预学习剧本渲染模型
后端 MUST 按请求的活动商品/套餐查询 MySQL 数据,并返回稳定的 camelCase 预学习剧本前端渲染模型。
#### Scenario: profile 字段与脚本表和 script_json 保持一致
- **WHEN** 后端读取 `dj_prelearn_product_script` 和其中的 `script_json.profile`
- **THEN** `script.profile.name` MUST 使用 `dj_prelearn_product_script.customer_name`
- **AND** `script.profile.type` MUST 使用 `script_json.profile.type`
- **AND** `script.profile.car` MUST 使用 `dj_prelearn_product_script.car_model`
- **AND** `script.profile.job` MUST 使用 `script_json.profile.job`
- **AND** `script.profile.family` MUST 使用 `script_json.profile.family`
- **AND** `script.profile.behavior` MUST 使用 `script_json.profile.behavior`
- **AND** `script.profile.objections` MUST 使用 `script_json.profile.objections` 并返回字符串数组
- **AND** `script.profile.needs` MUST 使用 `script_json.profile.needs` 并返回字符串数组
- **AND** 当 `script_json.profile.needs` 为字符串数组时,后端 MUST 保留去空白后的非空项并按原顺序返回数组
- **AND** 当 `script_json.profile.needs` 为字符串时,后端 MUST 按中文分号、英文分号、换行或逗号拆分为去空白后的非空字符串数组;若没有可拆分分隔符但文本非空,则作为单项数组返回
- **AND** 当 `script_json.profile.needs` 缺失或没有有效文本时,后端 MUST 返回空数组
- **AND** 后端 MUST NOT 将 `script.profile.needs` 拼接为字符串返回
- **AND** 后端 MUST NOT 返回 `script.profile.customerName`、`profileType`、`carSeries`、`occupation` 或 `demand` 旧别名
- **AND** 后端 MUST NOT 使用 `script_json.profile.name` 或 `script_json.profile.car` 覆盖脚本表中的客户名称或车型
### Requirement: 预学习剧本内容可被渲染
预学习页面 MUST 使用后端渲染模型中的 `packageInfo`、`profile` 和 `gameSteps` 渲染当前剧本。
#### Scenario: 渲染剧本主要区块
- **WHEN** 初始化成功且后端返回剧本渲染模型
- **THEN** 页面渲染页面标题、客户信息、套餐/商品信息、客户异议、需求场景和阶段时间轴
- **AND** 页面 MUST 使用 `profile.objections` 数组展示客户异议
- **AND** 页面 MUST 使用 `profile.needs` 数组展示需求场景
- **AND** 页面 MUST NOT 读取或展示 `profile.demand` 旧字段
#### Scenario: 异议和需求标签为只读展示
- **WHEN** 页面渲染主要异议或需求场景挖掘标签
- **THEN** 标签长文本省略号 MUST 仅来自文本截断样式
- **AND** 页面 MUST NOT 为标签或省略号绑定点击、跳转、弹窗或菜单交互
- **AND** 用户双击标签或省略号时,页面 MUST NOT 因浏览器文本选择行为展开、选中或暴露完整隐藏文本
## 1. OpenSpec 与契约
- [x] 1.1 创建 OpenSpec change,明确 `profile.needs` 与 `profile.objections` 同为字符串数组。
- [x] 1.2 更新前后端共享 contracts,将 `PrelearningProfile.needs` 从 `string` 调整为 `string[]`。
- [x] 1.3 更新长期 `prelearning-script-view` spec,移除 `needs` 数组拼接为字符串的旧口径。
## 2. 后端实现
- [x] 2.1 调整预学习 profile 归一化逻辑,使数组型 `needs` 保持数组返回。
- [x] 2.2 兼容历史字符串型 `needs`,按中文分号、英文分号、换行或逗号拆分为字符串数组。
- [x] 2.3 更新后端回归测试,覆盖数组输入、字符串输入、空值输入和接口响应结构。
## 3. 前端实现
- [x] 3.1 更新预学习 mock,使 `profile.needs` 使用字符串数组。
- [x] 3.2 调整需求场景组件入参和渲染逻辑,从 `needs: string[]` 渲染有效需求项。
- [x] 3.3 更新前端回归测试,覆盖页面读取 `profile.needs` 数组并展示需求场景。
## 4. 验证
- [x] 4.1 运行 `rtk openspec validate align-prelearning-needs-array --strict`。
- [x] 4.2 运行后端预学习相关测试。
- [x] 4.3 运行前端预学习相关测试。
- [x] 4.4 运行前后端类型检查。
- [x] 4.5 运行相关文件 `rtk git diff --check`。
## Context
`sop-material-preview` 当前将模型中的 `bgColor` 应用于页面根背景。Windows 企业微信内置浏览器会显示原生垂直滚动条和滚动条槽位;当槽位透明或参与根背景绘制时,右侧会露出背景色,截图中表现为右边缘色条。
本次需求已确认范围为:只隐藏 `sop-material-preview` 的滚动条视觉,不调整背景色来源、素材宽度、接口字段或其它页面行为。
## Goals / Non-Goals
**Goals:**
- 仅在 `sop-material-preview` 入口隐藏浏览器原生滚动条视觉。
- 保留页面纵向滚动能力,保证长素材仍可查看。
- 使用页面专属选择器限制影响范围,避免全局影响其它单页应用。
**Non-Goals:**
- 不改变 `bgColor` 的数据来源和兜底规则。
- 不改变素材图片/视频宽度、间距、圆角或排序。
- 不改变后端 SOP 素材查询、埋点和 iframe `postMessage` 协议。
## Decisions
- 在 `sop-material-preview.html` 的 `html`/`body` 添加页面专属 class,通过 CSS 作用域选择器隐藏滚动条。
- 原因:滚动条属于文档滚动容器,入口 HTML 是最小且清晰的作用域边界;避免把 `::-webkit-scrollbar` 全局隐藏到其它页面。
- 备选方案:在 React 组件挂载时动态修改 `document.documentElement` class。该方案依赖运行时副作用,卸载清理也更复杂,不作为首选。
- CSS 同时覆盖 WebKit/Blink、旧 Edge/IE 和 Firefox 语法。
- 原因:企业微信 Windows 内置浏览器通常基于 Chromium/WebKit 风格滚动条;补充 `scrollbar-width` 和 `-ms-overflow-style` 可以让规则在更多宿主中保持稳定。
## Risks / Trade-offs
- [Risk] 隐藏滚动条会降低“当前可滚动”的视觉提示。
- Mitigation: 本页是沉浸式素材预览,用户确认只隐藏该页滚动条;滚动能力不被禁用。
- [Risk] 如果选择器过宽会影响其它页面。
- Mitigation: 使用 `sop-material-preview-page` 页面专属 class 作为所有滚动条规则前缀。
## Open Questions
- 无。
## Why
Windows 企业微信内置浏览器打开 `sop-material-preview` 时,右侧原生滚动条槽位会露出页面背景色,导致素材预览右边缘出现与内容无关的色条。用户已确认本次只隐藏 `sop-material-preview` 的滚动条,不影响其它单页应用。
## What Changes
- `sop-material-preview` 页面隐藏宿主浏览器原生滚动条的视觉展示。
- 页面仍 MUST 保留纵向滚动能力,长素材列表继续可滚动查看。
- 隐藏滚动条的样式 MUST 只作用于 `sop-material-preview` 入口,不得影响预学习页或其它单页应用。
- 不改变 SOP 素材模型、背景色字段、素材渲染、埋点或 iframe 预览协议。
## Capabilities
### New Capabilities
### Modified Capabilities
- `sop-material-preview-h5`: 补充 SOP 素材页滚动条视觉展示要求。
## Impact
- 前端入口:`front/sop-material-preview.html`
- 前端全局样式:`front/src/styles/index.css`
- OpenSpec:`openspec/specs/sop-material-preview-h5`
- 不影响后端接口、数据库、埋点写入或其它 H5 入口。
## ADDED Requirements
### Requirement: SOP 素材页必须隐藏浏览器滚动条视觉
系统 MUST 在 `sop-material-preview` 页面隐藏宿主浏览器原生滚动条的视觉展示,同时保留页面滚动能力。
#### Scenario: 长素材内容仍可滚动查看
- **WHEN** SOP 素材页渲染内容高度超过可视区域
- **THEN** 用户仍能通过鼠标滚轮、触控板或触屏手势纵向滚动页面
- **AND** 页面不展示宿主浏览器原生垂直滚动条
#### Scenario: 滚动条隐藏范围限定在 SOP 素材页
- **WHEN** 用户打开 `sop-material-preview` 以外的单页应用入口
- **THEN** 该入口不因本需求新增样式而隐藏浏览器原生滚动条
#### Scenario: 隐藏滚动条不改变素材渲染和背景规则
- **WHEN** SOP 素材页渲染模型或 iframe 预览 payload
- **THEN** 页面继续使用既有 `bgColor` 规则绘制背景
- **AND** 图片和视频继续按既有宽度、比例、间距和顺序渲染
## 1. 规格与实现
- [x] 1.1 在 `sop-material-preview` 入口添加页面专属 class,作为隐藏滚动条的作用域边界。
- [x] 1.2 在共享样式中用页面专属选择器隐藏 `sop-material-preview` 的浏览器原生滚动条,并保留滚动能力。
- [x] 1.3 确认其它单页入口未被新增滚动条样式影响。
## 2. 验证
- [x] 2.1 运行 `openspec validate hide-sop-material-preview-scrollbar --strict`。
- [x] 2.2 运行前端相关测试、类型检查或构建。
- [x] 2.3 通过自动化断言确认滚动条隐藏样式只作用于 `sop-material-preview` 入口;用户已在浏览器中完成验证并确认通过。
......@@ -187,3 +187,20 @@ TBD - created by archiving change add-sop-material-preview-h5. Update Purpose af
- **THEN** 页面不展示“等待预览数据”文案
- **AND** 页面展示空白内容
### Requirement: SOP 素材页必须隐藏浏览器滚动条视觉
系统 MUST 在 `sop-material-preview` 页面隐藏宿主浏览器原生滚动条的视觉展示,同时保留页面滚动能力。
#### Scenario: 长素材内容仍可滚动查看
- **WHEN** SOP 素材页渲染内容高度超过可视区域
- **THEN** 用户仍能通过鼠标滚轮、触控板或触屏手势纵向滚动页面
- **AND** 页面不展示宿主浏览器原生垂直滚动条
#### Scenario: 滚动条隐藏范围限定在 SOP 素材页
- **WHEN** 用户打开 `sop-material-preview` 以外的单页应用入口
- **THEN** 该入口不因本需求新增样式而隐藏浏览器原生滚动条
#### Scenario: 隐藏滚动条不改变素材渲染和背景规则
- **WHEN** SOP 素材页渲染模型或 iframe 预览 payload
- **THEN** 页面继续使用既有 `bgColor` 规则绘制背景
- **AND** 图片和视频继续按既有宽度、比例、间距和顺序渲染
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!