From e4715cf967aed27cefde672c28597183805ee5a6 Mon Sep 17 00:00:00 2001 From: "mula.liu" Date: Sun, 1 Nov 2026 19:38:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20React=20=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E9=81=97=E7=95=99=EF=BC=9A=E5=88=86=E9=95=9C=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E5=99=A8=E6=94=B9=E6=96=87=E6=A1=88=E7=94=A8=20ref=20=E5=8F=96?= =?UTF-8?q?=E4=BB=A3=E5=A4=B1=E6=95=88=E7=9A=84=20.sb-insp=20=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=99=A8=E3=80=81=E5=8F=97=E6=8E=A7=E5=8B=BE=E9=80=89?= =?UTF-8?q?=E6=A1=86=E8=A1=A5=20onChange=20=E6=B6=88=E9=99=A4=E5=8F=AA?= =?UTF-8?q?=E8=AF=BB=E5=91=8A=E8=AD=A6=E3=80=81seed=20=E5=9B=9E=E8=90=BD?= =?UTF-8?q?=E7=A9=BA=E4=B8=B2=E4=BF=9D=E6=8C=81=E5=8F=97=E6=8E=A7=E3=80=81?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=94=A8=E6=88=B7=E5=90=8D=E8=A1=A5=E5=9B=9E?= =?UTF-8?q?=20#login-user=EF=BC=9B=E5=90=8C=E6=AD=A5=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E8=AE=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/工程规范.md | 4 ++-- frontend/src/pages/AssetLibrary.tsx | 9 ++++++--- frontend/src/pages/Login.tsx | 2 +- frontend/src/pages/project/Library.tsx | 7 +++++-- frontend/src/pages/project/Storyboard.tsx | 23 ++++++++++++++++------- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/docs/工程规范.md b/docs/工程规范.md index 3b4fd93..23aaa55 100644 --- a/docs/工程规范.md +++ b/docs/工程规范.md @@ -86,7 +86,7 @@ api/ → app/ → pages/ → components/{ui,forms,media}/ → hooks/ · ## 3. 测试规范 -- **归属**:自动化用例一律放 `backend/tests/`(当前 43 个文件、487 条)。 +- **归属**:自动化用例一律放 `backend/tests/`(当前 43 个文件、495 条)。 新增能力必须同时带用例;修 bug 必须先写能复现的用例,再改代码。 - **两类测试分工明确**: - `backend/tests/`(pytest + TestClient,进程内):契约、状态机、边界值, @@ -215,7 +215,7 @@ sudo ./scripts/server.sh systemd > /etc/systemd/system/nex-animation.service # 按顺序,任一步不过就不要提交: ```bash -cd backend && ../.venv/bin/python -m pytest -q # 487 passed, 1 skipped(约 3 分钟) +cd backend && ../.venv/bin/python -m pytest -q # 494 passed, 1 skipped(约 3 分钟) bash -n scripts/*.sh # 改过脚本就必须过,shell 没有编译器兜底 # 改过 .gitignore:跑 ./scripts/deploy.sh --check,第 3 条不变量会验它没吃掉代码 cd frontend && npm run build # 前端类型与打包 diff --git a/frontend/src/pages/AssetLibrary.tsx b/frontend/src/pages/AssetLibrary.tsx index 335dced..c1b98da 100644 --- a/frontend/src/pages/AssetLibrary.tsx +++ b/frontend/src/pages/AssetLibrary.tsx @@ -1190,7 +1190,8 @@ export default function AssetLibrary() { selectedMedia.has(media.id) && 'border-accent-line shadow-[0_0_0_1px_var(--c-accent-tint)]')}> @@ -1238,7 +1239,8 @@ export default function AssetLibrary() { @@ -1316,7 +1318,8 @@ export default function AssetLibrary() {
diff --git a/frontend/src/pages/Login.tsx b/frontend/src/pages/Login.tsx index 01b39e7..69712e2 100644 --- a/frontend/src/pages/Login.tsx +++ b/frontend/src/pages/Login.tsx @@ -85,7 +85,7 @@ export default function Login() { diff --git a/frontend/src/pages/project/Library.tsx b/frontend/src/pages/project/Library.tsx index a7f41d9..f44537d 100644 --- a/frontend/src/pages/project/Library.tsx +++ b/frontend/src/pages/project/Library.tsx @@ -1344,13 +1344,16 @@ const PICKED = 'border-l-2 border-l-accent-line -ml-[12px] pl-[10px] rounded-[6p * 卡片 / 表格行首的裸勾选框(.lib-pick)。 * * 不放可见文字,选的是谁由 aria-label 说明;Shift 连选读的是原生事件的 - * shiftKey,所以事件原样传给上层的 togglePick,别在这里换算成布尔值。 + * shiftKey,所以把 onChange 的 nativeEvent 原样交给上层的 togglePick, + * 别在这里换算成布尔值。(受控 checkbox 必须挂 onChange,只写 onClick 会被 + * React 当成只读字段,每个渲染周期往控制台刷一条 error。) */ function PickBox({ checked, label, className, onToggle }: { checked: boolean; label: string; className?: string; onToggle: (ev?: { shiftKey?: boolean }) => void }) { return ( - onToggle(e)} + onToggle(e.nativeEvent as MouseEvent)} className={cn('flex-none w-[14px] h-[14px] m-0 accent-accent cursor-pointer', className)} /> ) } diff --git a/frontend/src/pages/project/Storyboard.tsx b/frontend/src/pages/project/Storyboard.tsx index 22212c4..01f0b9d 100644 --- a/frontend/src/pages/project/Storyboard.tsx +++ b/frontend/src/pages/project/Storyboard.tsx @@ -549,7 +549,9 @@ export default function Storyboard() { const value = (full as any)[key] if (value !== undefined && value !== null) (next as any)[key] = value } - next.seed = full.seed ?? null + // seed 必须回落到空串而不是 null:`` 会让 React 报警, + // 并把输入框切成非受控(下一镜会带着上一镜留在 DOM 里的值);保存时 intOrNull('') 同样得到 null。 + next.seed = full.seed ?? '' next.lines = normalizeLines(full) next.ambience = full.ambience || '' next.sound_effects = (Array.isArray(full.sound_effects) ? full.sound_effects : []) @@ -578,11 +580,18 @@ export default function Storyboard() { if (row) await select(row.id) } + /* 检查器本体与「画面描述」的 DOM 句柄。旧站靠 document.querySelector('.sb-insp') + 跨组件摸元素,类名换成工具类之后那个钩子就不存在了——「✎ 改文案」点了不聚焦, + 属于静默失效(querySelector 返回 null 谁都不报错)。ref 挂在节点上, + 与样式类名彻底脱钩,改皮肤不会再弄丢行为。 */ + const inspRef = useRef(null) + const descRef = useRef(null) + /** 窄屏时检查器堆在看板上方,选中镜头后把它滚进视野,避免"点了没反应"的错觉 */ function scrollToInspector() { if (!window.matchMedia('(max-width: 1080px)').matches) return requestAnimationFrame(() => { - document.querySelector('.sb-insp')?.scrollIntoView({ behavior: 'smooth', block: 'start' }) + inspRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' }) }) } @@ -974,9 +983,9 @@ export default function Storyboard() { setInspectorTab('shot') if (live.current.selectedId !== shot.id) await select(shot.id, false) /* 四个页签的内容全都保持挂载、只用 hidden 收起来(见检查器注释), - 所以这里才 querySelector 得到;再等两帧让 hidden 真正摘掉,量出来的位置才对。 */ + 所以 ref 一直挂在节点上;再等两帧让 hidden 真正摘掉,量出来的位置才对。 */ await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve()))) - const el = document.querySelector('.sb-insp textarea[data-field="description"]') + const el = descRef.current if (!el) return el.scrollIntoView({ behavior: 'smooth', block: 'center' }) el.focus({ preventScroll: true }) @@ -1395,7 +1404,7 @@ export default function Storyboard() { )} - {/* ===== 检查器(.sb-insp)===== + {/* ===== 检查器(inspRef)===== 它不是 Drawer:Drawer 是模态(Esc 关闭 + 锁滚动 + 遮罩吞点击), 而改分镜要「左边挑镜头、右边改文案」来回看,遮罩会把看板挡死。 这里保留抽屉的皮肤(同一套 head/body/actions 类名),自己管开合。 */} @@ -1408,7 +1417,7 @@ export default function Storyboard() { /* 1400 / 1080 / 720 这三档没有命名断点(huge=1440 / mid=1180 / mid2=1100 / nav=900), 只能写任意值变体:检查器要同时放下「提示词 + 参考图 + 参数」两列, 按 1180 回落会在 1200px 屏上就把字段挤成一列,编辑区被表单撑爆。 */ -