chore(tests): 清理 6 过期/1 业务/2 .DS_Store (9 文件)
用户反馈 2026-07-07: 'dacli/tests 文件夹很乱, 是不是很多业务性或过期的'
清理 (4 步法#1 系统分类):
6 过期 (v0.15+ SSW fallback + _buildformdata.ts 已替代):
- test-ai-refactored.ts (1.1KB, _ai.ts 重构临时验证)
- test-direct-ai-call.ts (6.2KB, 直连 AI 测试, 已被 SSW 替代)
- test-direct-ai-jnpf-prompt.ts (8.7KB, GEN_MODEL_QUETION 验证, 已被 SSW 替代)
- test-e2e-direct-ai-buildformdata.ts (8.5KB, 业务特定 - jxcj app)
- test-import-buildformdata.mjs (2.6KB, 自写#/路径替换, 已被 _buildformdata.ts 替代)
- test-import-buildformdata.ts (4.3KB, 同上)
1 业务特定 (jxcj):
- fixtures/plan.md (数据要素人工智能创新大赛管理平台, jxcj app 业务)
2 macOS 临时:
- .DS_Store (tests/ + tests/e2e/)
保留 (通用 dacli 能力测试):
- test-kb.ts (KB 闭环, 5.3KB)
- unit/ (25 文件, 单元测试)
- integration/ (4 文件 + 我加的 audit/)
- e2e/ (15+ 文件, 含 _helpers/ + step-machine/)
Co-Authored-By: Claude <[email protected]>
This commit is contained in:
1 parent
24ac4184c9
commit
d982753739
9 files changed
-821
No files matched your search
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
-36
@@ -1,36 +0,0 @@
|
|||||||
# 数据要素人工智能创新大赛管理平台
|
|
||||||
|
|
||||||
## 元信息
|
|
||||||
|
|
||||||
| 字段 | 值 |
|
|
||||||
| --- | --- |
|
|
||||||
| app_code | jxcj |
|
|
||||||
| systemId | 841235275286839301 |
|
|
||||||
|
|
||||||
## 1. 当前任务 (上下文恢复指针)
|
|
||||||
|
|
||||||
- 阶段: 阶段 4 - 执行
|
|
||||||
- 具体任务: **派子代理创建 4 模块 10 form**
|
|
||||||
- 负责人: 主代理
|
|
||||||
- 预计完成: 本轮
|
|
||||||
- 前置依赖: jxcj 应用已重建
|
|
||||||
- 回滚点: 无 (新建应用)
|
|
||||||
|
|
||||||
## 2. 已决事项 (子代理回写)
|
|
||||||
|
|
||||||
| enCode | id | state | idempotency | 关键决策 |
|
|
||||||
| --- | --- | --- | --- | --- |
|
|
||||||
| competitionInfo | 8412... | 1 | ok | webType=2 |
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
graph LR
|
|
||||||
A[主代理] --> B[子代理]
|
|
||||||
B --> C[form]
|
|
||||||
```
|
|
||||||
|
|
||||||
## 3. 阶段进度
|
|
||||||
|
|
||||||
- [x] 阶段 1: 初始化
|
|
||||||
- [ ] 阶段 2: 设计
|
|
||||||
- [ ] 阶段 3: 审核
|
|
||||||
- [x] 阶段 4: 执行 (5/10)
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
// 验证 _ai.ts 改造后的双路径
|
|
||||||
// 用 env 强制走直连 AI(不依赖 JNPF backend)
|
|
||||||
|
|
||||||
import { callAiForm, printAiFormResult } from '../src/commands/form/_ai.ts';
|
|
||||||
|
|
||||||
// 凭据从环境变量读(不入文件、不入 git)
|
|
||||||
if (!process.env.ANTHROPIC_BASE_URL) {
|
|
||||||
console.error('❌ 请设置 ANTHROPIC_BASE_URL / ANTHROPIC_AUTH_TOKEN / ANTHROPIC_MODEL');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
console.log('配置: BASE_URL=' + process.env.ANTHROPIC_BASE_URL + ' MODEL=' + process.env.ANTHROPIC_MODEL);
|
|
||||||
console.log('走路径 1: 直连 AI (ANTHROPIC_* 已设)');
|
|
||||||
console.log();
|
|
||||||
|
|
||||||
const r = await callAiForm('做一个客户管理表:姓名、电话、客户类型(个人/企业)、备注');
|
|
||||||
printAiFormResult(r);
|
|
||||||
|
|
||||||
console.log('\n✅ 验证 _ai.ts 直连 AI 路径走通');
|
|
||||||
|
|
||||||
// 验证主子表
|
|
||||||
console.log('\n=== 第二个测试: 主子表 ===');
|
|
||||||
const r2 = await callAiForm('做一个商城订单管理。主表存订单(订单号、客户姓名、订单状态未付款/已付款/已发货),子表存订单商品明细(商品名称、商品数量)');
|
|
||||||
printAiFormResult(r2);
|
|
||||||
|
|
||||||
console.log('\n✅ 主子表也走通');
|
|
||||||
@@ -1,160 +0,0 @@
|
|||||||
// 测试:dacli _ai.ts 改造为 model-agnostic + 真实 API 调用
|
|
||||||
// 凭据通过环境变量注入,不入文件
|
|
||||||
|
|
||||||
import { readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
||||||
import { tmpdir } from 'os';
|
|
||||||
import { resolve, dirname } from 'path';
|
|
||||||
import { pathToFileURL } from 'url';
|
|
||||||
|
|
||||||
const BASE_URL = process.env.DACLI_AI_BASE_URL;
|
|
||||||
const AUTH_TOKEN = process.env.DACLI_AI_AUTH_TOKEN;
|
|
||||||
const MODEL = process.env.DACLI_AI_MODEL;
|
|
||||||
|
|
||||||
if (!BASE_URL || !AUTH_TOKEN || !MODEL) {
|
|
||||||
console.error('❌ 需要设置环境变量:');
|
|
||||||
console.error(' DACLI_AI_BASE_URL, DACLI_AI_AUTH_TOKEN, DACLI_AI_MODEL');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('=== 配置 ===');
|
|
||||||
console.log(' BASE_URL:', BASE_URL);
|
|
||||||
console.log(' AUTH_TOKEN:', AUTH_TOKEN.slice(0, 10) + '...' + AUTH_TOKEN.slice(-4));
|
|
||||||
console.log(' MODEL:', MODEL);
|
|
||||||
console.log();
|
|
||||||
|
|
||||||
// 1. 复用测试 1 的 import 机制拿 buildFormData
|
|
||||||
const WEB_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src';
|
|
||||||
let buildFormDataSrc = readFileSync(`${WEB_SRC}/components/FormGenerator/src/helper/formUtils.ts`, 'utf-8');
|
|
||||||
const JNPF_UTILS_UUID = '/home/ubuntu/ccWorkDir/web/packages/jnpf/utils/src/helpers/uuid.ts';
|
|
||||||
buildFormDataSrc = buildFormDataSrc
|
|
||||||
.replace(/from\s+['"]#\/(.+?)['"]/g, (_, p) => `from '${WEB_SRC}/${p}'`)
|
|
||||||
.replace(/from\s+['"]@jnpf\/utils['"]/g, `from '${JNPF_UTILS_UUID}'`)
|
|
||||||
.replace(/import\s*\{\s*cloneDeep\s*\}\s*from\s+['"]lodash-es['"];?/g,
|
|
||||||
`const cloneDeep = (x) => structuredClone(x);`);
|
|
||||||
|
|
||||||
const tmpDir = `${tmpdir()}/dacli-ai-test-${Date.now()}`;
|
|
||||||
mkdirSync(tmpDir, { recursive: true });
|
|
||||||
const tmpBuildFormData = `${tmpDir}/formUtils.ts`;
|
|
||||||
writeFileSync(tmpBuildFormData, buildFormDataSrc);
|
|
||||||
const { buildFormData } = await import(pathToFileURL(tmpBuildFormData).href);
|
|
||||||
console.log('✅ buildFormData 加载成功\n');
|
|
||||||
|
|
||||||
// 2. 调 AI 拿 form 描述(Anthropic Messages API 格式)
|
|
||||||
const url = `${BASE_URL}/v1/messages`;
|
|
||||||
const prompt = `设计一个简单的客户管理表单。包含字段:客户姓名(单行文本)、联系电话(单行文本)、客户类型(单选:个人/企业)、备注(多行文本)。
|
|
||||||
请严格按以下 JSON 格式返回(不要其他任何内容):
|
|
||||||
[{
|
|
||||||
"tableTitle": "客户",
|
|
||||||
"tableName": "customer",
|
|
||||||
"fields": [
|
|
||||||
{"fieldTitle": "客户姓名", "fieldName": "f_name", "fieldComponent": "input"},
|
|
||||||
...
|
|
||||||
]
|
|
||||||
}]`;
|
|
||||||
|
|
||||||
console.log('=== POST', url, '===');
|
|
||||||
const aiStart = Date.now();
|
|
||||||
const resp = await fetch(url, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'x-api-key': AUTH_TOKEN,
|
|
||||||
'anthropic-version': '2023-06-01',
|
|
||||||
'content-type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
model: MODEL,
|
|
||||||
max_tokens: 2000,
|
|
||||||
messages: [{ role: 'user', content: prompt }],
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
const aiMs = Date.now() - aiStart;
|
|
||||||
console.log(` HTTP ${resp.status} ${aiMs}ms`);
|
|
||||||
|
|
||||||
if (!resp.ok) {
|
|
||||||
const errText = await resp.text();
|
|
||||||
console.error('❌ AI 调用失败:');
|
|
||||||
console.error(errText.slice(0, 500));
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const aiResp = await resp.json();
|
|
||||||
console.log('\n=== AI 响应原始结构 ===');
|
|
||||||
console.log(' keys:', Object.keys(aiResp));
|
|
||||||
if (aiResp.usage) console.log(' usage:', JSON.stringify(aiResp.usage));
|
|
||||||
if (aiResp.model) console.log(' model:', aiResp.model);
|
|
||||||
if (aiResp.stop_reason) console.log(' stop_reason:', aiResp.stop_reason);
|
|
||||||
|
|
||||||
// 3. 提取 text content
|
|
||||||
const textContent = aiResp.content
|
|
||||||
?.filter((b: any) => b.type === 'text')
|
|
||||||
.map((b: any) => b.text)
|
|
||||||
.join('\n');
|
|
||||||
if (!textContent) {
|
|
||||||
console.error('❌ 响应中没有 text content');
|
|
||||||
console.error('content:', JSON.stringify(aiResp.content));
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('\n=== AI 返回文本(前 500 字)===');
|
|
||||||
console.log(textContent.slice(0, 500));
|
|
||||||
console.log('...');
|
|
||||||
|
|
||||||
// 4. 解析 JSON
|
|
||||||
const jsonStart = textContent.indexOf('[');
|
|
||||||
const jsonEnd = textContent.lastIndexOf(']');
|
|
||||||
if (jsonStart === -1 || jsonEnd === -1) {
|
|
||||||
console.error('❌ 响应中没有 JSON 数组');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
const jsonStr = textContent.slice(jsonStart, jsonEnd + 1);
|
|
||||||
let aiModelList;
|
|
||||||
try {
|
|
||||||
aiModelList = JSON.parse(jsonStr);
|
|
||||||
} catch (e: any) {
|
|
||||||
console.error('❌ JSON 解析失败:', e.message);
|
|
||||||
console.error('JSON 字符串(前 500):', jsonStr.slice(0, 500));
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
console.log('\n=== 解析后的 aiModelList ===');
|
|
||||||
console.log(' 表数:', aiModelList.length);
|
|
||||||
for (const t of aiModelList) {
|
|
||||||
console.log(` - [${t.isMain ? '主' : '子'}] ${t.tableName}: ${t.tableTitle} (${t.fields?.length || 0} 字段)`);
|
|
||||||
for (const f of t.fields || []) {
|
|
||||||
console.log(` ${f.fieldName} ${f.fieldComponent} "${f.fieldTitle}"`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. 喂给 buildFormData
|
|
||||||
console.log('\n=== 喂给 buildFormData ===');
|
|
||||||
const aiModelListWithMain = aiModelList.map((t: any, i: number) => ({ ...t, isMain: i === 0 }));
|
|
||||||
const formDataResult = buildFormData(aiModelListWithMain);
|
|
||||||
const formData = JSON.parse(formDataResult.formData);
|
|
||||||
|
|
||||||
console.log(' formData.fields 数:', formData.fields.length);
|
|
||||||
console.log(' formConf 顶层 keys 数:', Object.keys(formData).length);
|
|
||||||
console.log(' defaultDataForm 顶层 keys:', Object.keys(formDataResult).filter((k: string) => k !== 'formData'));
|
|
||||||
|
|
||||||
console.log('\n=== 第一个 field 详细 ===');
|
|
||||||
const f0 = formData.fields[0];
|
|
||||||
console.log(' __vModel__:', f0.__vModel__);
|
|
||||||
console.log(' __config__ keys (', Object.keys(f0.__config__).length, '个)');
|
|
||||||
console.log(' ⭐ formId:', f0.__config__.formId);
|
|
||||||
console.log(' ⭐ renderKey:', f0.__config__.renderKey);
|
|
||||||
console.log(' ⭐ tag:', f0.__config__.tag);
|
|
||||||
console.log(' ⭐ isSubTable:', f0.__config__.isSubTable);
|
|
||||||
|
|
||||||
console.log('\n=== select 字段(如果有)===');
|
|
||||||
const selectField = formData.fields.find((f: any) => f.options);
|
|
||||||
if (selectField) {
|
|
||||||
console.log(' 字段:', selectField.__vModel__);
|
|
||||||
console.log(' options:', JSON.stringify(selectField.options));
|
|
||||||
} else {
|
|
||||||
console.log(' (本例无 select)');
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('\n✅ 完整链路验证通过:');
|
|
||||||
console.log(' 1. AI API 调到 ✅');
|
|
||||||
console.log(' 2. AI 理解 JNPF schema 格式 ✅');
|
|
||||||
console.log(' 3. JSON 解析 ✅');
|
|
||||||
console.log(' 4. 喂给 buildFormData ✅');
|
|
||||||
console.log(' 5. schema 完整(含 formId/renderKey/isSubTable)✅');
|
|
||||||
@@ -1,194 +0,0 @@
|
|||||||
// 使用 JNPF 后端 GEN_MODEL_QUETION 原版 prompt + 直接 AI 调用
|
|
||||||
// 这是 dacli 替代 JNPF backend 的核心验证
|
|
||||||
|
|
||||||
import { readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
||||||
import { tmpdir } from 'os';
|
|
||||||
import { pathToFileURL } from 'url';
|
|
||||||
|
|
||||||
const BASE_URL = process.env.DACLI_AI_BASE_URL;
|
|
||||||
const AUTH_TOKEN = process.env.DACLI_AI_AUTH_TOKEN;
|
|
||||||
const MODEL = process.env.DACLI_AI_MODEL;
|
|
||||||
|
|
||||||
if (!BASE_URL || !AUTH_TOKEN || !MODEL) {
|
|
||||||
console.error('❌ 需要设置 DACLI_AI_BASE_URL / AUTH_TOKEN / MODEL');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('=== 配置 ===');
|
|
||||||
console.log(' BASE_URL:', BASE_URL);
|
|
||||||
console.log(' MODEL:', MODEL);
|
|
||||||
console.log();
|
|
||||||
|
|
||||||
// ====== JNPF 后端原版 prompt(直接复用)======
|
|
||||||
const GEN_MODEL_COMPNENT = '- input - textarea - inputNumber - switch - radio - checkbox - ' +
|
|
||||||
'select - datePicker - timePicker - uploadFile - uploadImg - colorPicker - rate - slider - editor - ' +
|
|
||||||
'depSelect - posSelect - userSelect - roleSelect - areaSelect - signature - sign - location';
|
|
||||||
|
|
||||||
const GEN_MODEL_QUETION = `根据当前业务需求,设计相应的表单结构。请仅返回JSON数据,不包含其他任何形式的内容。预期结果是一个JSON数组,因涉及不同表单需求,故可能包含多个表单对象。请确保命名规避数据库与编程保留字。
|
|
||||||
所需表单应充分利用以下组件列表进行设计: ${GEN_MODEL_COMPNENT}。
|
|
||||||
参考给定的JSON格式,属性包含:中文名(tableTitle)、英文名(tableName)、是否主表(isMain, true/false)、字段列表(fields);字段列表是一个json数组,包含字段英文名(fieldName)、字段中文名(fieldTitle)、数据库类型(fieldDbType)、前端组件(fieldComponent)、字典选项(fieldOptions, 仅 radio/checkbox/select/cascader/treeSelect 必填, 格式 {id, fullName})。
|
|
||||||
创建表单结构,示例如下: [
|
|
||||||
{
|
|
||||||
"tableTitle": "商城订单",
|
|
||||||
"tableName": "online_order_form",
|
|
||||||
"isMain": true,
|
|
||||||
"fields": [
|
|
||||||
{"fieldTitle": "订单编号", "fieldName": "order_id", "fieldDbType": "varchar", "fieldComponent": "input"},
|
|
||||||
{"fieldTitle": "订单状态", "fieldName": "order_status", "fieldDbType": "int", "fieldComponent": "radio",
|
|
||||||
"fieldOptions": [{"id": "1", "fullName": "未付款"}, {"id": "2", "fullName": "已付款"}]}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"tableTitle": "订单商品明细",
|
|
||||||
"tableName": "order_item_details",
|
|
||||||
"isMain": false,
|
|
||||||
"fields": [
|
|
||||||
{"fieldTitle": "商品名称", "fieldName": "product_name", "fieldDbType": "varchar", "fieldComponent": "input"},
|
|
||||||
{"fieldTitle": "商品数量", "fieldName": "quantity", "fieldDbType": "int", "fieldComponent": "inputNumber"}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
请依据实际业务逻辑,合理选择组件与字段类型,确保设计的表单既能满足数据收集需求,又便于用户操作。`;
|
|
||||||
|
|
||||||
// ====== 加载 buildFormData ======
|
|
||||||
const WEB_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src';
|
|
||||||
let buildFormDataSrc = readFileSync(`${WEB_SRC}/components/FormGenerator/src/helper/formUtils.ts`, 'utf-8');
|
|
||||||
const JNPF_UTILS_UUID = '/home/ubuntu/ccWorkDir/web/packages/jnpf/utils/src/helpers/uuid.ts';
|
|
||||||
buildFormDataSrc = buildFormDataSrc
|
|
||||||
.replace(/from\s+['"]#\/(.+?)['"]/g, (_, p) => `from '${WEB_SRC}/${p}'`)
|
|
||||||
.replace(/from\s+['"]@jnpf\/utils['"]/g, `from '${JNPF_UTILS_UUID}'`)
|
|
||||||
.replace(/import\s*\{\s*cloneDeep\s*\}\s*from\s+['"]lodash-es['"];?/g,
|
|
||||||
`const cloneDeep = (x) => structuredClone(x);`);
|
|
||||||
|
|
||||||
const tmpDir = `${tmpdir()}/dacli-ai-jnpf-prompt-${Date.now()}`;
|
|
||||||
mkdirSync(tmpDir, { recursive: true });
|
|
||||||
writeFileSync(`${tmpDir}/formUtils.ts`, buildFormDataSrc);
|
|
||||||
const { buildFormData } = await import(pathToFileURL(`${tmpDir}/formUtils.ts`).href);
|
|
||||||
console.log('✅ buildFormData 加载成功\n');
|
|
||||||
|
|
||||||
// ====== 测试 1: 简单表单(带 select)======
|
|
||||||
const testCases = [
|
|
||||||
{
|
|
||||||
name: '简单客户表',
|
|
||||||
userInput: '当前业务需求是: 做一个简单的客户管理表,包含客户姓名、联系电话、客户类型(个人/企业)、备注。',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '主+子表(订单+明细)',
|
|
||||||
userInput: '当前业务需求是: 做一个商城订单管理。主表存订单(订单号、客户姓名、订单状态未付款/已付款/已发货),子表存订单商品明细(商品名称、商品数量)。',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const tc of testCases) {
|
|
||||||
console.log(`\n========================================`);
|
|
||||||
console.log(`=== 测试: ${tc.name} ===`);
|
|
||||||
console.log(`========================================`);
|
|
||||||
|
|
||||||
const start = Date.now();
|
|
||||||
// 用 Anthropic Messages API 格式(用户 API 走这个)
|
|
||||||
const resp = await fetch(`${BASE_URL}/v1/messages`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'x-api-key': AUTH_TOKEN,
|
|
||||||
'anthropic-version': '2023-06-01',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
model: MODEL,
|
|
||||||
max_tokens: 2000,
|
|
||||||
system: GEN_MODEL_QUETION, // Anthropic 格式:system 单独字段
|
|
||||||
messages: [
|
|
||||||
{ role: 'user', content: tc.userInput },
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
const ms = Date.now() - start;
|
|
||||||
|
|
||||||
if (!resp.ok) {
|
|
||||||
const errText = await resp.text();
|
|
||||||
console.log(`❌ HTTP ${resp.status} (${ms}ms)`);
|
|
||||||
console.log(' error:', errText.slice(0, 300));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
console.log(`✅ HTTP 200 (${ms}ms)`);
|
|
||||||
|
|
||||||
const aiResp = await resp.json();
|
|
||||||
// Anthropic 格式:content 是数组,每项 {type: 'text', text: '...'}
|
|
||||||
const text = aiResp.content
|
|
||||||
?.filter((b: any) => b.type === 'text')
|
|
||||||
.map((b: any) => b.text)
|
|
||||||
.join('\n') || '';
|
|
||||||
console.log(` usage: ${JSON.stringify(aiResp.usage)}`);
|
|
||||||
console.log(` model: ${aiResp.model}, stop_reason: ${aiResp.stop_reason}`);
|
|
||||||
|
|
||||||
// 提取 JSON
|
|
||||||
const startIdx = text.indexOf('[');
|
|
||||||
const endIdx = text.lastIndexOf(']');
|
|
||||||
if (startIdx === -1) {
|
|
||||||
console.log('❌ 响应中没找到 JSON 数组');
|
|
||||||
console.log(' text:', text.slice(0, 200));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const jsonStr = text.slice(startIdx, endIdx + 1);
|
|
||||||
let aiList;
|
|
||||||
try {
|
|
||||||
aiList = JSON.parse(jsonStr);
|
|
||||||
} catch (e: any) {
|
|
||||||
console.log('❌ JSON parse 失败:', e.message);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
console.log(` AI 返回 ${aiList.length} 张表:`);
|
|
||||||
for (const t of aiList) {
|
|
||||||
console.log(` - [${t.isMain ? '主' : '子'}] ${t.tableName} "${t.tableTitle}" (${t.fields?.length || 0} 字段)`);
|
|
||||||
for (const f of t.fields || []) {
|
|
||||||
const opts = f.fieldOptions ? ` [${f.fieldOptions.length} 选项]` : '';
|
|
||||||
console.log(` ${f.fieldName} ${f.fieldComponent} "${f.fieldTitle}"${opts}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 喂给 buildFormData
|
|
||||||
// 确保 isMain 正确(JNPF 后端靠 setIsMain(0,i==0) 强制设置)
|
|
||||||
const normalized = aiList.map((t: any, i: number) => ({
|
|
||||||
...t,
|
|
||||||
isMain: i === 0,
|
|
||||||
}));
|
|
||||||
const formDataResult = buildFormData(normalized);
|
|
||||||
const formData = JSON.parse(formDataResult.formData);
|
|
||||||
|
|
||||||
console.log(`\n buildFormData 输出:`);
|
|
||||||
console.log(` fields 数: ${formData.fields.length}`);
|
|
||||||
console.log(` formConf keys: ${Object.keys(formData).length}`);
|
|
||||||
console.log(` defaultDataForm 顶层 keys: ${Object.keys(formDataResult).filter((k: string) => k !== 'formData').length}`);
|
|
||||||
|
|
||||||
// 抽样检查
|
|
||||||
const f0 = formData.fields[0];
|
|
||||||
console.log(` 第一个 field:`);
|
|
||||||
console.log(` __vModel__: ${f0.__vModel__}`);
|
|
||||||
console.log(` __config__ keys (${Object.keys(f0.__config__).length}): ${Object.keys(f0.__config__).join(', ')}`);
|
|
||||||
console.log(` formId: ${f0.__config__.formId}`);
|
|
||||||
console.log(` renderKey: ${f0.__config__.renderKey}`);
|
|
||||||
console.log(` isSubTable: ${f0.__config__.isSubTable}`);
|
|
||||||
|
|
||||||
// select 字段验证
|
|
||||||
const selectField = formData.fields.find((f: any) =>
|
|
||||||
['select', 'radio', 'checkbox'].includes(f.options?.[0]?.id?.toString() ? f.__config__?.jnpfKey : ''));
|
|
||||||
// 简化:找 options 长度 > 0 的
|
|
||||||
const fieldWithOpts = formData.fields.find((f: any) => Array.isArray(f.options) && f.options.length > 0);
|
|
||||||
if (fieldWithOpts) {
|
|
||||||
console.log(` 含 options 的字段: ${fieldWithOpts.__vModel__} options: ${JSON.stringify(fieldWithOpts.options)}`);
|
|
||||||
} else {
|
|
||||||
console.log(` (本例无含 options 的字段)`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查主子表(如果有)
|
|
||||||
if (aiList.length > 1) {
|
|
||||||
const subTable = formData.fields.find((f: any) => f.__config__.isSubTable);
|
|
||||||
if (subTable) {
|
|
||||||
console.log(` 子表字段: ${subTable.__vModel__} parentVModel: ${subTable.__config__.parentVModel}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('\n\n=== 全部完成 ===');
|
|
||||||
console.log('✅ 结论: 用 JNPF 原版 GEN_MODEL_QUETION prompt + 直接 AI API');
|
|
||||||
console.log(' 可以完整替代 JNPF backend 的 ai/form 端点');
|
|
||||||
console.log(' 返回的 aiModelList 直接喂给 buildFormData 即可');
|
|
||||||
@@ -1,255 +0,0 @@
|
|||||||
// Task 6 端到端: 直连 AI → buildFormData → POST /api/visualdev/Base → 验证
|
|
||||||
// 跑前需要: ANTHROPIC_* env vars 已设 + dacli 已登录 (jxcj app)
|
|
||||||
|
|
||||||
import { readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
||||||
import { tmpdir } from 'os';
|
|
||||||
import { pathToFileURL } from 'url';
|
|
||||||
import { JnpfClient } from '../src/core/client.ts';
|
|
||||||
import { callAiForm } from '../src/commands/form/_ai.ts';
|
|
||||||
import { log } from '../src/core/log.ts';
|
|
||||||
|
|
||||||
// 1. 检查前置条件
|
|
||||||
if (!process.env.ANTHROPIC_BASE_URL) {
|
|
||||||
console.error('❌ ANTHROPIC_BASE_URL 未设');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('=== Task 6 端到端验证 ===');
|
|
||||||
console.log(' 链路: 直连 AI → buildFormData → POST /visualdev/Base → 浏览器');
|
|
||||||
console.log(' (JNPF 现在不用建物理表, 直接 form create 即可)');
|
|
||||||
console.log();
|
|
||||||
|
|
||||||
// 1.5 登录
|
|
||||||
const c = await JnpfClient.fromToken();
|
|
||||||
console.log(` baseUrl: ${c.baseUrl} appCode: ${c.appCode}`);
|
|
||||||
|
|
||||||
// 2. 加载 buildFormData (用前面验证过的 import 机制)
|
|
||||||
const WEB_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src';
|
|
||||||
let buildFormDataSrc = readFileSync(`${WEB_SRC}/components/FormGenerator/src/helper/formUtils.ts`, 'utf-8');
|
|
||||||
const JNPF_UTILS_UUID = '/home/ubuntu/ccWorkDir/web/packages/jnpf/utils/src/helpers/uuid.ts';
|
|
||||||
buildFormDataSrc = buildFormDataSrc
|
|
||||||
.replace(/from\s+['"]#\/(.+?)['"]/g, (_, p) => `from '${WEB_SRC}/${p}'`)
|
|
||||||
.replace(/from\s+['"]@jnpf\/utils['"]/g, `from '${JNPF_UTILS_UUID}'`)
|
|
||||||
.replace(/import\s*\{\s*cloneDeep\s*\}\s*from\s+['"]lodash-es['"];?/g,
|
|
||||||
`const cloneDeep = (x) => structuredClone(x);`);
|
|
||||||
|
|
||||||
const tmpDir = `${tmpdir()}/dacli-e2e-${Date.now()}`;
|
|
||||||
mkdirSync(tmpDir, { recursive: true });
|
|
||||||
const tmpBuildFile = `${tmpDir}/formUtils.ts`;
|
|
||||||
writeFileSync(tmpBuildFile, buildFormDataSrc);
|
|
||||||
const { buildFormData } = await import(pathToFileURL(tmpBuildFile).href);
|
|
||||||
console.log('✅ buildFormData 加载成功');
|
|
||||||
|
|
||||||
// 3. 调直连 AI
|
|
||||||
console.log('\n=== Step 1: 调直连 AI ===');
|
|
||||||
const prompt = '做一个简单的图书管理表:书名(单行文本)、作者(单行文本)、出版日期(日期选择器)、是否上架(开关)';
|
|
||||||
const aiResp = await callAiForm(prompt);
|
|
||||||
console.log(` ✅ AI 返回: enCode=${aiResp.enCode} fullName=${aiResp.fullName}`);
|
|
||||||
console.log(` ✅ aiModelList: ${aiResp.aiModelList?.length || 0} 张表`);
|
|
||||||
const mainTable = aiResp.aiModelList?.[0];
|
|
||||||
if (!mainTable) {
|
|
||||||
console.error('❌ AI 没返回表');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
console.log(` ✅ 主表: ${mainTable.tableName} (${mainTable.fields?.length || 0} 字段)`);
|
|
||||||
for (const f of mainTable.fields || []) {
|
|
||||||
console.log(` - ${f.fieldName} ${f.fieldComponent} "${f.fieldTitle}"`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. buildFormData 构造 formData
|
|
||||||
console.log('\n=== Step 2: buildFormData 构造 formData ===');
|
|
||||||
const formDataResult = buildFormData(aiResp.aiModelList!);
|
|
||||||
const formData = JSON.parse(formDataResult.formData);
|
|
||||||
console.log(` ✅ formData.fields: ${formData.fields.length}`);
|
|
||||||
console.log(` ✅ 第一个 field 的 formId: ${formData.fields[0].__config__.formId}`);
|
|
||||||
console.log(` ✅ 第一个 field 的 renderKey: ${formData.fields[0].__config__.renderKey}`);
|
|
||||||
|
|
||||||
// 5. 构造 create body
|
|
||||||
const enCode = `e2e_${Date.now().toString(36).slice(-6)}`; // 避免 enCode 重复
|
|
||||||
const fullName = 'E2E 测试图书表';
|
|
||||||
|
|
||||||
// 5. 构造 create body (用最小化 columnData + tables)
|
|
||||||
|
|
||||||
// 最小 columnData (用 form 自己的 fields 填充)
|
|
||||||
const columnList = mainTable.fields!.map((f: any) => ({
|
|
||||||
label: f.fieldTitle,
|
|
||||||
labelI18nCode: '',
|
|
||||||
prop: f.fieldName,
|
|
||||||
fixed: 'none',
|
|
||||||
headerAlign: 'left',
|
|
||||||
align: 'left',
|
|
||||||
sortable: false,
|
|
||||||
width: null,
|
|
||||||
jnpfKey: f.fieldComponent,
|
|
||||||
id: f.fieldName,
|
|
||||||
fullName: f.fieldTitle,
|
|
||||||
fullNameI18nCode: [''],
|
|
||||||
clearable: true,
|
|
||||||
disabled: false,
|
|
||||||
readonly: false,
|
|
||||||
placeholder: '请输入',
|
|
||||||
style: { width: '100%' },
|
|
||||||
on: { change: '...' },
|
|
||||||
__vModel__: f.fieldName,
|
|
||||||
__config__: {
|
|
||||||
jnpfKey: f.fieldComponent,
|
|
||||||
tag: 'JnpfInput',
|
|
||||||
tagIcon: 'icon-ym icon-ym-generator-input',
|
|
||||||
label: f.fieldTitle,
|
|
||||||
showLabel: true,
|
|
||||||
tipLabel: '',
|
|
||||||
labelWidth: undefined,
|
|
||||||
tableAlign: 'left',
|
|
||||||
tableFixed: 'none',
|
|
||||||
className: [],
|
|
||||||
defaultValue: '',
|
|
||||||
required: false,
|
|
||||||
layout: 'colFormItem',
|
|
||||||
span: 24,
|
|
||||||
dragDisabled: false,
|
|
||||||
visibility: ['pc', 'app'],
|
|
||||||
tableName: enCode,
|
|
||||||
noShow: false,
|
|
||||||
regList: [],
|
|
||||||
trigger: 'change',
|
|
||||||
formId: `formItem${enCode}`,
|
|
||||||
renderKey: Date.now(),
|
|
||||||
transferList: [],
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
const columnDataObj = {
|
|
||||||
type: 1,
|
|
||||||
pageSize: 20,
|
|
||||||
ruleList: { matchLogic: 'and', conditionList: [] },
|
|
||||||
resizable: true,
|
|
||||||
showOverflow: true,
|
|
||||||
childTableStyle: 1,
|
|
||||||
showSummary: false,
|
|
||||||
summaryField: [],
|
|
||||||
columnOptions: [],
|
|
||||||
defaultColumnList: [],
|
|
||||||
defaultSortConfig: [],
|
|
||||||
viewKey: '',
|
|
||||||
hasPage: true,
|
|
||||||
hasTreeQuery: false,
|
|
||||||
hasPrint: false,
|
|
||||||
printIds: [],
|
|
||||||
printBtnPosition: 'right',
|
|
||||||
uploaderTemplateJson: {},
|
|
||||||
useColumnPermission: false,
|
|
||||||
useFormPermission: false,
|
|
||||||
useBtnPermission: false,
|
|
||||||
useDataPermission: false,
|
|
||||||
columnPermissions: [],
|
|
||||||
btnsList: [],
|
|
||||||
btnsPosition: 'right',
|
|
||||||
rowBtnsList: [],
|
|
||||||
columnBtnsList: [],
|
|
||||||
customBtnsList: [],
|
|
||||||
useCustomBtns: false,
|
|
||||||
funcs: { afterOnload: '', rowStyle: '', cellStyle: '' },
|
|
||||||
sortList: [],
|
|
||||||
useDataInterface: false,
|
|
||||||
dataInterfaceId: '',
|
|
||||||
pageSizes: [10, 20, 50, 100],
|
|
||||||
showCheckbox: false,
|
|
||||||
usePage: true,
|
|
||||||
useAdvancedQuery: true,
|
|
||||||
useFilter: true,
|
|
||||||
useSort: true,
|
|
||||||
useDragSort: true,
|
|
||||||
columnList,
|
|
||||||
searchList: [],
|
|
||||||
appColumnOptions: [],
|
|
||||||
appColumnList: [],
|
|
||||||
tabConfig: { on: false, relationField: '', hasAllTab: true },
|
|
||||||
cardListConfig: {},
|
|
||||||
complexHeaderList: [],
|
|
||||||
tableConfig: { border: true, stripe: false, size: 'default', showRadio: false, showRowNumber: true },
|
|
||||||
relationForm: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
// 最小 tables (主表 + 系统列 + 用户字段)
|
|
||||||
const userFields = mainTable.fields!.map((f: any) => ({
|
|
||||||
dataType: f.fieldDbType || 'varchar',
|
|
||||||
field: f.fieldName,
|
|
||||||
fieldName: f.fieldTitle,
|
|
||||||
primaryKey: 0,
|
|
||||||
allowNull: 1,
|
|
||||||
dataLength: '200',
|
|
||||||
}));
|
|
||||||
const tables = [
|
|
||||||
{
|
|
||||||
table: enCode,
|
|
||||||
typeId: '1',
|
|
||||||
comment: fullName,
|
|
||||||
fields: [
|
|
||||||
{ dataType: 'varchar', field: 'f_id', fieldName: '主键', primaryKey: 1, allowNull: 0, dataLength: '50' },
|
|
||||||
{ dataType: 'varchar', field: 'f_tenant_id', fieldName: '租户id', primaryKey: 1, allowNull: 0, dataLength: '50' },
|
|
||||||
...userFields,
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const body = {
|
|
||||||
fullName,
|
|
||||||
enCode,
|
|
||||||
type: 1,
|
|
||||||
webType: '2', // 2=表单+列表
|
|
||||||
category: null,
|
|
||||||
description: 'created by e2e test (direct AI + buildFormData)',
|
|
||||||
dbLinkId: c.dbLinkId, // 用 token 的 dbLinkId (业务库)
|
|
||||||
enableFlow: 0,
|
|
||||||
flowId: '',
|
|
||||||
formData: JSON.stringify(formData),
|
|
||||||
columnData: JSON.stringify(columnDataObj),
|
|
||||||
appColumnData: JSON.stringify(columnDataObj),
|
|
||||||
tables: JSON.stringify(tables),
|
|
||||||
state: 0,
|
|
||||||
sortCode: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log('\n=== Step 3: POST /api/visualdev/Base ===');
|
|
||||||
console.log(` enCode: ${enCode}`);
|
|
||||||
|
|
||||||
const start = Date.now();
|
|
||||||
const r = await c.postJson<unknown>('/visualdev/Base', body);
|
|
||||||
const ms = Date.now() - start;
|
|
||||||
console.log(` HTTP 响应: code=${r.code} ${ms}ms`);
|
|
||||||
console.log(` msg: ${r.msg || '(无)'}`);
|
|
||||||
|
|
||||||
if (r.code !== 200) {
|
|
||||||
console.error('❌ 创建失败');
|
|
||||||
console.error(JSON.stringify(r, null, 2).slice(0, 800));
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. 反查 form id
|
|
||||||
console.log('\n=== Step 4: 反查 form id ===');
|
|
||||||
const listR = await c.get<{ list: { id: string; enCode: string; fullName: string }[] }>('/visualdev/Base', {
|
|
||||||
keyword: enCode,
|
|
||||||
});
|
|
||||||
const newForm = listR.data?.list.find((f) => f.enCode === enCode);
|
|
||||||
if (!newForm) {
|
|
||||||
console.error('❌ 反查没找到');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
console.log(` ✅ 找到: id=${newForm.id} enCode=${newForm.enCode} fullName=${newForm.fullName}`);
|
|
||||||
|
|
||||||
// 7. 发布 (state=1)
|
|
||||||
console.log('\n=== Step 5: 发布 (state=1) ===');
|
|
||||||
const rr = await c.postJson(`/visualdev/Base/${newForm.id}/Actions/Release`, {});
|
|
||||||
if (rr.code !== 200) {
|
|
||||||
console.warn(` ⚠️ 发布失败: ${rr.msg}`);
|
|
||||||
} else {
|
|
||||||
console.log(` ✅ 发布成功`);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('\n=== 总结 ===');
|
|
||||||
console.log(` formId: ${newForm.id}`);
|
|
||||||
console.log(` enCode: ${enCode}`);
|
|
||||||
console.log(` fullName: ${fullName}`);
|
|
||||||
console.log(` baseUrl: ${c.baseUrl}/jnpf_app_jxcj?modelId=${newForm.id}`);
|
|
||||||
console.log(` 浏览器测试: 用 admin/123456 登录 http://nginx/jnpf_app_jxcj 看这个表单`);
|
|
||||||
console.log(`\n✅ 端到端走通: 直连 AI → buildFormData → create API → 发布`);
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
// 用 tsx 跑 + 自定义 #/ alias 解析
|
|
||||||
import { pathToFileURL } from 'url';
|
|
||||||
import { resolve as pathResolve, dirname } from 'path';
|
|
||||||
import { existsSync } from 'fs';
|
|
||||||
|
|
||||||
const WEB_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src';
|
|
||||||
|
|
||||||
// 自定义 resolve hook
|
|
||||||
export async function resolve(specifier, context, nextResolve) {
|
|
||||||
// 处理 #/ 别名
|
|
||||||
if (specifier.startsWith('#/')) {
|
|
||||||
const relPath = specifier.slice(2); // 去掉 #/
|
|
||||||
const absPath = pathResolve(WEB_SRC, relPath);
|
|
||||||
return nextResolve(pathToFileURL(absPath).href, context);
|
|
||||||
}
|
|
||||||
return nextResolve(specifier, context);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('=== Test: buildFormData via tsx + #/ resolver ===');
|
|
||||||
try {
|
|
||||||
const mod = await import('/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src/components/FormGenerator/src/helper/formUtils.ts');
|
|
||||||
console.log('✅ Imported! Exports:', Object.keys(mod));
|
|
||||||
|
|
||||||
const aiModelList = [
|
|
||||||
{
|
|
||||||
tableTitle: '客户表',
|
|
||||||
tableName: 'customer',
|
|
||||||
isMain: true,
|
|
||||||
fields: [
|
|
||||||
{ fieldTitle: '姓名', fieldName: 'f_name', fieldComponent: 'input' },
|
|
||||||
{ fieldTitle: '电话', fieldName: 'f_phone', fieldComponent: 'input' },
|
|
||||||
{ fieldTitle: '状态', fieldName: 'f_status', fieldComponent: 'select',
|
|
||||||
fieldOptions: [{id: '1', fullName: '启用'}, {id: '0', fullName: '禁用'}] },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const result = mod.buildFormData(aiModelList);
|
|
||||||
const formData = JSON.parse(result.formData);
|
|
||||||
console.log('✅ buildFormData 跑了!');
|
|
||||||
console.log(' fields 数:', formData.fields.length);
|
|
||||||
console.log(' 第一个 field 的 __vModel__:', formData.fields[0].__vModel__);
|
|
||||||
console.log(' __config__ keys (共', Object.keys(formData.fields[0].__config__).length, '个):', Object.keys(formData.fields[0].__config__));
|
|
||||||
console.log(' ⭐ formId:', formData.fields[0].__config__.formId);
|
|
||||||
console.log(' ⭐ renderKey:', formData.fields[0].__config__.renderKey);
|
|
||||||
console.log(' ⭐ isSubTable:', formData.fields[0].__config__.isSubTable);
|
|
||||||
|
|
||||||
const statusField = formData.fields.find(f => f.__vModel__ === 'f_status');
|
|
||||||
console.log(' select 组件 options:', JSON.stringify(statusField?.options));
|
|
||||||
|
|
||||||
// 看顶层 defaultDataForm
|
|
||||||
console.log('\n defaultDataForm 顶层 keys:', Object.keys(result).filter(k => k !== 'formData'));
|
|
||||||
console.log(' tables:', result.tables);
|
|
||||||
console.log(' webType:', result.webType);
|
|
||||||
console.log(' state:', result.state);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('❌ Failed:', e.message);
|
|
||||||
console.error('Stack:', e.stack?.split('\n').slice(0, 5).join('\n'));
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
// 预处理 formUtils.ts:把 #/ 路径替换成绝对路径,然后 import
|
|
||||||
import { readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
||||||
import { dirname, resolve } from 'path';
|
|
||||||
import { pathToFileURL } from 'url';
|
|
||||||
import { tmpdir } from 'os';
|
|
||||||
|
|
||||||
const WEB_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src';
|
|
||||||
const SRC = `${WEB_SRC}/components/FormGenerator/src/helper/formUtils.ts`;
|
|
||||||
|
|
||||||
// 1. 读源
|
|
||||||
let src = readFileSync(SRC, 'utf-8');
|
|
||||||
|
|
||||||
// 2. 替换 #/ 为绝对路径,@jnpf/utils 替换成 web 端本地 uuid.ts(避开 Vite env 依赖)
|
|
||||||
const JNPF_UTILS_UUID = '/home/ubuntu/ccWorkDir/web/packages/jnpf/utils/src/helpers/uuid.ts';
|
|
||||||
src = src.replace(/from\s+['"]#\/(.+?)['"]/g, (_, p) => `from '${WEB_SRC}/${p}'`);
|
|
||||||
src = src.replace(/from\s+['"]@jnpf\/utils['"]/g, `from '${JNPF_UTILS_UUID}'`);
|
|
||||||
// 3. lodash-es 替换成 Node 内置 structuredClone(formUtils.ts 只用 cloneDeep)
|
|
||||||
src = src.replace(/import\s*\{\s*cloneDeep\s*\}\s*from\s+['"]lodash-es['"];?/g,
|
|
||||||
`const cloneDeep = (x) => structuredClone(x);`);
|
|
||||||
|
|
||||||
console.log('=== 替换后的 formUtils.ts 头 10 行 ===');
|
|
||||||
console.log(src.split('\n').slice(0, 15).join('\n'));
|
|
||||||
console.log('...\n');
|
|
||||||
|
|
||||||
// 3. 写到 /tmp
|
|
||||||
const tmpDir = `${tmpdir()}/dacli-test-${Date.now()}`;
|
|
||||||
mkdirSync(tmpDir, { recursive: true });
|
|
||||||
const tmpFile = `${tmpDir}/formUtils-fixed.ts`;
|
|
||||||
writeFileSync(tmpFile, src);
|
|
||||||
console.log('=== 写到:', tmpFile, '===\n');
|
|
||||||
|
|
||||||
// 4. 动态 import
|
|
||||||
try {
|
|
||||||
const mod = await import(pathToFileURL(tmpFile).href);
|
|
||||||
console.log('✅ Imported! Exports:', Object.keys(mod));
|
|
||||||
|
|
||||||
const aiModelList = [
|
|
||||||
{
|
|
||||||
tableTitle: '客户表',
|
|
||||||
tableName: 'customer',
|
|
||||||
isMain: true,
|
|
||||||
fields: [
|
|
||||||
{ fieldTitle: '姓名', fieldName: 'f_name', fieldComponent: 'input' },
|
|
||||||
{ fieldTitle: '电话', fieldName: 'f_phone', fieldComponent: 'input' },
|
|
||||||
{ fieldTitle: '状态', fieldName: 'f_status', fieldComponent: 'select',
|
|
||||||
fieldOptions: [{id: '1', fullName: '启用'}, {id: '0', fullName: '禁用'}] },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const result = mod.buildFormData(aiModelList);
|
|
||||||
const formData = JSON.parse(result.formData);
|
|
||||||
|
|
||||||
console.log('\n✅ buildFormData 调用成功!');
|
|
||||||
console.log(' defaultDataForm 顶层 keys:', Object.keys(result).filter(k => k !== 'formData'));
|
|
||||||
console.log(' formData.fields 数:', formData.fields.length);
|
|
||||||
console.log(' formConf 顶层 keys (前 10):', Object.keys(formData).slice(0, 10));
|
|
||||||
|
|
||||||
console.log('\n=== 第一个 field 详细结构 ===');
|
|
||||||
const f0 = formData.fields[0];
|
|
||||||
console.log(' __vModel__:', f0.__vModel__);
|
|
||||||
console.log(' __config__ 键数:', Object.keys(f0.__config__).length);
|
|
||||||
console.log(' __config__ keys:', Object.keys(f0.__config__).join(', '));
|
|
||||||
console.log(' ⭐ formId:', f0.__config__.formId);
|
|
||||||
console.log(' ⭐ renderKey:', f0.__config__.renderKey);
|
|
||||||
console.log(' ⭐ isSubTable:', f0.__config__.isSubTable);
|
|
||||||
console.log(' ⭐ tag:', f0.__config__.tag);
|
|
||||||
console.log(' ⭐ visibility:', f0.__config__.visibility);
|
|
||||||
|
|
||||||
console.log('\n=== select 字段的 options ===');
|
|
||||||
const statusField = formData.fields.find(f => f.__vModel__ === 'f_status');
|
|
||||||
console.log(' status field options:', JSON.stringify(statusField?.options));
|
|
||||||
console.log(' status field dataType:', statusField?.__config__?.dataType);
|
|
||||||
|
|
||||||
console.log('\n=== 顶层 defaultDataForm 详情 ===');
|
|
||||||
console.log(' webType:', result.webType, '(=2 表单+列表)');
|
|
||||||
console.log(' state:', result.state, '(=1 已发布)');
|
|
||||||
console.log(' type:', result.type, '(=1 自定义)');
|
|
||||||
console.log(' dbLinkId:', result.dbLinkId, '(="0" 主库)');
|
|
||||||
console.log(' tables:', result.tables);
|
|
||||||
console.log(' columnData:', result.columnData);
|
|
||||||
|
|
||||||
console.log('\n=== 验证 BS-51/BS-54 修复 ===');
|
|
||||||
console.log(' ✅ formId 存在:', !!f0.__config__.formId);
|
|
||||||
console.log(' ✅ renderKey 存在:', !!f0.__config__.renderKey);
|
|
||||||
console.log(' ✅ isSubTable 存在:', f0.__config__.isSubTable === false);
|
|
||||||
console.log(' ✅ select 组件 options 存在:', Array.isArray(statusField?.options));
|
|
||||||
console.log(' ✅ options 不为空:', (statusField?.options?.length ?? 0) > 0);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('❌ Failed:', e.message);
|
|
||||||
console.error('Stack:', e.stack?.split('\n').slice(0, 8).join('\n'));
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user