From 4b564c63165ada5a5fea91982ec9fe9caf7c225c Mon Sep 17 00:00:00 2001 From: zhengwr Date: Fri, 19 Jun 2026 20:28:32 +0800 Subject: [PATCH 01/24] test(e2e): executable AI-recipe render smoke gate (M-Gate) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 把「手动用浏览器验 AI 生成页渲染成 house-style」codify 成可复用的可执行门,补上 critic 点名「playwright-render 名实不符(从不真渲染)」的缺口——不给后端加浏览器依赖。 - e2e/recipe-render-smoke.spec.ts:给定 templateId,从 served schema 自推期望 (数据列 label + 所有按钮 label),再断言 amis 真渲染成无错 DOM:amis-host 可见 且无 schema-error-card / 每列每动作出现 / tbody 无裸 true·false·ISO 串 (列渲染类型生效)/ 0 console.error·pageerror。 - playwright.recipe-smoke.config.ts:复用已在跑的 5174,不自起 webServer。 - recipe-render-smoke.sh:一键端到端——登录→auto-develop 1 maintenance + 1 tree 样例→对两页跑断言→DROP 表+删三真相行清理(trap 保证失败也清,sys_ai_* 保留)。 验证:./recipe-render-smoke.sh 端到端全绿(maintenance + tree 两页均 PASSED, 0 console error),库残留复查 0。 Co-Authored-By: Claude Opus 4.8 (1M context) --- e2e/recipe-render-smoke.spec.ts | 169 ++++++++++++++++++++++++++++++ playwright.recipe-smoke.config.ts | 30 ++++++ recipe-render-smoke.sh | 66 ++++++++++++ 3 files changed, 265 insertions(+) create mode 100644 e2e/recipe-render-smoke.spec.ts create mode 100644 playwright.recipe-smoke.config.ts create mode 100755 recipe-render-smoke.sh diff --git a/e2e/recipe-render-smoke.spec.ts b/e2e/recipe-render-smoke.spec.ts new file mode 100644 index 0000000..ab206e6 --- /dev/null +++ b/e2e/recipe-render-smoke.spec.ts @@ -0,0 +1,169 @@ +/** + * AI recipe 渲染冒烟门(M-Gate 的可执行化)。 + * + * 把「手动用浏览器验 AI 生成页是否真渲染成 house-style」codify 成一条可复用断言: + * 给定一个 templateId,从【已生成并 served】的页面 schema 自推期望(列/动作),再断言 + * amis 真把它渲染成无错 DOM——补上 critic 点名「playwright-render 名实不符(从不真渲染)」的缺口。 + * + * 断言(schema 驱动,recipe 无关): + * ① amis-host 可见 且 无 schema-error-card → 渲染无致命错 + * ② body=crud,且 schema 每个数据列 label 出现在表头 → 列真渲染 + * ③ schema 里每个 {type:button} 的 label 出现在页面 → 工具栏/节点动作真渲染 + * ④ tbody 无裸 true/false、无裸 ISO 时间串 → 列渲染类型(是/否、日期格式)生效 + * ⑤ 0 pageerror + 0 console.error → 无运行时报错 + * + * 入参(env):RECIPE_SMOKE_TEMPLATE(必填,templateId)。 + * 前置:localhost:5174(前端 dev)+ localhost:8093(后端 dev)。页面须已 served。 + * 运行:RECIPE_SMOKE_TEMPLATE= npx playwright test --config=playwright.recipe-smoke.config.ts + */ +import { expect, test, type Page, type ConsoleMessage } from '@playwright/test'; +import * as http from 'node:http'; +import * as path from 'node:path'; +import * as fs from 'node:fs'; +import { fileURLToPath } from 'node:url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const TEMPLATE_ID = process.env.RECIPE_SMOKE_TEMPLATE ?? ''; +const ARTIFACT_DIR = path.join(__dirname, 'artifacts', 'recipe-render-smoke'); + +let _tokenCache: string | null = null; + +function getJson(reqPath: string, body?: string): Promise { + return new Promise((resolve, reject) => { + const req = http.request( + { + hostname: 'localhost', + port: 8093, + path: reqPath, + method: body ? 'POST' : 'GET', + headers: body + ? { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) } + : {}, + }, + (res) => { + let data = ''; + res.on('data', (c) => (data += c)); + res.on('end', () => { + try { + resolve(JSON.parse(data) as T); + } catch (e) { + reject(new Error(`非 JSON 响应 ${reqPath}: ${data.slice(0, 200)}`)); + } + }); + }, + ); + req.on('error', reject); + if (body) req.write(body); + req.end(); + }); +} + +async function getToken(): Promise { + if (_tokenCache) return _tokenCache; + const parsed = await getJson<{ success: boolean; token: string }>( + '/api/auth/login', + JSON.stringify({ account: 'admin', password: '111111' }), + ); + if (!parsed.success) throw new Error('登录失败'); + _tokenCache = parsed.token; + return parsed.token; +} + +async function seedAuth(page: Page) { + const token = await getToken(); + await page.addInitScript( + ({ t }: { t: string }) => { + localStorage.setItem('eip4_token', t); + localStorage.setItem( + 'eip4_profile', + JSON.stringify({ userId: 'ADMIN', account: 'admin', name: '系统管理员', roles: [] }), + ); + }, + { t: token }, + ); +} + +/** 递归收集 schema 中所有 {type:'button'} 节点的 label —— 工具栏 + 节点操作动作。 */ +function collectButtonLabels(node: unknown, out: Set): void { + if (Array.isArray(node)) { + node.forEach((n) => collectButtonLabels(n, out)); + return; + } + if (node && typeof node === 'object') { + const obj = node as Record; + if (obj.type === 'button' && typeof obj.label === 'string' && obj.label.trim()) { + out.add(obj.label.trim()); + } + Object.values(obj).forEach((v) => collectButtonLabels(v, out)); + } +} + +test.beforeAll(() => { + fs.mkdirSync(ARTIFACT_DIR, { recursive: true }); + if (!TEMPLATE_ID) throw new Error('缺 env RECIPE_SMOKE_TEMPLATE'); +}); + +test(`AI recipe 页 ${TEMPLATE_ID} 渲染成无错 house-style DOM`, async ({ page }) => { + // 0 console.error / pageerror 收集(house-style 页应零报错)。 + const consoleErrors: string[] = []; + page.on('console', (m: ConsoleMessage) => { + if (m.type() === 'error') consoleErrors.push(m.text()); + }); + page.on('pageerror', (e) => consoleErrors.push(`pageerror: ${e.message}`)); + + // 自推期望:从 served schema 拿数据列 label 与所有按钮 label。 + const schema = await getJson<{ + body?: { type?: string; columns?: Array<{ name?: string; label?: string; type?: string }> }; + }>(`/api/page/schema/${TEMPLATE_ID}`); + expect(schema.body?.type, 'body.type 应为 crud').toBe('crud'); + const dataColumnLabels = (schema.body?.columns ?? []) + .filter((c) => c.name && c.label && c.type !== 'operation') + .map((c) => c.label!) as string[]; + const buttonLabels = new Set(); + collectButtonLabels(schema, buttonLabels); + + await seedAuth(page); + await page.goto(`/page/${TEMPLATE_ID}`); + + // ① 渲染完成且无致命错卡。 + await expect(page.locator('[data-testid="amis-host"]')).toBeVisible({ timeout: 45_000 }); + await expect(page.locator('[data-testid="schema-error-card"]')).not.toBeVisible(); + await page + .waitForSelector( + '[data-testid="amis-host"] table, [data-testid="amis-host"] .cxd-CRUD', + { timeout: 20_000 }, + ) + .catch(() => {/* 空表也算渲染成功,继续 */}); + + await page.screenshot({ + path: path.join(ARTIFACT_DIR, `${TEMPLATE_ID}-full.png`), + fullPage: true, + }); + + const bodyText = (await page.textContent('body')) ?? ''; + + // ② 每个数据列 label 出现在页面(表头)。 + for (const label of dataColumnLabels) { + expect(bodyText, `列「${label}」应渲染`).toContain(label); + } + + // ③ 每个按钮 label 出现在页面(工具栏/节点动作真渲染)。 + for (const label of Array.from(buttonLabels)) { + expect(bodyText, `动作「${label}」应渲染`).toContain(label); + } + + // ④ 列渲染类型生效:表体无裸 true/false、无裸 ISO 时间串。 + const tbodyText = await page + .evaluate(() => document.querySelector('tbody')?.textContent ?? '') + .catch(() => ''); + if (tbodyText.trim()) { + expect(tbodyText, '布尔列应渲染为 是/否,而非裸 true').not.toMatch(/\btrue\b/); + expect(tbodyText, '布尔列应渲染为 是/否,而非裸 false').not.toMatch(/\bfalse\b/); + expect(tbodyText, '日期列应格式化,而非裸 ISO 串').not.toMatch(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/); + } + + // ⑤ 0 console.error / pageerror。 + expect(consoleErrors, `控制台报错:\n${consoleErrors.join('\n')}`).toHaveLength(0); +}); diff --git a/playwright.recipe-smoke.config.ts b/playwright.recipe-smoke.config.ts new file mode 100644 index 0000000..5351a06 --- /dev/null +++ b/playwright.recipe-smoke.config.ts @@ -0,0 +1,30 @@ +import { defineConfig, devices } from '@playwright/test'; + +// ──────────────────────────────────────────────────────────────────────────── +// AI recipe 渲染冒烟门专属配置(M-Gate 可执行化)。 +// +// 与默认 playwright.config.ts 的区别(关键): +// - 复用【已在跑】的 5174 dev server,不自拉 webServer(不重启任何服务)。 +// - 仅匹配 recipe-render-smoke.spec.ts。 +// +// 一键跑(含生成/清理):见 recipe-render-smoke.sh +// 单跑某页:RECIPE_SMOKE_TEMPLATE= npx playwright test --config=playwright.recipe-smoke.config.ts +// 前置:localhost:5174(前端 dev)+ localhost:8093(后端 dev/eip4dev)。 +// ──────────────────────────────────────────────────────────────────────────── +export default defineConfig({ + testDir: './e2e', + testMatch: /recipe-render-smoke\.spec\.ts/, + fullyParallel: false, + workers: 1, + timeout: 90_000, + reporter: [['list']], + outputDir: './e2e/artifacts/recipe-render-smoke/_pw-output', + use: { + baseURL: 'http://localhost:5174', + trace: 'retain-on-failure', + screenshot: 'only-on-failure', + video: 'off', + }, + projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }], + // 故意不配置 webServer —— 复用已在跑的 5174,不重启。 +}); diff --git a/recipe-render-smoke.sh b/recipe-render-smoke.sh new file mode 100755 index 0000000..1d3a1d7 --- /dev/null +++ b/recipe-render-smoke.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash +# ───────────────────────────────────────────────────────────────────────────── +# AI recipe 渲染冒烟门 —— 一键端到端(M-Gate 可执行化)。 +# +# 把「手动用浏览器验 AI 生成页渲染成 house-style」codify 成一条命令: +# 1) 登录拿 admin token +# 2) 经 AI pipeline 生成 1 个 maintenance + 1 个 tree 隔离样例(auto-develop) +# 3) 用 recipe-render-smoke.spec 断言两页真渲染成无错 house-style DOM +# 4) DROP 表 + 删三真相行清理(trap 保证失败也清,sys_ai_* 审计保留) +# +# 前置:localhost:8093(后端 dev/eip4dev)+ localhost:5174(前端 dev)+ psql:5433。 +# 跑: cd eip4-web && ./recipe-render-smoke.sh +# ───────────────────────────────────────────────────────────────────────────── +set -uo pipefail + +BACKEND="${BACKEND:-http://localhost:8093}" +PGHOST="${PGHOST:-localhost}"; PGPORT="${PGPORT:-5433}"; PGUSER="${PGUSER:-zhengwr}"; PGDB="${PGDB:-eip4dev}" +export PGPASSWORD="${PGPASSWORD:-}" +SMOKE_TABLES=(EIP4AI_SMOKE_M EIP4AI_SMOKE_T) + +psql_run() { psql -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d "$PGDB" -v ON_ERROR_STOP=1 -At "$@"; } + +cleanup() { + for t in "${SMOKE_TABLES[@]}"; do + local tpl tbl + tpl="$(echo "$t" | tr 'A-Z_' 'a-z-')" # EIP4AI_SMOKE_M → eip4ai-smoke-m (templateId) + tbl="$(echo "$t" | tr 'A-Z' 'a-z')" # EIP4AI_SMOKE_M → eip4ai_smoke_m (物理表,PG 折叠小写) + psql_run -c "DROP TABLE IF EXISTS eip3.${tbl}; + DELETE FROM eip3.sys_entity WHERE upper(tablename)='${t}'; + DELETE FROM eip3.sys_page_schema WHERE template_id='${tpl}'; + DELETE FROM eip3.sys_serviceflow WHERE upper(sys_serviceflow_id) LIKE '${t}\\_%'; + DELETE FROM eip3.sys_menu WHERE view_templateid='${tpl}';" >/dev/null 2>&1 + done + echo "🧹 清理完成(${SMOKE_TABLES[*]})" +} +trap cleanup EXIT + +login() { + curl -s -X POST "$BACKEND/api/auth/login" -H 'Content-Type: application/json' \ + -d '{"account":"admin","password":"111111"}' \ + | python3 -c "import sys,json;print(json.load(sys.stdin).get('token',''))" +} + +# auto_dev +auto_dev() { + local table="$1" tpl="$2" name="$3" recipe="$4" + curl -s -X POST "$BACKEND/api/ai/features/auto-develop" \ + -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \ + -d "{\"feature\":{\"objective\":\"render-smoke\",\"featureName\":\"${name}维护\",\"tableName\":\"${table}\",\"entityName\":\"${name}\",\"templateId\":\"${tpl}\",\"menuName\":\"${name}\",\"fields\":[{\"column\":\"NAME\",\"label\":\"名称\",\"type\":\"string\",\"length\":100,\"required\":true},{\"column\":\"ENABLED\",\"label\":\"启用\",\"type\":\"boolean\",\"required\":false}],\"pageRecipe\":\"${recipe}\"},\"baseUrl\":\"${BACKEND}\",\"generateDeploymentPackage\":true,\"maxRepairAttempts\":2}" \ + | python3 -c "import sys,json;d=json.load(sys.stdin);print((d.get('applyRun') or {}).get('status','?'))" +} + +echo "🔑 登录…"; TOKEN="$(login)" +[ -n "$TOKEN" ] || { echo "❌ 登录失败"; exit 1; } + +echo "🏗 生成 maintenance 样例…"; [ "$(auto_dev EIP4AI_SMOKE_M eip4ai-smoke-m 列渲染样例 maintenance-crud-v1)" = "PASSED" ] || { echo "❌ maintenance apply 未 PASSED"; exit 1; } +echo "🌲 生成 tree 样例…"; [ "$(auto_dev EIP4AI_SMOKE_T eip4ai-smoke-t 树样例 tree-crud-v1)" = "PASSED" ] || { echo "❌ tree apply 未 PASSED"; exit 1; } + +rc=0 +for tpl in eip4ai-smoke-m eip4ai-smoke-t; do + echo "🖥 渲染断言 $tpl …" + RECIPE_SMOKE_TEMPLATE="$tpl" npx playwright test --config=playwright.recipe-smoke.config.ts || rc=1 +done + +[ "$rc" = 0 ] && echo "✅ recipe 渲染冒烟全绿" || echo "❌ recipe 渲染冒烟有失败" +exit "$rc" From 2278cbce4b0fe3841dc058efcecd8d9d9fbe52be Mon Sep 17 00:00:00 2001 From: zhengwr Date: Fri, 19 Jun 2026 22:05:16 +0800 Subject: [PATCH 02/24] fix(designer): remove StrictMode so amis-editor mounts (was blank screen) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 页面设计器(editor.html)整片空白:amis-editor 用 mobx-state-tree 维护 EditorRoot store,而 src/editor/main.tsx 用 包裹——dev 下 StrictMode 故意 mount→unmount→remount,销毁第一个 EditorRoot,其 pending 异步(markReady/ calculateHighlightBox)随后打到已死实例 → 抛「[mobx-state-tree] object no longer part of a state tree」→ 编辑器不渲染。 移除编辑器入口的 StrictMode(主应用 main.tsx 跑 amis SDK 运行时渲染器、容忍 StrictMode,不动)。实测:三栏(组件库/画布/属性面板)+画布真渲业务页全部恢复, mobx-state-tree 报错消失(剩 Monaco worker/React 弃用警告均良性、不阻塞)。 Co-Authored-By: Claude Opus 4.8 (1M context) --- src/editor/main.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/editor/main.tsx b/src/editor/main.tsx index 497c99f..2681bb5 100644 --- a/src/editor/main.tsx +++ b/src/editor/main.tsx @@ -1,14 +1,15 @@ // F4-L1 设计器独立入口(editor.html 多页应用) // 与主应用 React 实例完全隔离,amis 用 npm 包版,不依赖 sdk-local -import React from 'react'; +// +// ⚠️ 不能包 :amis-editor 用 mobx-state-tree 维护 EditorRoot store, +// StrictMode 在 dev 下故意 mount→unmount→remount,会销毁第一个 EditorRoot,而其 pending +// 异步(markReady / calculateHighlightBox)随后打到已死实例 → 抛 +// 「[mobx-state-tree] object no longer part of a state tree」→ 编辑器整片空白。 +// 主应用 main.tsx 跑 amis SDK(运行时渲染器,容忍 StrictMode),唯独 amis-editor 不行。 import { createRoot } from 'react-dom/client'; import { DesignerPage } from './DesignerPage'; const root = document.getElementById('editor-root'); if (root) { - createRoot(root).render( - - - , - ); + createRoot(root).render(); } From 8603d0f8d8b88c4e4c13a9cfd66e8da5568a0455 Mon Sep 17 00:00:00 2001 From: zhengwr Date: Fri, 19 Jun 2026 22:05:16 +0800 Subject: [PATCH 03/24] fix(web): make scrollbars visible (were 6px transparent, looked absent) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户反馈「整个页面没有滚动条、没办法往下滚动」。根因:theme.css 滚动条 6px + 透明轨道 + 浅灰 thumb,在 macOS overlay 滚动条下近乎隐形,长页面(如设计中心 812 页 10209px)能滚但看不到条、误以为滚不动。 改:10px 宽 + 浅底轨道(--surface-2) + 可见 thumb(--line-strong,padding-box 描边) + hover 加深;`* { scrollbar-width:thin; scrollbar-color }` 兼容 Firefox。 全局生效(壳层 + amis 区域)。 Co-Authored-By: Claude Opus 4.8 (1M context) --- src/shell/theme.css | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/shell/theme.css b/src/shell/theme.css index 607a764..f2e7ca2 100644 --- a/src/shell/theme.css +++ b/src/shell/theme.css @@ -136,10 +136,17 @@ body { margin: 0; } -/* 滚动条 */ -::-webkit-scrollbar { width: 6px; height: 6px; } -::-webkit-scrollbar-track { background: transparent; } -::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; } +/* 滚动条 —— 做成清晰可见(原 6px 透明轨道+浅灰 thumb 在 macOS overlay 下近乎隐形, + 用户误以为「没有滚动条/滚不动」)。10px 宽 + 浅底轨道 + 可见 thumb + hover 加深; + Firefox 用 scrollbar-* 同口径。 */ +* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; } +::-webkit-scrollbar { width: 10px; height: 10px; } +::-webkit-scrollbar-track { background: var(--surface-2); } +::-webkit-scrollbar-thumb { + background: var(--line-strong); border-radius: 6px; + border: 2px solid var(--surface-2); background-clip: padding-box; +} +::-webkit-scrollbar-thumb:hover { background: var(--text-3); } /* ============================================================================ 通用工具类(全局可用) From 3abeefebacf51a89020ba925e9f097cc2c0ec23a Mon Sep 17 00:00:00 2001 From: zhengwr Date: Fri, 19 Jun 2026 22:22:27 +0800 Subject: [PATCH 04/24] fix(designer): constrain amis-editor height so canvas scrolls (was clipped) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 设计器「整个页面没有滚动条、看不到底部」真因:amis-editor 自带 CSS 未把 .ae-Editor 约束到容器高度,它按内容自然撑高(新闻管理页达 ~2804px),超出被 DesignerPage 外层 wrapper(flex:1;overflow:hidden) 裁掉、底部够不到。 (此前 theme.css 滚动条改动只作用主应用,editor.html 隔离入口未受影响 → 用户 反馈「没修」。) 修:editor.html From f39661a5ddfaa57fe004541866413fb954a0abf6 Mon Sep 17 00:00:00 2001 From: zhengwr Date: Fri, 19 Jun 2026 22:34:23 +0800 Subject: [PATCH 05/24] =?UTF-8?q?fix(shell):=20open=20=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=20as=20its=20own=20tab=20instead=20of=20cove?= =?UTF-8?q?ring=20current?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 顶栏「设计中心」画笔按钮 navigate('/design-center'),但 AppShell 地址同步 useEffect 只为 /page/:id 路由自动建 Tab → /design-center 既不在 tabs、又非 /page/ 开头,两个分支都不命中:不建 Tab、activeKey 不变 → Outlet 渲染设计中心 内容但 Tab 条仍高亮旧页,设计中心「盖」在当前选中 Tab 上(用户反馈)。 修:新增 SINGLETON_TAB_TITLES 映射(/design-center→设计中心),地址同步 useEffect 对这类单例功能路由也自动建并激活独立 Tab(任意入口生效:顶栏/直接URL/前进后退; prev.some 去重)。实测:从工作台点画笔 → Tab 条新增「设计中心」并激活,原 新闻收藏 Tab 保留不被覆盖,localStorage tabs/activeKey 同步。 Co-Authored-By: Claude Opus 4.8 (1M context) --- src/shell/AppShell.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/shell/AppShell.tsx b/src/shell/AppShell.tsx index a2a42fa..d71ee84 100644 --- a/src/shell/AppShell.tsx +++ b/src/shell/AppShell.tsx @@ -44,6 +44,12 @@ const TODO_POLL_INTERVAL = 60_000; // 初始 Tab:「工作台」作为保底 Tab,不可关闭 const TODO_TAB: Tab = { key: '/workbench', title: '工作台' }; +// 非 /page/:id 的单例功能路由 → Tab 标题。navigate 到这些路由时自动开成独立 Tab, +// 避免「盖」在当前选中 Tab 上(见下方地址同步 useEffect)。 +const SINGLETON_TAB_TITLES: Record = { + '/design-center': '设计中心', +}; + function loadTabs(): Tab[] { try { const raw = localStorage.getItem(TABS_KEY); @@ -105,6 +111,18 @@ export function AppShell() { return [...prev, { key: path, title: templateId }]; }); setActiveKey(path); + } else { + // 非 /page/ 的单例功能路由(如顶栏「设计中心」入口):也自动开成独立 Tab, + // 否则 navigate() 只换 Outlet 内容、不建 Tab → 设计中心「盖」在当前选中 Tab 上、 + // Tab 条仍高亮旧页(用户反馈「覆盖当前选中 tab」)。 + const title = SINGLETON_TAB_TITLES[path]; + if (title) { + setTabs((prev) => { + if (prev.some((t) => t.key === path)) return prev; + return [...prev, { key: path, title }]; + }); + setActiveKey(path); + } } }, [location.pathname, tabs]); From 37298186eb2ae95cfbcd7b6f25213521b5d8f4e7 Mon Sep 17 00:00:00 2001 From: zhengwr Date: Fri, 19 Jun 2026 22:54:46 +0800 Subject: [PATCH 06/24] chore(build): add preview proxy for local production-build verification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 验证「设计器生产构建是否裂」时需要本地托管 dist 并能访问后端。`vite preview` 默认不带 /api 反代,补 preview.proxy(与 server.proxy 同口径,走 .env.local 的 VITE_BACKEND_TARGET)→ 可本地跑 `npm run preview` 验证 prod 构建。 结论(实测):生产构建本就安全——editor.html 源里 3 个 /node_modules CSS 直链在 vite build 时被解析+打包进 dist/assets/editor-*.css(2.3MB,含完整 amis-editor/ amis-ui 样式,1742×.ae- / 12155×.cxd-),dist/editor.html 零 /node_modules 残留; preview 托管 dist 实测编辑器三栏完整带样式渲染(panelCount 123)、高度约束修复 生效(aeEditor 831px/clippedLayers 0)、schema 经 proxy 加载。memory「生产可能裂」 顾虑证伪。 Co-Authored-By: Claude Opus 4.8 (1M context) --- vite.config.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vite.config.ts b/vite.config.ts index 3d2a1eb..8870c98 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -38,6 +38,16 @@ export default defineConfig(({ mode }) => { allow: ['..'], }, }, + // `npm run preview` 托管 dist 产物时也把 /api 反代到后端,便于本地验证生产构建 + // (生产真部署由 Nginx 反代 /api;此处仅本地 prod-build 验证用,与 server.proxy 同口径)。 + preview: { + proxy: { + '/api': { + target: backendTarget, + changeOrigin: true, + }, + }, + }, build: { // 产物直接交 Nginx 托管;amis 本地 SDK 在 public/ 下原样拷贝,不参与打包。 outDir: 'dist', From 690f4c755e6f45f6fff68e00c13f9c6593ae3c15 Mon Sep 17 00:00:00 2001 From: zhengwr Date: Sat, 20 Jun 2026 09:31:18 +0800 Subject: [PATCH 07/24] =?UTF-8?q?fix(web):=20dev=20=E5=8F=8D=E4=BB=A3?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E7=9B=AE=E6=A0=87=208084=E2=86=928093?= =?UTF-8?q?=EF=BC=8Cfresh=20checkout=20=E5=BC=80=E7=AE=B1=E5=8D=B3?= =?UTF-8?q?=E9=80=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit .env.local(8093) 被 gitignore 排除,新克隆退回 .env/vite.config 的 8084(local profile)死口。 统一提交进库的默认值为 8093(dev profile),无需手建 .env.local 即可联调。 Co-Authored-By: Claude Opus 4.8 (1M context) --- .env | 5 +++-- vite.config.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.env b/.env index 6891bfd..0bc4185 100644 --- a/.env +++ b/.env @@ -1,2 +1,3 @@ -# 后端反代目标。后端默认 8084(local profile);若 8084 被占改为 8090,此处同步改。 -VITE_BACKEND_TARGET=http://localhost:8084 +# 后端反代目标。dev profile 默认 8093(本机联调跑这个口)。 +# 若端口冲突,复制本文件为 .env.local 并改 VITE_BACKEND_TARGET(.env.local 已 gitignore,不入库)。 +VITE_BACKEND_TARGET=http://localhost:8093 diff --git a/vite.config.ts b/vite.config.ts index 8870c98..05618f4 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,7 +2,7 @@ import { defineConfig, loadEnv } from 'vite'; import react from '@vitejs/plugin-react'; import { resolve } from 'path'; -// 开发期 dev server 把 /api 反代到后端(默认 8084,端口被占时改 8090)。 +// 开发期 dev server 把 /api 反代到后端(dev profile 默认 8093,端口被占时用 .env.local 覆盖)。 // 后端地址经 .env 的 VITE_BACKEND_TARGET 配置;生产由 Nginx 反代,前端只发相对 /api。 // // F4-L1 多页应用(MPA): @@ -16,7 +16,7 @@ import { resolve } from 'path'; // CSS 由 editor.html 直接引用 /node_modules/... 路径,server.fs.allow 放开目录。 export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), ''); - const backendTarget = env.VITE_BACKEND_TARGET || 'http://localhost:8084'; + const backendTarget = env.VITE_BACKEND_TARGET || 'http://localhost:8093'; return { plugins: [react()], resolve: { From ae0155eb2cbabc242a462c8bdd49ca39eb48ef19 Mon Sep 17 00:00:00 2001 From: zhengwr Date: Sat, 20 Jun 2026 09:33:34 +0800 Subject: [PATCH 08/24] =?UTF-8?q?fix(web):=20editor.html=20CSS=20=E6=94=B9?= =?UTF-8?q?=20import=20=E8=BF=9B=20bundle=EF=BC=8C=E4=BF=AE=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E6=9E=84=E5=BB=BA=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit editor.html 三条 /node_modules/*.css 绝对 link 在 vite build 后不入 dist, preview/静态托管下 404 → 设计器裸样式。改由 src/editor/main.tsx import, rollup 收集进 dist/assets/*.css。dev 不受影响(vite 转译同源)。 注:amis-ui/amis-editor-core 的 exports 字段不暴露 css 子路径,裸包名 import 被 rollup 拒绝, 故用相对 node_modules 路径直引真实 css 文件。 REQUIRED-before-any-hosted-demo, OPTIONAL-for-pure-dev。 Co-Authored-By: Claude Opus 4.8 (1M context) --- editor.html | 5 +---- src/editor/main.tsx | 10 ++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/editor.html b/editor.html index ef99b7a..e08a2ff 100644 --- a/editor.html +++ b/editor.html @@ -5,10 +5,7 @@ EIP4 页面设计器 - - - - +