Per audit §7 / H1: ~37 src files hardcoded '/home/ubuntu/ccWorkDir', welding the
whole pipeline to one container (external CI / other machines crash).
- new src/core/paths.ts: getCcWorkDir() (env CCWORKDIR || default) + getWebSrc()
- swept 36 files: '/home/ubuntu/ccWorkDir<sub>' literals → `${getCcWorkDir()}<sub>`
templates; collapsed 3 inline (process.env.CCWORKDIR || '...') dupes to getCcWorkDir()
- covers webapi mirror (_loader WEB_SRC/JNPF_UTILS_UUID + 24 module *_SRC), db/verify
paths, drift/coverage/selfcheck, buildformdata, codegen, render, blindspot boot paths
- playwright .cache path + doc-comment refs left as-is (not ccWorkDir-rooted)
Verified: tsc 0 (validates every inserted import path); runtime menu webapi
initWebapi OK; smoke form list returns real data (WEB_SRC end-to-end via getCcWorkDir);
vitest unit 336 pass.
Co-Authored-By: Claude <[email protected]>
197 lines
5.8 KiB
TypeScript
197 lines
5.8 KiB
TypeScript
/**
|
|
* webapi/system.ts — 直接 import web 端 system.ts (v3.0+ regression audit P0)
|
|
*
|
|
* web/apps/jnpf-web-apps-main/src/api/system/system.ts 15 函数:
|
|
* getSystemList, getAuthSystemList, create, update, getInfo, delSystem,
|
|
* copySystem, exportSystem, getAppAuth, saveAppAuth, changeAppAuth,
|
|
* getDevUser, getSystemSelector, getSystemlist, setPin
|
|
*
|
|
* v3.0+ (2026-06-29) 新增原因:
|
|
* - v3.0+ 评审已识别: app/list.ts, app/info.ts, app/create.ts 之前 0 webapi 引用, 直接 c.get/postJson
|
|
* - 应 webapi 镜像, 复用 web 端 15 个 API (CRUD + Copy/Export + Auth + Selector)
|
|
* - 之前缺失的能力 (copySystem / exportSystem / getAppAuth / saveAppAuth / changeAppAuth / setPin) 一并恢复
|
|
*
|
|
* 设计 (与其他 webapi 模块一致):
|
|
* - loadWebModule 真 import web 源码 (不复刻)
|
|
* - defHttp shim 用 JnpfClient 实现 (Node CLI 环境)
|
|
* - initWebapi(client) 一次性初始化 + 缓存
|
|
*/
|
|
import { getCcWorkDir } from '../core/paths.ts'
|
|
import { JnpfClient } from '../core/client.ts'
|
|
import { loadWebModule } from './_loader.ts'
|
|
|
|
const SYSTEM_SRC = `${getCcWorkDir()}/web/apps/jnpf-web-apps-main/src/api/system/system.ts`
|
|
|
|
let cached: any = null
|
|
|
|
export async function initWebapi(client: JnpfClient): Promise<void> {
|
|
if (cached) return
|
|
const { initDefHttpShim } = await import('./_defhttp_shim.ts')
|
|
initDefHttpShim(client)
|
|
cached = await loadWebModule(SYSTEM_SRC)
|
|
}
|
|
|
|
export function isWebapiLoaded(): boolean {
|
|
return cached !== null
|
|
}
|
|
|
|
/**
|
|
* SystemData namespace — 镜像 web SystemController 接口定义 (精简版)
|
|
*
|
|
* 完整 schema 在后端 SystemController.java, 这里只暴露 dacli 常用字段
|
|
*/
|
|
export namespace SystemData {
|
|
/** 应用列表查询参数 */
|
|
export interface ListParams {
|
|
keyword?: string
|
|
currentPage?: number
|
|
pageSize?: number
|
|
[key: string]: unknown
|
|
}
|
|
|
|
/** 应用信息 (来自 getInfo) */
|
|
export interface SystemInfo {
|
|
id: string
|
|
enCode: string
|
|
fullName: string
|
|
/** 父级 id, "0" 或 "-1" 表示顶级 */
|
|
parentId?: string
|
|
/** 分类 */
|
|
category?: string
|
|
/** 应用图标 */
|
|
icon?: string
|
|
/** 排序码 */
|
|
sortCode?: number
|
|
/** 启用标记 0/1 */
|
|
enabledMark?: number
|
|
/** 描述 */
|
|
description?: string
|
|
[key: string]: unknown
|
|
}
|
|
|
|
/** 创建/更新应用参数 */
|
|
export interface CreateParams {
|
|
enCode: string
|
|
fullName: string
|
|
parentId?: string
|
|
category?: string
|
|
icon?: string
|
|
sortCode?: number
|
|
enabledMark?: number
|
|
description?: string
|
|
/** 数据库名 (app create 时必填) */
|
|
dbName?: string
|
|
/** 数据源 ID */
|
|
dbLinkId?: string
|
|
[key: string]: unknown
|
|
}
|
|
|
|
/** 更新应用参数 (与 CreateParams 类似, 但必带 id) */
|
|
export interface UpdateParams extends CreateParams {
|
|
id: string
|
|
}
|
|
|
|
/** 保存应用授权参数 */
|
|
export interface SaveAppAuthParams {
|
|
/** 应用 id */
|
|
id: string
|
|
/** 角色 id 列表 */
|
|
roleIds?: string[]
|
|
/** 用户 id 列表 */
|
|
userIds?: string[]
|
|
/** 按钮权限 */
|
|
buttonPermission?: Record<string, string[]>
|
|
[key: string]: unknown
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Proxy 包装的 webapi 模块
|
|
*
|
|
* 调用前必须先 `await initWebapi(client)`
|
|
*/
|
|
export const loadSystem: any = new Proxy({} as any, {
|
|
get(_target, prop) {
|
|
if (!cached) {
|
|
throw new Error(`system 模块未初始化, 请先 await initWebapi(client)`)
|
|
}
|
|
return cached[prop]
|
|
},
|
|
})
|
|
|
|
// ===== 便捷包装函数 (15 个, 完全镜像 web 端) =====
|
|
|
|
/** 获取应用列表 */
|
|
export async function getSystemList(params?: SystemData.ListParams): Promise<unknown> {
|
|
return loadSystem.getSystemList(params)
|
|
}
|
|
|
|
/** 获取权限应用列表 (当前用户可见) */
|
|
export async function getAuthSystemList(params?: SystemData.ListParams): Promise<unknown> {
|
|
return loadSystem.getAuthSystemList(params)
|
|
}
|
|
|
|
/** 创建应用 */
|
|
export async function create(params: SystemData.CreateParams): Promise<unknown> {
|
|
return loadSystem.create(params)
|
|
}
|
|
|
|
/** 更新应用 */
|
|
export async function update(params: SystemData.UpdateParams): Promise<unknown> {
|
|
return loadSystem.update(params)
|
|
}
|
|
|
|
/** 获取单个应用详情 */
|
|
export async function getInfo(id: string): Promise<SystemData.SystemInfo> {
|
|
return loadSystem.getInfo(id)
|
|
}
|
|
|
|
/** 删除应用 */
|
|
export async function delSystem(id: string): Promise<unknown> {
|
|
return loadSystem.delSystem(id)
|
|
}
|
|
|
|
/** 复制应用 (v3.0+ 新增恢复能力) */
|
|
export async function copySystem(id: string): Promise<unknown> {
|
|
return loadSystem.copySystem(id)
|
|
}
|
|
|
|
/** 导出应用 (v3.0+ 新增恢复能力) */
|
|
export async function exportSystem(id: string): Promise<unknown> {
|
|
return loadSystem.exportSystem(id)
|
|
}
|
|
|
|
/** 获取应用授权信息 */
|
|
export async function getAppAuth(id: string): Promise<unknown> {
|
|
return loadSystem.getAppAuth(id)
|
|
}
|
|
|
|
/** 保存应用授权信息 (app create 必备, 旧 dacli 缺失此步) */
|
|
export async function saveAppAuth(params: SystemData.SaveAppAuthParams): Promise<unknown> {
|
|
return loadSystem.saveAppAuth(params)
|
|
}
|
|
|
|
/** 移交应用创建人 */
|
|
export async function changeAppAuth(params: Record<string, unknown>): Promise<unknown> {
|
|
return loadSystem.changeAppAuth(params)
|
|
}
|
|
|
|
/** 获取开发人员列表 */
|
|
export async function getDevUser(params?: Record<string, unknown>): Promise<unknown> {
|
|
return loadSystem.getDevUser(params)
|
|
}
|
|
|
|
/** 流程监控所属应用 (下拉选择) */
|
|
export async function getSystemSelector(params?: Record<string, unknown>): Promise<unknown> {
|
|
return loadSystem.getSystemSelector(params)
|
|
}
|
|
|
|
/** 获取所有应用 (别名) */
|
|
export async function getSystemlist(params?: Record<string, unknown>): Promise<unknown> {
|
|
return loadSystem.getSystemlist(params)
|
|
}
|
|
|
|
/** 置顶应用 */
|
|
export async function setPin(params: Record<string, unknown>): Promise<unknown> {
|
|
return loadSystem.setPin(params)
|
|
} |