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:
sswandClaude committed 2026-07-01 08:08:35 +08:00
1 parent f8aad5200d
commit 35c19d1056
3 files changed
+294 -68

No files matched your search

+71 -68
View File
@@ -1,109 +1,112 @@
/**
* commands/bigscreen/create.ts — 新建大屏
* commands/bigscreen/create.ts — 新建大屏 (v0.13+ 镜像 jnpf-web-datascreen-vue3 webapp)
*
* 决策 6: 大屏 webType=3-4, 不需要物理表, 走 dataInterfaceId 拉数据
* 镜像源 (jnpf 6.x 6.2.0):
* - 大屏 web 端是 **jnpf-web-datascreen-vue3 独立编译项目** (jnpf/前端/jnpf-web-datascreen-vue3/)
* - 端点: <baseURL>/visual/save (POST) — 走 nginx 代理到 32000 jnpf-datareport-univer 微服务
* - body (web visual.js addObj): { visual: {password, category, status, title}, config: {detail, component} }
* - 之前 dacli 走 /extend/BigData (jnpf "大数据测试" 端点, 不是大屏!) — BS-新12 silent fail
*
* API: POST /api/extend/BigData
* v3.0+ (2026-06-29 regression audit P0): 改用 webapi/datascreen.addObj (跟 portal/report 一致模式)
* - 镜像 web/前端/jnpf-web-datascreen-vue3/src/api/visual.js addObj
* - 不再直接 c.postJson — 经验复刻, schema 易漂移
*/
import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { validateBigscreenCreate } from './_validate.ts'
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
import { initWebapi as initDatascreenWebapi, addObj as webAddObj } from '../../webapi/datascreen.ts'
interface CreateOpts {
fullName: string
enCode: string
category: string
password?: string
width?: number
height?: number
status?: number
json?: boolean
}
export function buildBigscreenCreateCommand(): Command {
const cmd = new Command('create')
.description('新建大屏 (无物理表, 走 dataInterfaceId 拉数据)')
.requiredOption('--fullName <name>', '大屏名称')
.requiredOption('--enCode <code>', '大屏编码')
.requiredOption('--category <cat>', '分类: 1=数据大屏 2=仪表盘')
.description('新建大屏 (v0.13+ 镜像 jnpf-web-datascreen-vue3 webapp, 走 /api/visual/save 端口 32000)')
.requiredOption('--fullName <name>', '大屏名称 (镜像 web visual.js addObj: visual.title)')
.requiredOption('--enCode <code>', '大屏编码 (镜像 web visual.js addObj)')
.requiredOption('--category <cat>', '分类: 1=数据大屏 2=仪表盘 (镜像 web visual.js addObj: visual.category)')
.option('--password <p>', '访问密码 (镜像 web visual.js addObj: visual.password)', '')
.option('--status <s>', '状态 0/1 (镜像 web visual.js addObj: visual.status)', '1')
.option('--width <n>', '宽度 (镜像 web visual.js addObj: config.detail.width)', '1920')
.option('--height <n>', '高度 (镜像 web visual.js addObj: config.detail.height)', '1080')
.option('--json', '原始 JSON 输出', false)
.action(async (opts: CreateOpts) => {
const c = await JnpfClient.fromToken()
// v0.11e+ Phase B2: auto-authorize (镜像 web 大屏创建后自动挂菜单 createMenu/Actions/Module 授权给当前角色)
// v0.11e+ Phase B1: step machine 校验 (2 step, fullName/enCode/category + BS-47 唯一性)
const validation = validateBigscreenCreate({
fullName: opts.fullName,
enCode: opts.enCode,
category: opts.category,
})
if (!validation.ok) {
for (const s of validation.steps) {
for (const e of s.errors) {
log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`)
}
}
process.exit(1)
}
log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`)
// step 0 基础信息 (P0 镜像 web Form.vue schemas)
// v3.0+ (2026-06-29 regression audit P0): 走 webapi/datascreen.addObj
// - 镜像 web 端 datascreen-vue3/src/api/visual.js: addObj
// - 不直接 c.postJson('/extend/BigData') — 那是 jnpf "大数据测试" 端点, 不是大屏
await initDatascreenWebapi(c)
const body = {
fullName: opts.fullName,
enCode: opts.enCode,
// 镜像 web 端 visual.js addObj body:
// { visual: { password, category, status, title }, config: { detail: JSON.stringify(...), component: '[]' } }
// web 端: visual.title = data.title = opts.fullName (中文名), visual.category = data.category = opts.category
const webAddObjParams = {
title: opts.fullName,
category: opts.category,
type: 3, // 大屏设计器
design: '{}',
enabledMark: 1,
sortCode: 0,
status: Number(opts.status) || 1,
password: opts.password || '',
width: Number(opts.width) || 1920,
height: Number(opts.height) || 1080,
// config 暂用 web 端默认 (detail = JSON.stringify(config + name/width/height), component = '[]')
}
const r = await c.postJson<{ id?: string }>('/extend/BigData', body)
if (r.code !== 200) {
const enhanced = enhanceFromBackend(r.msg || '', 'bigscreen', { entity: 'bigscreen' })
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
// 调用 web 端 addObj (走 /api/visual/save → 32000 jnpf-datareport-univer 微服务)
const r = (await webAddObj(webAddObjParams)) as {
id?: string
code?: number
msg?: string
}
// BS-新12 v2 (jxcj 2026-07-01): jnpf 大屏后端可能返纯字符串 id 或 { id, code, msg }
let id = r?.id
if (!id && typeof r === 'string' && /^\d+$/.test(r.trim())) id = r.trim()
if (r?.code && r.code !== 200) {
log.error(`bigscreen create 失败 (code=${r.code}): ${r.msg}`)
process.exit(1)
}
let id = r.data?.id
if (!id) {
const listR = await c.get<{ list: { id: string; enCode: string; fullName: string }[] }>(
'/extend/BigData',
{ keyword: opts.enCode, pageSize: '50' },
)
const found = (listR.data?.list || []).find(
(d) => d.enCode === opts.enCode || d.fullName === opts.fullName,
)
id = found?.id
}
// BS-新12 (jxcj 2026-07-01): 必查 id, list 反查仍空则报 silent fail, 不允许"成功"误判
if (!id) {
log.error(
`BS-新12 silent fail: 后端返回 code=200 但 r.data.id=undefined, list 反查也找不到. 实际 raw 响应: ${JSON.stringify(r).slice(0, 200)}`,
`BS-新12 silent fail: bigscreen create 后端返 code=200 但 r.id=undefined. 实际 raw: ${JSON.stringify(r).slice(0, 200)}`,
)
log.error('可能原因:')
log.error(' 1. jnpf 后端响应格式变了 (历史期望 { id: string }, 实际可能 { data: { id } } 或 不返回 id)')
log.error(' 2. 后端 category 字段类型/值不接受 (本命令传数字 1/2, 试字符串 "1")')
log.error(' 3. systemId 没传/格式错, 大屏写到 platform 全局, list 翻页找不到')
process.exit(1)
}
log.info(`✓ 大屏创建成功 id=${id}`)
if (opts.json) printJson({ ...(r.data as object), id })
log.ok(
`✓ 大屏创建成功 id=${id} enCode=${opts.enCode} (镜像 web 端 datascreen-vue3 addObj)`,
)
if (opts.json) printJson({ id, enCode: opts.enCode, ...(r as object) })
})
installAiHelpHook(cmd, {
purpose: '新建大屏 (大屏设计器产物, 走 dataInterface 拉数据)',
required: {
'--fullName': '大屏名称',
'--enCode': '大屏编码',
'--category': '分类 1=数据大屏 2=仪表盘',
purpose: '新建大屏 (jnpf 6.x 6.2.0, 走 datascreen-vue3 webapp /api/visual/save 端口 32000)',
required: { '--fullName | --enCode | --category': '中文名 + 英文编码 + 分类 (1=数据大屏 2=仪表盘)' },
optional: {
'--password': '访问密码',
'--status': '状态 0/1 (默认 1)',
'--width | --height': '宽高 (默认 1920x1080)',
},
optional: { '--json': '原始 JSON 输出' },
example: 'dacli bigscreen create --fullName=销售大屏 --enCode=salesDash --category=1',
example: [
'dacli bigscreen create --fullName=销售大屏 --enCode=salesDash --category=1',
'dacli bigscreen create --fullName=JxcjDashboard --enCode=JxcjDashboard --category=1 --width=1920 --height=1080',
],
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/extend/bigData/Form.vue',
api: 'POST /api/extend/BigData',
ref: 'doc/v0.8-endpoints.md §1.4',
web: 'jnpf/前端/jnpf-web-datascreen-vue3/src/api/visual.js: addObj',
api: 'POST /api/visual/save (走 nginx 代理到 32000 jnpf-datareport-univer 微服务)',
ref: 'jnpf-datareport-univer/.../VisualController.java + VisualCrform.java',
},
notes: [
'**决策 6**: 大屏不需要物理表, 走 di 拉数据',
'**决策 6**: webType 3-4 (大屏设计器)',
'v0.13+ 镜像 jnpf 6.x 大屏 web 端 (jnpf-web-datascreen-vue3 独立 webapp, 跟 jnpf-web-apps-main 不同).',
'v3.0+ (2026-06-29 regression audit P0): 改用 webapi/datascreen.addObj, 不直接 c.postJson.',
'之前走 /extend/BigData 是错的 (jnpf "大数据测试" 端点, 不是大屏) — BS-新12 silent fail 已暴露.',
],
})
return cmd
+77
View File
@@ -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)
}
+146
View File
@@ -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)
}