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