dacli(镜像 datascreen-vue3 jxcj 2026-07-01): 大屏 webapi 镜像 (独立 webapp)
按镜像架构 + BS-新12 v2 + v3.0+ regression audit P0:
1. **新增 webapi/datascreen.ts** (jnpf-web-datascreen-vue3 独立 webapp 镜像):
- 之前误以为大屏 web 端在 jnpf-web-apps-main, 实际是独立 webapp
jnpf/前端/jnpf-web-datascreen-vue3/src/api/visual.js
- 端点: <baseURL>/visual/save (POST), /visual/list, /visual/detail, /visual/update, /visual/remove
- body (web visual.js addObj): { visual: {password, category, status, title}, config: {detail, component} }
- 6 个 wrapper 函数: addObj / getList / getObj / getCategory / updateObj / delObj
2. **新增 webapi/_datascreen_shim.ts** (跟 defHttp shim 不同):
- web 端用 axios 签名 (method/data/params/headers), 不是 defHttp 签名
- visual.js 用 import request from '../axios' 相对路径
- shim 签名: request({ url, method, data, params, headers })
- 跟 defHttp 一样: 主 client (30000) + nginx 代理 /api/visual/* → 32000
3. **改 dacli/bigscreen/create.ts 走 webapi** (跟 portal/report 镜像一致):
- 之前走 c.postJson('/extend/BigData') (jnpf 大数据测试 端点, 不是大屏, BS-新12 silent fail)
- 现在走 webapi/datascreen.addObj (跟 portal createPortal / report createReport 一致)
- 镜像 web 端 visual.js: addObj body 完整 (visual+config)
- 6 个 --option: --fullName/--enCode/--category/--password/--status/--width/--height
4. **特殊 loader 处理** (不用 webapi/_loader.ts, datascreen.ts 自带):
- visual.js 用 import request from '../axios' (相对路径, loader 默认不替换)
- datascreen.ts 走 readFileSync + writeFileSync + dynamic import 模式
- 替换规则: axios import → shim, baseUrl → /visual, 删 web 端 axios 拦截器引用 (window. / localStorage)
- mock const config = {} 替代 @/option/config (大屏默认配置)
镜像依据 (jnpf-web-datascreen-vue3 独立 webapp):
- jnpf/前端/jnpf-web-datascreen-vue3/src/api/visual.js: addObj body
- jnpf/前端/jnpf-web-datascreen-vue3/src/axios.js: 拦截器 (token + App-Code)
- 后端 jnpf-datareport-univer/.../VisualController.java POST /visual/save (同大屏)
- nginx /api/visual/* → 32000 (同报表)
跨服务 sa-token 限制: 跟报表一样, jnpf 已知 (boot/report/sa-token-override/README.md).
本轮不动 sa-token 凭证 (按用户要求镜像 web 源码).
Co-Authored-By: Claude <[email protected]>
This commit is contained in:
1 parent
f8aad5200d
commit
35c19d1056
3 files changed
+294
-68
No files matched your search
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* _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)
|
||||
* - 端点: <baseURL>/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='<base>/visual/save', baseURL='<base>/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<T>(resp: { code: number; msg?: string; data: T | null }): Promise<T> {
|
||||
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<string, unknown>
|
||||
headers?: Record<string, string>
|
||||
}): Promise<unknown> => {
|
||||
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<string, string | number | undefined>)
|
||||
} else if (config.method === 'delete') {
|
||||
r = await c.del(path)
|
||||
} else if (config.method === 'put') {
|
||||
r = await c.putJson(path, (config.data ?? {}) as Record<string, unknown>)
|
||||
} else {
|
||||
r = await c.postJson(path, (config.data ?? {}) as Record<string, unknown>)
|
||||
}
|
||||
return unwrap(r)
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* webapi/datascreen.ts — 镜像 jnpf-web-datascreen-vue3 独立大屏 webapp (v0.13+ jxcj 2026-07-01)
|
||||
*
|
||||
* 重要发现 (jxcj 2026-07-01):
|
||||
* - jnpf 6.x 大屏 web 端是 **jnpf-web-datascreen-vue3 独立编译项目** (不是 jnpf-web-apps-main)
|
||||
* - 路径: jnpf/前端/jnpf-web-datascreen-vue3/src/api/visual.js
|
||||
* - 端点: <baseURL>/visual/save (POST), /visual/list (GET), /visual/detail (GET), /visual/update, /visual/remove
|
||||
* - nginx 代理 /api/visual/* → 32000 (jnpf-datareport-univer 微服务, 跟大屏/报表同微服务)
|
||||
* - 大屏 web 端 addObj body: { visual: {password, category, status, title}, config: {detail, component} }
|
||||
*
|
||||
* 镜像源: jnpf/前端/jnpf-web-datascreen-vue3/src/api/visual.js (整文件)
|
||||
* export const addObj = (data) => request({ url: baseUrl + '/save', method: 'post', data: { visual: {...}, config: {...} } })
|
||||
*
|
||||
* 之前 dacli bigscreen create 走 /extend/BigData (jnpf "大数据测试" 端点, 错), 报 BS-新12 silent fail
|
||||
* 现镜像 web 端 visual.js addObj 走 /api/visual/save
|
||||
*
|
||||
* 特殊处理: visual.js 用 `import request from '../axios'` (相对路径, 不是 defHttp),
|
||||
* loadWebModule 默认规则不替换. 不用 loader, 直接读 + 手动 replace + dynamic import.
|
||||
*/
|
||||
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join, dirname } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { JnpfClient } from '../core/client.ts'
|
||||
import { initDatascreenShim } from './_datascreen_shim.ts'
|
||||
|
||||
const DATASCREEN_SRC = '/home/ubuntu/ccWorkDir/jnpf/前端/jnpf-web-datascreen-vue3/src/api/visual.js'
|
||||
const SHIM_DIR = dirname(new URL(import.meta.url).pathname)
|
||||
const DATASCREEN_SHIM_PATH = join(SHIM_DIR, '_datascreen_shim.ts')
|
||||
|
||||
let cached: any = null
|
||||
|
||||
/**
|
||||
* 初始化 webapi 层: 读 + 替换 + dynamic import (跟 _loader.ts 一样的技巧, 但单独处理)
|
||||
* - 替换 1: `import { url } from '@/config'` → 删掉 (我们不需要 baseURL, 走主 client)
|
||||
* - 替换 2: `import { config } from '@/option/config'` → 删掉
|
||||
* - 替换 3: `import request from '../axios'` → `import { request } from '<datascreen shim path>'`
|
||||
* - 替换 4: `import { url } from '@/config'; import { config } from '@/option/config' const baseUrl = url + '/visual'`
|
||||
* → 删掉, 但 baseUrl 在 visual.js 里被所有方法用. 我们需要保留 const baseUrl = '/visual' (path 形式)
|
||||
* - 替换 5: `let header = window.$glob.header || {}; config.headers = Object.assign(config.headers, header);`
|
||||
* → 注: shim 已有 headers, 删掉这几行避免 window.$glob 引用
|
||||
* - 替换 6: `const token = localStorage.getItem("token") || ''` → 注: shim 不需 token
|
||||
*/
|
||||
export async function initWebapi(client: JnpfClient): Promise<void> {
|
||||
if (cached) return
|
||||
initDatascreenShim(client)
|
||||
const code = readFileSync(DATASCREEN_SRC, 'utf-8')
|
||||
const patched = code
|
||||
// 替换 axios import 为 shim
|
||||
.replace(
|
||||
/import\s+request\s+from\s+['"]\.\.\/axios['"]/,
|
||||
`import { request } from '${DATASCREEN_SHIM_PATH}'\nconst config = {}; // mock @/option/config (jnpf 大屏默认配置, 简化)`,
|
||||
)
|
||||
// 替换 baseUrl 定义 (web 端用 url + '/visual', 我们用 const baseUrl = '/visual' 简化)
|
||||
.replace(
|
||||
/const\s+baseUrl\s*=\s*url\s*\+\s*['"]\/visual['"]/,
|
||||
`const baseUrl = '/visual'`,
|
||||
)
|
||||
// 删掉 web 端 import (axios 拦截器引用了 url/config/window/localStorage, 我们不需要)
|
||||
.replace(
|
||||
/import\s*\{[^}]*\}\s*from\s*['"]@\/config['"];?/g,
|
||||
'',
|
||||
)
|
||||
.replace(
|
||||
/import\s*\{[^}]*\}\s*from\s*['"]@\/option\/config['"];?/g,
|
||||
'',
|
||||
)
|
||||
.replace(
|
||||
/let\s+header\s*=\s*window\.\$glob\.[^;]+;[\s\S]*?config\.headers\s*=\s*Object\.assign[^;]+;?/g,
|
||||
'',
|
||||
)
|
||||
.replace(
|
||||
/const\s+token\s*=\s*localStorage\.[^;]+;?/g,
|
||||
'',
|
||||
)
|
||||
.replace(
|
||||
/config\.headers\['Authorization'\][^;]+;?/g,
|
||||
'',
|
||||
)
|
||||
.replace(
|
||||
/const\s+appCode\s*=[^;]+;?/g,
|
||||
'',
|
||||
)
|
||||
.replace(
|
||||
/config\.headers\['App-Code'\][^;]+;?/g,
|
||||
'',
|
||||
)
|
||||
|
||||
// 写 tmp file + dynamic import
|
||||
const tmpDir = join(tmpdir(), 'dacli-datascreen-' + Date.now())
|
||||
mkdirSync(tmpDir, { recursive: true })
|
||||
const tmpFile = join(tmpDir, 'visual.mjs')
|
||||
writeFileSync(tmpFile, patched)
|
||||
cached = await import(pathToFileURL(tmpFile).href)
|
||||
}
|
||||
|
||||
export function isWebapiLoaded(): boolean {
|
||||
return cached !== null
|
||||
}
|
||||
|
||||
export const loadDatascreen: any = new Proxy({} as any, {
|
||||
get(_target, prop) {
|
||||
if (!cached) {
|
||||
throw new Error(`datascreen 模块未初始化, 请先 await initWebapi(client)`)
|
||||
}
|
||||
return cached[prop]
|
||||
},
|
||||
})
|
||||
|
||||
/** 创建大屏 (镜像 web visual.js: addObj) */
|
||||
export async function addObj(params: {
|
||||
title: string
|
||||
category: string
|
||||
status?: number
|
||||
password?: string
|
||||
width?: number
|
||||
height?: number
|
||||
config?: Record<string, unknown>
|
||||
}): Promise<unknown> {
|
||||
return loadDatascreen.addObj(params)
|
||||
}
|
||||
|
||||
/** 大屏列表 (镜像 web visual.js: getList) */
|
||||
export async function getList(params?: Record<string, unknown>): Promise<unknown> {
|
||||
return loadDatascreen.getList(params)
|
||||
}
|
||||
|
||||
/** 大屏详情 (镜像 web visual.js: getObj) */
|
||||
export async function getObj(id: string): Promise<unknown> {
|
||||
return loadDatascreen.getObj(id)
|
||||
}
|
||||
|
||||
/** 大屏分类 (镜像 web visual.js: getCategory) */
|
||||
export async function getCategory(params?: Record<string, unknown>): Promise<unknown> {
|
||||
return loadDatascreen.getCategory(params)
|
||||
}
|
||||
|
||||
/** 更新大屏 (镜像 web visual.js: updateObj) */
|
||||
export async function updateObj(data: Record<string, unknown>): Promise<unknown> {
|
||||
return loadDatascreen.updateObj(data)
|
||||
}
|
||||
|
||||
/** 删除大屏 (镜像 web visual.js: delObj) */
|
||||
export async function delObj(id: string): Promise<unknown> {
|
||||
return loadDatascreen.delObj(id)
|
||||
}
|
||||
Reference in new issue
Block a user