feat(condition): 条件表达式内联变量 chips(议题一 P0)

编辑器出口表达式下展示可用变量(近期 50 条办件 formData 顶层键聚合去重截 40 + 内置,口径同调试弹窗),点击插入光标处;未知标识符内联提示疑似拼错(仅提示不拦截,去字符串/函数名/属性访问后比对)。EditorCtx 增 availableVars,index.vue 载入一次(拉取失败退化为仅内置,不阻塞编辑)。vite build:base 通过。
This commit is contained in:
chenxing
2026-10-14 18:18:42 +08:00
parent fbd428b913
commit 0542279636
3 changed files with 143 additions and 1 deletions
+25
View File
@@ -69,6 +69,8 @@ const depts = reactive<DeptOption[]>([]);
const userNames = reactive<Record<number, string>>({});
/** 条件分支的判断服务注册(flw_router;拉取失败为空数组,校验降级提示) */
const routers = reactive<RouterOption[]>([]);
/** 可用变量 chips:近期办件 formData 顶层键聚合(去重截 40)+ 内置变量;拉取失败仅内置 */
const availableVars = reactive<string[]>([]);
const issues = computed<Issue[]>(() => validateModel(model, depts, routers));
const defJson = computed(() => toContentJson(model));
@@ -201,6 +203,27 @@ async function loadRouters(): Promise<void> {
}
}
/** 表达式可用变量:近期 50 条办件 formData 顶层键聚合(去重截 40)+ 内置,口径同调试弹窗;失败仅内置 */
const BUILTIN_VARS = ["schId", "instanceId", "instanceVersion", "bizType", "bizId", "nodeId", "nodeName", "submitterId"];
async function loadVars(): Promise<void> {
const keys = new Set<string>();
try {
const rows: any[] = (await flowApi.adminInstances({ page: 1, size: 50 }).send())?.content || [];
rows.forEach((r) => {
try {
const v = JSON.parse(r.formDataJson || "{}");
if (v && typeof v === "object" && !Array.isArray(v)) Object.keys(v).forEach((k) => keys.add(k));
} catch {
/* 脏 formData 跳过,不影响其它办件的键聚合 */
}
});
} catch {
/* 办件列表拉取失败:退化为仅内置变量,不阻塞编辑 */
}
const merged = Array.from(new Set([...Array.from(keys).slice(0, 40), ...BUILTIN_VARS]));
availableVars.splice(0, availableVars.length, ...merged);
}
function applyParsed(parsed: ParsedDef): void {
model.code = parsed.code || model.code;
model.name = parsed.name || model.name;
@@ -217,6 +240,7 @@ async function load(): Promise<void> {
try {
await loadDepts();
await loadRouters();
void loadVars();
try {
const rows: any[] = (await flowApi.appList().send()) || [];
appOptions.value = rows
@@ -385,6 +409,7 @@ provide<EditorCtx>(EDITOR_CTX, {
depts,
userNames,
routers,
availableVars,
issueOf,
openNode,
removeNode,