diff --git a/src/commands/form/create.ts b/src/commands/form/create.ts index 5de7fec..c4d7cac 100644 --- a/src/commands/form/create.ts +++ b/src/commands/form/create.ts @@ -193,16 +193,63 @@ export function buildFormCreateCommand(): Command { // v0.7.1 fix (盲点 23): 必须显式 4 个 use*Permission 字段, 否则后端 VisualUtil.setPcPermission // 解开 Boolean (columnData.getUseBtnPermission().booleanValue()) NPE → 返 "System abnormality" // 见 jnpf VisualUtil.java:139 + 后端 log_error.log - const columnDataObj = { - columnOptions: [], - searchList: [], - formData: {}, + // + // v0.7.4 (盲点 50): 必传 columnList + searchList, 否则 webType≠1 (有列表) 保存报 + // "列表字段不允许为空" toast 2 次. 参考 e2eTest1 (id=836658473499370693) columnData 结构: + // columnList[0] = {label, labelI18nCode, prop, fixed, headerAlign, align, sortable, + // width, jnpfKey, __vModel__, __config__, fullName, id} + // searchList[0] = {... + sourceType, value, searchType, searchMultiple, isKeyword, noShow} + // 排除系统字段 (f_id / f_tenant_id / f_flow_* / f_sort_code / f_create_* / f_modify_* / f_description) + const SYSTEM_FIELDS = new Set([ + 'f_id', 'f_tenant_id', + 'f_flow_task_id', 'f_flow_id', 'f_flow_state', + 'f_sort_code', + 'f_create_user', 'f_create_time', 'f_modify_user', 'f_modify_time', + 'f_description', + ]) + const buildColumnListEntry = (field: any) => { + const label = field.fieldName || field.field + const prop = field.field + return { + label, labelI18nCode: '', prop, + fixed: 'none', headerAlign: 'left', align: 'left', + sortable: false, width: null, + jnpfKey: 'input', + __vModel__: prop, + __config__: { jnpfKey: 'input', label, showLabel: true, tableName: opts.enCode, formId: `formItem${opts.enCode}` }, + fullName: label, id: prop, + } + } + const buildSearchListEntry = (entry: any) => ({ + ...entry, + sourceType: 2, value: '', searchType: 1, searchMultiple: 0, isKeyword: false, noShow: false, + }) + + const columnDataObj: any = { + // type: 1=table 2=tree 3=group (JNPF 后端 parseInt, 必须 number, 不是 string) + type: 1, pageSize: 20, + showSummary: false, summaryField: '', + btnsList: [], btnsPosition: 'right', rowBtnsList: [], columnBtnsList: [], + sortList: [], + useColumnPermission: false, columnPermissions: [], + defaultSortConfig: {}, + useDataInterface: false, dataInterfaceId: '', + pageSizes: [10, 20, 50, 100], + showCheckbox: false, + usePage: true, useAdvancedQuery: true, useFilter: true, useSort: true, + useOverflow: true, useDragSort: true, + hasPrint: false, printId: '', printBtnPosition: 'right', + cardListConfig: {}, + complexHeaderList: [], complexHeaderConfig: {}, + useCustomBtns: false, customBtnsList: [], + columnList: [], searchList: [], + appColumnOptions: [], appColumnList: [], tableConfig: { border: true, stripe: false, size: 'default', showRadio: false, showRowNumber: true }, relationForm: { ' popupTable': '', columnOptions: [], searchForms: [] }, useBtnPermission: false, - useColumnPermission: false, useFormPermission: false, useDataPermission: false, + hasPage: true, hasDefaultValue: false, hasSuperQuery: false, hasTreeQuery: false, } const tables = opts.tables ? JSON.parse(opts.tables) @@ -223,6 +270,37 @@ export function buildFormCreateCommand(): Command { }, ] + // v0.7.4 (盲点 50): 自动从 tables[0].fields 生成 columnList + searchList + // 排除系统字段; 仅在 webType != 1 (有列表) 时生成; 优先取 rawFields 的 label + if (webType !== 1 && Array.isArray(tables) && tables.length > 0) { + const mainTable = tables[0] as { fields?: any[] } + const userFields = (mainTable.fields || []).filter((f: any) => f && f.field && !SYSTEM_FIELDS.has(f.field)) + if (userFields.length > 0) { + // 用 rawFields 的 label 优先 (jnpf 字段有 "控件标题"), 否则用 field.fieldName + const labelByField = new Map() + for (const rf of rawFields as any[]) { + const v = rf.__vModel__ || rf.__id__ || rf.id || rf.vmodel + const lbl = (rf.__config__ && rf.__config__.label) || rf.label || rf.fieldName + if (v && lbl) labelByField.set(v, lbl) + } + const entries = userFields.map((f: any) => { + const e = buildColumnListEntry(f) + const lbl = labelByField.get(f.field) + if (lbl) { + e.label = lbl + e.fullName = lbl + if (e.__config__) (e.__config__ as any).label = lbl + } + return e + }) + columnDataObj.columnList = entries + columnDataObj.searchList = entries.map(buildSearchListEntry) + log.info(`v0.7.4 自动生成 columnList + searchList: ${entries.length} 个字段 (排除系统字段)`) + } else { + log.warn(`v0.7.4 webType=${webType} 但 tables[0] 无用户字段, 仍可能报"列表字段不允许为空"`) + } + } + const body: Record = { fullName: opts.fullName, enCode: opts.enCode,