From fdd591a9cf02ac2bb43586bd23e7240ca5df7e32 Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 2 Jul 2026 12:20:13 +0800 Subject: [PATCH] =?UTF-8?q?P1-5=20=E4=BF=AE=E5=A4=8D:=20datascreen=20?= =?UTF-8?q?=E9=9B=86=E6=88=90=E5=B1=82=E5=8E=BB=E9=87=8D=20+=20shim=20?= =?UTF-8?q?=E6=B8=85=E7=90=86=20(2026-07-02)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FINDING-B4: datascreen.ts 与 visualdata.ts 平行重复 (CLAUDE.md §2.5 违反) - datascreen.ts 自写 initWebapi + initDatascreenShim + loadDatascreen Proxy - visualdata.ts 用既有 _loader.ts 机制 + _visualdata_*.ts shim - 6 个 wrapper (addObj/getList/getObj/getCategory/updateObj/delObj) 零引用 - 集成层违反: 两份 initWebapi 各自缓存, 时机/顺序在多命令链路下未定义 修复: - 删 datascreen.ts initWebapi/initDatascreenShim/loadDatascreen/6 wrapper (97 行) - 删 _datascreen_shim.ts (CLAUDE.md §3.6 集中化) - 保留 5 个纯工具函数 (getBaseConfig/getValidProps/listComponentProps/constructConfigDetail/constructComponentJson) - 这些是文件读 + 字符串处理, 不发 HTTP, 不需要 client - construct.ts 不变 (已走 visualdata.addObj/updateComponent) 审计: dacli/docs/cmd-review/v0.14-rollout-audit-2026-07-02.md §1.1 B4 --- src/webapi/_datascreen_shim.ts | 77 ---------------- src/webapi/datascreen.ts | 163 +++++---------------------------- 2 files changed, 22 insertions(+), 218 deletions(-) delete mode 100644 src/webapi/_datascreen_shim.ts diff --git a/src/webapi/_datascreen_shim.ts b/src/webapi/_datascreen_shim.ts deleted file mode 100644 index 8fa8b73..0000000 --- a/src/webapi/_datascreen_shim.ts +++ /dev/null @@ -1,77 +0,0 @@ -/** - * _datascreen_shim.ts — 大屏 web 端 axios shim (jxcj 2026-07-01) - * - * 镜像源: jnpf/前端/jnpf-web-datascreen-vue3/src/axios.js - * - web 端默认 axios + 拦截器加 Authorization / App-Code headers - * - visual.js 用 `import request from '../axios'` (相对路径, 不是 defHttp) - * - 端点: /visual/save, /visual/list, /visual/detail, /visual/update, /visual/remove - * - * 跟 _defhttp_shim.ts 区别: - * - 签名是 axios (config: { url, method, data, params, headers }) - * - 不 strip /api 前缀 (web 端 visual.js 用的 url='/visual/save', baseURL='/api', 实际路径='/api/visual/save') - * - 走 nginx → 32000 jnpf-datareport-univer 微服务 (跟报表同) - * - * shim 行为: 跟 defHttp 一致, 但用 axios 签名 (method/post/data/params/headers) - * request(config) → c.get/c.postJson/c.putJson/c.del 映射 method - */ -import { JnpfClient } from '../core/client.ts' - -const GLOBAL_KEY = '__dacli_datascreen_shim_client__' -type GlobalWithClient = typeof globalThis & { [GLOBAL_KEY]?: JnpfClient } - -function getClient(): JnpfClient { - const client = (globalThis as GlobalWithClient)[GLOBAL_KEY] - if (!client) { - throw new Error('datascreen shim 未初始化, 请先调 initDatascreenShim(client)') - } - return client -} - -/** 初始化 shim, 必须先调一次 (visual.js 模块加载前) */ -export function initDatascreenShim(client: JnpfClient): void { - ;(globalThis as GlobalWithClient)[GLOBAL_KEY] = client -} - -/** - * shim of web 端 axios — 签名: request({ url, method, data, params, headers }) - * 大屏 visual.js 用相对路径 '../axios', 走 baseURL /api + /visual/save = /api/visual/save - * 我们直接用主 client (30000), nginx 代理 /api/visual/* → 32000 (跟报表同) - */ -function stripApiPrefix(url: string): string { - if (url.startsWith('/api/')) return url.slice(4) - if (url === '/api') return '' - return url -} - -async function unwrap(resp: { code: number; msg?: string; data: T | null }): Promise { - if (resp.code !== 200) { - throw new Error(`API code=${resp.code}: ${resp.msg ?? ''}`) - } - if (resp.data === null || resp.data === undefined) { - return { code: resp.code, msg: resp.msg, id: undefined } as unknown as T - } - return resp.data as T -} - -export const request = async (config: { - url: string - method: 'get' | 'post' | 'put' | 'delete' - data?: unknown - params?: Record - headers?: Record -}): Promise => { - const c = getClient() - const path = stripApiPrefix(config.url) - // web 端 axios 拦截器加 Authorization + App-Code, 我们 client 已有 - let r - if (config.method === 'get') { - r = await c.get(path, config.params as Record) - } else if (config.method === 'delete') { - r = await c.del(path) - } else if (config.method === 'put') { - r = await c.putJson(path, (config.data ?? {}) as Record) - } else { - r = await c.postJson(path, (config.data ?? {}) as Record) - } - return unwrap(r) -} diff --git a/src/webapi/datascreen.ts b/src/webapi/datascreen.ts index 8428e01..07b28d3 100644 --- a/src/webapi/datascreen.ts +++ b/src/webapi/datascreen.ts @@ -1,151 +1,32 @@ /** - * webapi/datascreen.ts — 镜像 jnpf-web-datascreen-vue3 独立大屏 webapp (v0.13+ jxcj 2026-07-01) + * webapi/datascreen.ts — 大屏**纯工具函数**模块 (v0.15+ 集成层去重, 2026-07-02) * - * 重要发现 (jxcj 2026-07-01): - * - jnpf 6.x 大屏 web 端是 **jnpf-web-datascreen-vue3 独立编译项目** (不是 jnpf-web-apps-main) + * v0.15+ (P1-5): 删 initWebapi/initDatascreenShim/loadDatascreen/6 个 wrapper + * - 这些代码跟 webapi/visualdata.ts (走 _loader.ts 机制) 平行重复 + * - 整个 codebase 零引用 (construct.ts 走 visualdata.addObj/updateObj, 不走 loadDatascreen) + * - 删 shim 文件 _datascreen_shim.ts 一起清理 (CLAUDE.md §3.6 集中化) + * + * 保留: 5 个纯函数 (无 webapi 依赖, 读 web 端 option/config.js + option/components/*.vue) + * - getBaseConfig(): 镜像 web option/config.js 的 config 模板 + * - getValidProps(): 镜像 option/config.js:268 dicOption.dataList (P1-4 真值源) + * - listComponentProps(): 兜底走 option/components/*.vue 目录扫描 + * - constructConfigDetail(): 镜像 header.vue:200-211 save formdata 结构 + * - constructComponentJson(): 镜像 build.vue:705-709 nav 数组结构 + * - getComponentDefaults(prop): 镜像 option/components/.vue