@stalfh233/omc-cli 0.8.35 → 0.8.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/approval-flow.js +1 -1
- package/dist/cli.js +12 -0
- package/dist/form-support.js +692 -13
- package/dist/lanes/app.js +47 -6
- package/dist/lanes/businessrule.js +24 -8
- package/dist/lanes/form-contract.js +3 -3
- package/dist/lanes/form.js +47 -14
- package/dist/lanes/runtime-data/record-write.js +18 -2
- package/dist/lanes/runtime-data/shapes.js +23 -0
- package/dist/lanes/runtime-data/submission.js +20 -0
- package/dist/lanes/runtime-data/write-support.js +112 -0
- package/dist/model-purge.js +62 -26
- package/dist/plan.js +63 -5
- package/dist/read-projection.js +42 -0
- package/dist/read-shapes.js +4 -3
- package/dist/read.js +3 -1
- package/dist/recipes/field.js +7 -3
- package/dist/recipes/form.js +51 -1
- package/dist/recipes/runtime-data.js +2 -1
- package/dist/search-index.js +4 -0
- package/dist/write-outcome.js +14 -0
- package/package.json +3 -3
- package/skills/omc-business-configuration.md +7 -6
- package/skills/omc-capabilities.md +1 -0
package/dist/form-support.js
CHANGED
|
@@ -292,6 +292,122 @@ export function repairChildTableRelationColumns(attributesJson, fields) {
|
|
|
292
292
|
}
|
|
293
293
|
return JSON.stringify(attributes);
|
|
294
294
|
}
|
|
295
|
+
function normalizeRequiredFormula(value) {
|
|
296
|
+
if (typeof value === "string") {
|
|
297
|
+
const trimmed = value.trim();
|
|
298
|
+
// "" / "false" are the platform's "not required" spellings; only a real
|
|
299
|
+
// condition (or the literal "true") is a comparable value.
|
|
300
|
+
return trimmed === "" || trimmed.toLowerCase() === "false" ? null : trimmed;
|
|
301
|
+
}
|
|
302
|
+
if (value === true)
|
|
303
|
+
return "true";
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Control-level `requiredFormula` entries on an attributes face ([] when absent/
|
|
308
|
+
* unparsable). `controlType` is the FORM control type (`type`), needed by the
|
|
309
|
+
* drift detector to tell a field control from a layout/system control that
|
|
310
|
+
* happens to reuse the same key.
|
|
311
|
+
*/
|
|
312
|
+
export function controlLevelRequiredFormulas(attributesJson) {
|
|
313
|
+
if (typeof attributesJson !== "string" || attributesJson.trim() === "")
|
|
314
|
+
return [];
|
|
315
|
+
let parsed;
|
|
316
|
+
try {
|
|
317
|
+
parsed = JSON.parse(attributesJson);
|
|
318
|
+
}
|
|
319
|
+
catch {
|
|
320
|
+
return [];
|
|
321
|
+
}
|
|
322
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
323
|
+
return [];
|
|
324
|
+
const entries = [];
|
|
325
|
+
for (const [control, raw] of Object.entries(parsed)) {
|
|
326
|
+
const options = raw?.options;
|
|
327
|
+
if (!options || typeof options !== "object" || Array.isArray(options))
|
|
328
|
+
continue;
|
|
329
|
+
const value = normalizeRequiredFormula(options.requiredFormula);
|
|
330
|
+
if (value === null)
|
|
331
|
+
continue;
|
|
332
|
+
const rawType = raw?.type;
|
|
333
|
+
const controlType = Number(rawType);
|
|
334
|
+
entries.push({ control, value, ...(Number.isInteger(controlType) ? { controlType } : {}) });
|
|
335
|
+
}
|
|
336
|
+
return entries;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Compare control-level conditions with the published field face. Controls that
|
|
340
|
+
* are not top-level published fields (sub-table columns, system/custom controls)
|
|
341
|
+
* are skipped: their authority is not the field face. CHILD_TABLE parents are
|
|
342
|
+
* skipped too — their field-level `options` are dropped by the platform
|
|
343
|
+
* (r60a-F8), so the control face is the documented exception there.
|
|
344
|
+
*/
|
|
345
|
+
export async function detectRequiredFormulaDrift(session, args) {
|
|
346
|
+
const controlLevel = controlLevelRequiredFormulas(args.attributesJson);
|
|
347
|
+
if (controlLevel.length === 0)
|
|
348
|
+
return { drift: [] };
|
|
349
|
+
let fields = args.fields;
|
|
350
|
+
if (fields === undefined) {
|
|
351
|
+
try {
|
|
352
|
+
const rows = wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode: args.schemaCode, isPublish: "true" } })).data);
|
|
353
|
+
fields = rows.map((row) => {
|
|
354
|
+
const fieldOptions = decodeJsonObjectColumn(row.options, { invalid: "throw", array: "accept", object: "accept" });
|
|
355
|
+
return {
|
|
356
|
+
code: String(row.code ?? row.propertyCode ?? ""),
|
|
357
|
+
type: Number(row.type ?? row.propertyType),
|
|
358
|
+
...(fieldOptions !== undefined ? { fieldOptions } : {}),
|
|
359
|
+
...(row.propertyEmpty === true ? { propertyEmpty: true } : {}),
|
|
360
|
+
};
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
365
|
+
return { drift: [], unknown: reason.slice(0, 160) };
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const byCode = new Map(fields.map((field) => [field.code, field]));
|
|
369
|
+
const drift = [];
|
|
370
|
+
for (const entry of controlLevel) {
|
|
371
|
+
const field = byCode.get(entry.control);
|
|
372
|
+
if (field === undefined)
|
|
373
|
+
continue;
|
|
374
|
+
if (field.type === 8)
|
|
375
|
+
continue;
|
|
376
|
+
// A control is only comparable when it IS this field's form control. A
|
|
377
|
+
// layout/system control that reuses a field code (custom container, title,
|
|
378
|
+
// system row) has its own authority; comparing it would be a false alarm.
|
|
379
|
+
const expectedControlType = FIELD_CONTROL_TYPES[field.type];
|
|
380
|
+
if (expectedControlType === undefined || entry.controlType !== expectedControlType)
|
|
381
|
+
continue;
|
|
382
|
+
const fieldLevel = normalizeRequiredFormula(field.fieldOptions?.requiredFormula)
|
|
383
|
+
?? (field.propertyEmpty === true ? "true" : null);
|
|
384
|
+
// Unconditional required ("true") is derived from the field's propertyEmpty,
|
|
385
|
+
// and some read faces omit that write-only key. Claiming drift from an
|
|
386
|
+
// absent field value would be a false alarm — only conditional expressions
|
|
387
|
+
// (the ticket's subject) are compared on an unreadable field flag.
|
|
388
|
+
if (fieldLevel === null && entry.value === "true")
|
|
389
|
+
continue;
|
|
390
|
+
if (fieldLevel === entry.value)
|
|
391
|
+
continue;
|
|
392
|
+
drift.push({ control: entry.control, fieldLevel, controlLevel: entry.value });
|
|
393
|
+
}
|
|
394
|
+
return { drift };
|
|
395
|
+
}
|
|
396
|
+
/** Receipt projection shared by form.draft / form.publish. */
|
|
397
|
+
export function requiredFormulaDriftReadback(report) {
|
|
398
|
+
if (report.unknown !== undefined) {
|
|
399
|
+
return {
|
|
400
|
+
requiredFormulaDriftUnknown: true,
|
|
401
|
+
requiredFormulaDriftNote: `控件级 requiredFormula 已存在,但字段级读取失败(${report.unknown})——无法判定权威面对齐,本次不阻断。字段级 options.requiredFormula 才是权威面;控件级是派生面(设计器保存会按字段元数据/规则行重建控件)。稍后重读 field.list 核对。`,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
if (report.drift.length === 0)
|
|
405
|
+
return {};
|
|
406
|
+
return {
|
|
407
|
+
requiredFormulaDrift: report.drift,
|
|
408
|
+
requiredFormulaDriftNote: "字段级 options.requiredFormula 是权威面;控件级 requiredFormula 是派生面——平台设计器保存会按字段元数据/规则行重建控件,手工写控件级会被清空。改条件请写字段级:omc call field.update(自动配对 bizdatarule type4)→ form.publish rebuild:true 刷新控件。",
|
|
409
|
+
};
|
|
410
|
+
}
|
|
295
411
|
export function syncFieldDerivedControlOptions(attributesJson, fields) {
|
|
296
412
|
let attributes;
|
|
297
413
|
try {
|
|
@@ -620,14 +736,7 @@ export function formulaBearingControlOptions(face) {
|
|
|
620
736
|
* artifact or pass the layout explicitly.
|
|
621
737
|
*/
|
|
622
738
|
export function assertFormulasSurvivedRebuild(next, baseline, where) {
|
|
623
|
-
const lost =
|
|
624
|
-
for (const [code, optionKeys] of formulaBearingControlOptions(baseline)) {
|
|
625
|
-
const options = next[code]?.options;
|
|
626
|
-
const current = options && typeof options === "object" && !Array.isArray(options) ? options : {};
|
|
627
|
-
for (const key of optionKeys)
|
|
628
|
-
if (!nonEmptyExpression(current[key]))
|
|
629
|
-
lost.push({ control: code, option: key });
|
|
630
|
-
}
|
|
739
|
+
const lost = formulaLosses(next, baseline);
|
|
631
740
|
if (lost.length === 0)
|
|
632
741
|
return;
|
|
633
742
|
throw new ToolRefusalError({
|
|
@@ -678,6 +787,503 @@ export function preserveDesignerControlOptions(next, previous) {
|
|
|
678
787
|
}
|
|
679
788
|
return preserved;
|
|
680
789
|
}
|
|
790
|
+
/**
|
|
791
|
+
* GitLab issue #57(CloudPivot 8.1.108 真机):表单**非字段控件**(设计器布局控件)
|
|
792
|
+
* 没有任何可写路径,`form.publish rebuild:true` 还会把它们静默清掉。
|
|
793
|
+
*
|
|
794
|
+
* 证据:
|
|
795
|
+
* - 前端控件枚举 `admin/src/template/template.ts:185`(`'a-description': 202`;
|
|
796
|
+
* 200 分组标题 / 203 表单标题),设计器控件面板把 200/202/203 归「布局控件」
|
|
797
|
+
* (frontend-dist/admin/js/20156.9cbebcd2.js:`{type:y.jM.Group,name:"分组标题"}` /
|
|
798
|
+
* `{type:y.jM.Description,name:"描述说明"}`)。
|
|
799
|
+
* - 描述说明的正文是 `options.name`(移动端渲染 `domProps:{innerHTML:...}`,
|
|
800
|
+
* frontend-dist/admin/js/20156.9cbebcd2.js 的 `h3-moilbe-view-common-description-title`
|
|
801
|
+
* 分支;`headStyle` 对 Group/Description 读 `options.align` + `options.styleInfo`)。
|
|
802
|
+
* - 后端枚举 `BizFormPropertyType.java:10-51` **没有** 200/202/203——它们不是数据
|
|
803
|
+
* 属性,只是 attributes/view 里的前端布局控件;publish 逐字复制草稿面
|
|
804
|
+
* (`AppIntegrationFacadeImpl.java:2725-2728`),平台不校验其形状。
|
|
805
|
+
*
|
|
806
|
+
* 未知项(需 8.1.108 真机采样):设计器新建描述块时除 name/align/styleInfo/span
|
|
807
|
+
* 之外还会写哪些 options 键。本模块只写渲染必需键,改已有控件时其余 options 原样保留。
|
|
808
|
+
*/
|
|
809
|
+
export const FORM_DECORATION_TYPES = new Set([200, 202, 203]);
|
|
810
|
+
export const FORM_DECORATION_TYPE_NAMES = Object.freeze({ 200: "分组标题", 202: "描述说明", 203: "表单标题" });
|
|
811
|
+
const DECORATION_KEY_PREFIX = Object.freeze({ 200: "Group", 202: "Description", 203: "Title" });
|
|
812
|
+
function parseControlFace(face) {
|
|
813
|
+
if (typeof face !== "string" || face.trim() === "")
|
|
814
|
+
return undefined;
|
|
815
|
+
try {
|
|
816
|
+
const parsed = JSON.parse(face);
|
|
817
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
|
|
818
|
+
return undefined;
|
|
819
|
+
return parsed;
|
|
820
|
+
}
|
|
821
|
+
catch {
|
|
822
|
+
return undefined;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
function decorationTypeName(type) {
|
|
826
|
+
return FORM_DECORATION_TYPE_NAMES[type] ?? `type ${type}`;
|
|
827
|
+
}
|
|
828
|
+
function decorationControlType(control) {
|
|
829
|
+
const type = Number(control?.type);
|
|
830
|
+
return Number.isInteger(type) ? type : undefined;
|
|
831
|
+
}
|
|
832
|
+
function decorationNameOf(control) {
|
|
833
|
+
const name = control?.options?.name;
|
|
834
|
+
return typeof name === "string" ? name : undefined;
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* `form.get` 的非字段控件摘要。体积有界:单条 HTML 最多 400 字符,整表 JSON
|
|
838
|
+
* ≤1800B;超了就把 `html` 换成 `htmlPresent:true + htmlBytes`(正文用
|
|
839
|
+
* `form.get full:true` + artifact 取 `draftAttributesJson`),绝不把大 HTML
|
|
840
|
+
* 塞进默认面。`row` 是 1-based(与 `draftViewJson` 的行序一致)。
|
|
841
|
+
*/
|
|
842
|
+
export function summarizeFormDecorations(attributesJson, viewJson, options = {}) {
|
|
843
|
+
const attributes = parseControlFace(attributesJson);
|
|
844
|
+
if (attributes === undefined)
|
|
845
|
+
return { decorations: [], truncated: 0 };
|
|
846
|
+
const rows = layoutRowsOf(viewJson) ?? [];
|
|
847
|
+
const rowOf = new Map();
|
|
848
|
+
rows.forEach((row, index) => { for (const code of row)
|
|
849
|
+
if (!rowOf.has(code))
|
|
850
|
+
rowOf.set(code, index + 1); });
|
|
851
|
+
const htmlLimit = options.htmlLimit ?? 400;
|
|
852
|
+
const totalBudget = options.totalBudget ?? 1800;
|
|
853
|
+
const decorations = [];
|
|
854
|
+
for (const [key, control] of Object.entries(attributes)) {
|
|
855
|
+
const type = decorationControlType(control);
|
|
856
|
+
if (type === undefined || !FORM_DECORATION_TYPES.has(type))
|
|
857
|
+
continue;
|
|
858
|
+
const optionsFace = control.options;
|
|
859
|
+
const name = decorationNameOf(control);
|
|
860
|
+
const span = Number(optionsFace?.span ?? NaN);
|
|
861
|
+
const row = rowOf.get(key);
|
|
862
|
+
const item = {
|
|
863
|
+
key,
|
|
864
|
+
type,
|
|
865
|
+
typeName: decorationTypeName(type),
|
|
866
|
+
...(type === 202 && name !== undefined ? { html: name, htmlPresent: true, htmlBytes: Buffer.byteLength(name, "utf8") } : {}),
|
|
867
|
+
...(type !== 202 && name !== undefined ? { name } : {}),
|
|
868
|
+
...(Number.isInteger(span) ? { span } : {}),
|
|
869
|
+
...(row !== undefined ? { row } : {}),
|
|
870
|
+
};
|
|
871
|
+
if (type === 202 && typeof item.html === "string" && item.html.length > htmlLimit) {
|
|
872
|
+
item.html = item.html.slice(0, htmlLimit);
|
|
873
|
+
item.htmlTruncated = true;
|
|
874
|
+
}
|
|
875
|
+
decorations.push(item);
|
|
876
|
+
}
|
|
877
|
+
let truncated = 0;
|
|
878
|
+
// 预算:先从尾部剥 html(而不是整条丢弃),保留 key/type/row 这些定位信息。
|
|
879
|
+
for (let index = decorations.length - 1; index >= 0 && Buffer.byteLength(JSON.stringify(decorations), "utf8") > totalBudget; index -= 1) {
|
|
880
|
+
const item = decorations[index];
|
|
881
|
+
if (item?.html === undefined)
|
|
882
|
+
continue;
|
|
883
|
+
delete item.html;
|
|
884
|
+
delete item.htmlTruncated;
|
|
885
|
+
item.htmlPresent = true;
|
|
886
|
+
truncated += 1;
|
|
887
|
+
}
|
|
888
|
+
// 行数上限:真实客户表单可能有几十个分组标题;默认面必须有界。完整清单在
|
|
889
|
+
// full:true 的 attributes 里。
|
|
890
|
+
const MAX_ROWS = 20;
|
|
891
|
+
let omitted = 0;
|
|
892
|
+
while (decorations.length > MAX_ROWS) {
|
|
893
|
+
decorations.pop();
|
|
894
|
+
omitted += 1;
|
|
895
|
+
}
|
|
896
|
+
while (decorations.length > 1 && Buffer.byteLength(JSON.stringify(decorations), "utf8") > totalBudget) {
|
|
897
|
+
decorations.pop();
|
|
898
|
+
omitted += 1;
|
|
899
|
+
}
|
|
900
|
+
const note = [
|
|
901
|
+
truncated > 0
|
|
902
|
+
? `${truncated} 条描述块 HTML 超出内联预算未内联(htmlPresent:true)——正文用 form.get full:true 后 artifact get <detailArtifactId> --jq 'draftAttributesJson["<key>"].options.name'`
|
|
903
|
+
: "",
|
|
904
|
+
omitted > 0 ? `另有 ${omitted} 个布局控件未内联(上限 20 条/1800B)——完整清单见 full:true 的 draftAttributesJson/publishedAttributesJson` : "",
|
|
905
|
+
].filter((part) => part !== "").join(";");
|
|
906
|
+
return { decorations, truncated, ...(note !== "" ? { note } : {}) };
|
|
907
|
+
}
|
|
908
|
+
/** 下一个可用的布局控件 key(与既有 key 不冲突;按类型前缀 + 递增序号)。 */
|
|
909
|
+
function nextDecorationKey(attributes, type) {
|
|
910
|
+
const prefix = DECORATION_KEY_PREFIX[type] ?? "Decoration";
|
|
911
|
+
let max = 0;
|
|
912
|
+
for (const key of Object.keys(attributes)) {
|
|
913
|
+
// 只把「短序号」当序号:脚手架键是 `Group<13位 Date.now()>`,若把它算进 max,
|
|
914
|
+
// 下一个生成的就是 Group<ts+1>——看起来像脚手架自动键,丢失清单也难区分。
|
|
915
|
+
const match = new RegExp(`^${prefix}(\\d{1,9})$`).exec(key);
|
|
916
|
+
if (match)
|
|
917
|
+
max = Math.max(max, Number(match[1]));
|
|
918
|
+
}
|
|
919
|
+
let next = max + 1;
|
|
920
|
+
while (attributes[`${prefix}${next}`] !== undefined)
|
|
921
|
+
next += 1;
|
|
922
|
+
return `${prefix}${next}`;
|
|
923
|
+
}
|
|
924
|
+
function decorationDefaultOptions(type, name, span) {
|
|
925
|
+
if (type === 200)
|
|
926
|
+
return {
|
|
927
|
+
name, tips: "", expand: true, align: "", style: "", span,
|
|
928
|
+
styleInfo: { fontSize: 18, textColor: "#111218", blod: true, italic: false, textCss: "", textCssSwitch: false },
|
|
929
|
+
};
|
|
930
|
+
if (type === 203)
|
|
931
|
+
return {
|
|
932
|
+
name, name_i18n: {}, visible: true, labelVisible: true, span, labelAlign: "", style: "", tips: "", dataItemName: "", useDataTitle: false,
|
|
933
|
+
styleInfo: { height: 1, bgColor: "#ffffff", bgImg: "", textAlign: "center", fontSize: 28, textColor: "#111218", blod: true, italic: false, textCss: "", textCssSwitch: false },
|
|
934
|
+
};
|
|
935
|
+
return {
|
|
936
|
+
name, name_i18n: {}, visible: true, labelVisible: true, span, align: "", tips: "", displayFormula: "",
|
|
937
|
+
styleInfo: { fontSize: 14, textColor: "#111218", bgColor: "#ffffff", blod: false, italic: false, textCss: "", textCssSwitch: false, bgCss: "", bgCssSwitch: false, borderRadius: 2 },
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
function spanOfControl(control) {
|
|
941
|
+
const raw = Number(control?.options?.span);
|
|
942
|
+
return Number.isInteger(raw) ? raw : FULL_SPAN;
|
|
943
|
+
}
|
|
944
|
+
function rowSpanTotal(rows, attributes, rowIndex, ignore) {
|
|
945
|
+
return (rows[rowIndex] ?? []).filter((code) => code !== ignore).reduce((sum, code) => sum + spanOfControl(attributes[code]), 0);
|
|
946
|
+
}
|
|
947
|
+
function layoutViolationKey(violation) {
|
|
948
|
+
return `${violation.classification}|${violation.field ?? ""}|${violation.row ?? ""}|${violation.span ?? ""}`;
|
|
949
|
+
}
|
|
950
|
+
function insertDecorationRow(rows, rowIndex, key) {
|
|
951
|
+
if (rowIndex >= rows.length)
|
|
952
|
+
rows.push([key]);
|
|
953
|
+
else
|
|
954
|
+
rows[rowIndex].push(key);
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* `form.draft {decorations:[...]}`:与 `layout` 同形的增量面——以当前草稿
|
|
958
|
+
* (为空/与发布面逐字相同则退回发布面)为基线,只增/改布局控件,不碰其它控件。
|
|
959
|
+
* dry-run(writeLint)与真写共用本函数,所以预览里的 `decorations` 回执就是
|
|
960
|
+
* 真写会写下的控件。
|
|
961
|
+
*/
|
|
962
|
+
export async function composeFormDecorationsDraft(session, args) {
|
|
963
|
+
const sheet = await readFormOrNull(session, args.schemaCode, args.sheetCode);
|
|
964
|
+
const usable = (value) => typeof value === "string" && value.trim() !== "" && value.trim() !== "{}" && value.trim() !== "[]" ? value : undefined;
|
|
965
|
+
const baseAttributesJson = usable(sheet?.draftAttributesJson) ?? usable(sheet?.publishedAttributesJson);
|
|
966
|
+
const baseViewJson = usable(sheet?.draftViewJson) ?? usable(sheet?.publishedViewJson);
|
|
967
|
+
if (baseAttributesJson === undefined)
|
|
968
|
+
throw new ToolRefusalError({
|
|
969
|
+
status: "refused",
|
|
970
|
+
blocker: "form-decorations-no-baseline",
|
|
971
|
+
schemaCode: args.schemaCode,
|
|
972
|
+
sheetCode: args.sheetCode,
|
|
973
|
+
message: `表单 ${args.sheetCode} 还没有可作基线的控件面(草稿/发布面的 attributes 都为空):decorations 是**增量**面,必须先把字段绑进表单(form.draft / configure_form),再用 form.draft {decorations} 加描述块。`,
|
|
974
|
+
});
|
|
975
|
+
const parsedAttributes = parseControlFace(baseAttributesJson);
|
|
976
|
+
if (parsedAttributes === undefined)
|
|
977
|
+
throw new ToolRefusalError({
|
|
978
|
+
status: "refused",
|
|
979
|
+
blocker: "form-decorations-baseline-unreadable",
|
|
980
|
+
schemaCode: args.schemaCode,
|
|
981
|
+
sheetCode: args.sheetCode,
|
|
982
|
+
message: "已有表单的 draftAttributesJson 不是合法 JSON 对象,无法增量合并布局控件;先按 `omc call form.get` 的原文修复布局",
|
|
983
|
+
});
|
|
984
|
+
const attributes = parsedAttributes;
|
|
985
|
+
const parsedRows = layoutRowsOf(baseViewJson);
|
|
986
|
+
const warnings = [];
|
|
987
|
+
let rows = parsedRows !== undefined ? parsedRows.map((row) => [...row]) : [];
|
|
988
|
+
const beforeViolations = new Set(validateFormLayout(rows, attributes).map(layoutViolationKey));
|
|
989
|
+
if (parsedRows === undefined) {
|
|
990
|
+
rows = Object.keys(attributes).map((code) => [code]);
|
|
991
|
+
warnings.push({ classification: "layout_coverage_mismatch", message: "基线 draftViewJson 缺失或不是二维数组:已按 attributes 顺序临时补行分组(每控件一行),回读请核对布局" });
|
|
992
|
+
}
|
|
993
|
+
// 覆盖自洽:平台自身布局偶有 attrs 有控件而 rows 未列(历史数据),补到末行才
|
|
994
|
+
// 能通过 validateFormLayout 的覆盖门,且不改变既有行的相对顺序。
|
|
995
|
+
const inRows = new Set(rows.flat());
|
|
996
|
+
for (const code of Object.keys(attributes)) {
|
|
997
|
+
if (inRows.has(code))
|
|
998
|
+
continue;
|
|
999
|
+
rows.push([code]);
|
|
1000
|
+
warnings.push({ classification: "layout_coverage_mismatch", message: `基线 viewJson 未包含控件 ${code};已补为末行(原布局未改动)` });
|
|
1001
|
+
}
|
|
1002
|
+
const added = [];
|
|
1003
|
+
const updated = [];
|
|
1004
|
+
for (const request of args.decorations) {
|
|
1005
|
+
const existingKey = typeof request.key === "string" ? request.key : undefined;
|
|
1006
|
+
const existing = existingKey !== undefined ? attributes[existingKey] : undefined;
|
|
1007
|
+
if (existingKey !== undefined && existing !== undefined && !FORM_DECORATION_TYPES.has(decorationControlType(existing) ?? -1))
|
|
1008
|
+
throw new ToolRefusalError({
|
|
1009
|
+
status: "refused",
|
|
1010
|
+
blocker: "form-decoration-not-a-layout-control",
|
|
1011
|
+
schemaCode: args.schemaCode,
|
|
1012
|
+
sheetCode: args.sheetCode,
|
|
1013
|
+
key: existingKey,
|
|
1014
|
+
controlType: decorationControlType(existing),
|
|
1015
|
+
message: `${existingKey} 是普通字段控件,不是布局控件(200 分组标题 / 202 描述说明 / 203 表单标题):decorations 只改这些;字段控件用 field.update / form.draft 的 layout`,
|
|
1016
|
+
});
|
|
1017
|
+
const type = request.type ?? (existing !== undefined ? decorationControlType(existing) : 202) ?? 202;
|
|
1018
|
+
if (!FORM_DECORATION_TYPES.has(type))
|
|
1019
|
+
throw new ToolRefusalError({
|
|
1020
|
+
status: "refused",
|
|
1021
|
+
blocker: "form-decoration-type-unknown",
|
|
1022
|
+
schemaCode: args.schemaCode,
|
|
1023
|
+
sheetCode: args.sheetCode,
|
|
1024
|
+
type,
|
|
1025
|
+
allowed: [...FORM_DECORATION_TYPES],
|
|
1026
|
+
message: `未知布局控件 type=${String(request.type)}:只支持 200(分组标题)/ 202(描述说明)/ 203(表单标题)`,
|
|
1027
|
+
});
|
|
1028
|
+
if (existing !== undefined && decorationControlType(existing) !== type)
|
|
1029
|
+
throw new ToolRefusalError({
|
|
1030
|
+
status: "refused",
|
|
1031
|
+
blocker: "form-decoration-type-mismatch",
|
|
1032
|
+
schemaCode: args.schemaCode,
|
|
1033
|
+
sheetCode: args.sheetCode,
|
|
1034
|
+
key: existingKey,
|
|
1035
|
+
existingType: decorationControlType(existing),
|
|
1036
|
+
requestedType: type,
|
|
1037
|
+
message: `控件 ${existingKey} 现为 ${decorationControlType(existing)}(${decorationTypeName(decorationControlType(existing) ?? 0)}),不能原地改成 ${type}(${decorationTypeName(type)});先删旧控件再加新控件`,
|
|
1038
|
+
});
|
|
1039
|
+
const key = existingKey ?? nextDecorationKey(attributes, type);
|
|
1040
|
+
if (attributes[key] === undefined && (rows.flat().includes(key) || key in attributes))
|
|
1041
|
+
throw new ToolRefusalError({
|
|
1042
|
+
status: "refused",
|
|
1043
|
+
blocker: "form-decoration-key-conflict",
|
|
1044
|
+
schemaCode: args.schemaCode,
|
|
1045
|
+
sheetCode: args.sheetCode,
|
|
1046
|
+
key,
|
|
1047
|
+
message: `控件 key ${key} 已被占用:换一个 key(描述块默认生成 Description<序号>)`,
|
|
1048
|
+
});
|
|
1049
|
+
// 202 的正文是 HTML(options.name);200/203 的 name 是纯文本。两者都给时按
|
|
1050
|
+
// 控件类型取语义正确的那一个,不猜「html 是不是文本」。
|
|
1051
|
+
const html = request.html;
|
|
1052
|
+
const plainName = request.name;
|
|
1053
|
+
const body = type === 202 ? html ?? plainName : plainName ?? html;
|
|
1054
|
+
if (type === 202 && (body === undefined || body.trim() === ""))
|
|
1055
|
+
throw new ToolRefusalError({
|
|
1056
|
+
status: "refused",
|
|
1057
|
+
blocker: "form-decoration-html-required",
|
|
1058
|
+
schemaCode: args.schemaCode,
|
|
1059
|
+
sheetCode: args.sheetCode,
|
|
1060
|
+
key,
|
|
1061
|
+
message: `描述说明(type 202)的正文是 options.name(HTML):decorations[] 要带 html(或 name)。红字提示例:{"type":202,"html":"<div style=\\"color:#e02020\\">如涉及二级图纸归档,需明确产品是否做小批试制</div>","span":24}`,
|
|
1062
|
+
});
|
|
1063
|
+
const previousRow = (() => {
|
|
1064
|
+
const index = rows.findIndex((row) => row.includes(key));
|
|
1065
|
+
return index >= 0 ? index : undefined;
|
|
1066
|
+
})();
|
|
1067
|
+
const requestedRow = request.row;
|
|
1068
|
+
if (requestedRow !== undefined && (!Number.isInteger(requestedRow) || requestedRow < 1 || requestedRow > rows.length + 1))
|
|
1069
|
+
throw new ToolRefusalError({
|
|
1070
|
+
status: "refused",
|
|
1071
|
+
blocker: "form-decoration-row-out-of-range",
|
|
1072
|
+
schemaCode: args.schemaCode,
|
|
1073
|
+
sheetCode: args.sheetCode,
|
|
1074
|
+
key,
|
|
1075
|
+
row: requestedRow,
|
|
1076
|
+
rowCount: rows.length,
|
|
1077
|
+
message: `row 是 1-based 行号,必须在 1..${rows.length + 1} 之间(省略 = 末尾追加一行)`,
|
|
1078
|
+
});
|
|
1079
|
+
const targetRow = requestedRow !== undefined ? requestedRow - 1 : previousRow !== undefined ? previousRow : rows.length;
|
|
1080
|
+
const isNewRow = targetRow >= rows.length || (rows[targetRow] ?? []).length === 0;
|
|
1081
|
+
const explicitSpan = request.span;
|
|
1082
|
+
if (explicitSpan !== undefined && (!Number.isInteger(explicitSpan) || !ALLOWED_SPANS.has(explicitSpan)))
|
|
1083
|
+
throw new ToolRefusalError({
|
|
1084
|
+
status: "refused",
|
|
1085
|
+
blocker: "form-decoration-span-invalid",
|
|
1086
|
+
schemaCode: args.schemaCode,
|
|
1087
|
+
sheetCode: args.sheetCode,
|
|
1088
|
+
key,
|
|
1089
|
+
span: explicitSpan,
|
|
1090
|
+
message: `span 必须是 24 栅格宽度 ${[...ALLOWED_SPANS].join("/")}(描述块整宽用 24,两列用 12)`,
|
|
1091
|
+
});
|
|
1092
|
+
let span = explicitSpan;
|
|
1093
|
+
if (span === undefined) {
|
|
1094
|
+
if (existing === undefined || isNewRow)
|
|
1095
|
+
span = FULL_SPAN;
|
|
1096
|
+
else {
|
|
1097
|
+
const used = rowSpanTotal(rows, attributes, targetRow, key);
|
|
1098
|
+
const remaining = FULL_SPAN - used;
|
|
1099
|
+
if (!ALLOWED_SPANS.has(remaining))
|
|
1100
|
+
throw new ToolRefusalError({
|
|
1101
|
+
status: "refused",
|
|
1102
|
+
blocker: "form-decoration-row-full",
|
|
1103
|
+
schemaCode: args.schemaCode,
|
|
1104
|
+
sheetCode: args.sheetCode,
|
|
1105
|
+
key,
|
|
1106
|
+
row: targetRow + 1,
|
|
1107
|
+
usedSpan: used,
|
|
1108
|
+
message: `第 ${targetRow + 1} 行已用 ${used}/24 栅格,插入布局控件后无可用的合法 span;省略 row 让描述块单独占一末行,或换一行、或显式传 span(${[...ALLOWED_SPANS].join("/")})`,
|
|
1109
|
+
});
|
|
1110
|
+
span = remaining;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
if (existing !== undefined) {
|
|
1114
|
+
const optionsFace = existing.options;
|
|
1115
|
+
if (optionsFace === undefined || typeof optionsFace !== "object" || Array.isArray(optionsFace))
|
|
1116
|
+
existing.options = decorationDefaultOptions(type, body ?? "", span);
|
|
1117
|
+
else {
|
|
1118
|
+
const optionsRecord = optionsFace;
|
|
1119
|
+
if (body !== undefined)
|
|
1120
|
+
optionsRecord.name = body;
|
|
1121
|
+
optionsRecord.span = span;
|
|
1122
|
+
}
|
|
1123
|
+
if (previousRow !== undefined && previousRow !== targetRow) {
|
|
1124
|
+
rows[previousRow] = rows[previousRow].filter((code) => code !== key);
|
|
1125
|
+
if (rows[previousRow].length === 0)
|
|
1126
|
+
rows.splice(previousRow, 1);
|
|
1127
|
+
const adjusted = targetRow > previousRow ? targetRow - 1 : targetRow;
|
|
1128
|
+
insertDecorationRow(rows, adjusted, key);
|
|
1129
|
+
}
|
|
1130
|
+
updated.push({ key, type, typeName: decorationTypeName(type) });
|
|
1131
|
+
}
|
|
1132
|
+
else {
|
|
1133
|
+
attributes[key] = { key, type, options: decorationDefaultOptions(type, body ?? "", span) };
|
|
1134
|
+
insertDecorationRow(rows, targetRow, key);
|
|
1135
|
+
added.push({ key, type, typeName: decorationTypeName(type), ...(type === 202 ? { html } : { name: body }) });
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
const afterViolations = validateFormLayout(rows, attributes);
|
|
1139
|
+
const newViolations = afterViolations.filter((violation) => !beforeViolations.has(layoutViolationKey(violation)));
|
|
1140
|
+
if (newViolations.length > 0)
|
|
1141
|
+
throw new ToolRefusalError({
|
|
1142
|
+
status: "refused",
|
|
1143
|
+
blocker: "form-decoration-layout-invalid",
|
|
1144
|
+
schemaCode: args.schemaCode,
|
|
1145
|
+
sheetCode: args.sheetCode,
|
|
1146
|
+
validation: newViolations,
|
|
1147
|
+
message: `加入布局控件后表单布局不自洽(写前零 wire 拒绝):${newViolations.map((violation) => violation.message).join(";")}`,
|
|
1148
|
+
});
|
|
1149
|
+
return {
|
|
1150
|
+
viewJson: JSON.stringify(rows),
|
|
1151
|
+
attributesJson: JSON.stringify(attributes),
|
|
1152
|
+
receipt: {
|
|
1153
|
+
added,
|
|
1154
|
+
...(updated.length > 0 ? { updated } : {}),
|
|
1155
|
+
rows: rows.map((row) => row.join("+")),
|
|
1156
|
+
...(warnings.length > 0 ? { warnings } : {}),
|
|
1157
|
+
note: "只合并布局控件(200/202/203),其它控件与行分组逐键保留;写入后仍需 form.publish 才在门户生效",
|
|
1158
|
+
},
|
|
1159
|
+
warnings,
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
/** `decorations` 是增量写面:与整包布局/重建/其它增量面互斥(零 wire 拒绝)。 */
|
|
1163
|
+
export function assertDecorationRequestConflicts(args) {
|
|
1164
|
+
if (args.decorations === undefined)
|
|
1165
|
+
return;
|
|
1166
|
+
if (Array.isArray(args.decorations) && args.decorations.length === 0)
|
|
1167
|
+
throw new ToolRefusalError({
|
|
1168
|
+
status: "refused",
|
|
1169
|
+
blocker: "form-decorations-empty",
|
|
1170
|
+
schemaCode: String(args.schemaCode ?? ""),
|
|
1171
|
+
sheetCode: String(args.sheetCode ?? args.schemaCode ?? ""),
|
|
1172
|
+
message: "decorations 是空数组:没有要写的内容。省略该参数 = 不改布局控件",
|
|
1173
|
+
});
|
|
1174
|
+
const conflictKeys = ["draftViewJson", "draftAttributesJson", "layout", "rebuild", "refreshFromFields", "fromReadback", "fieldCodes", "childColumns", "allowEmptyLayout"].filter((key) => args[key] !== undefined);
|
|
1175
|
+
if (conflictKeys.length === 0)
|
|
1176
|
+
return;
|
|
1177
|
+
throw new ToolRefusalError({
|
|
1178
|
+
status: "refused",
|
|
1179
|
+
blocker: "form-decoration-param-conflict",
|
|
1180
|
+
schemaCode: String(args.schemaCode ?? ""),
|
|
1181
|
+
sheetCode: String(args.sheetCode ?? args.schemaCode ?? ""),
|
|
1182
|
+
conflictKeys,
|
|
1183
|
+
message: `decorations 与 ${conflictKeys.join("、")} 互斥:decorations 是增量面(以当前草稿为基线,只增/改 200/202/203 布局控件),不要同时回传整包 view/attrs、不要 rebuild、不要和 layout/fieldCodes/childColumns 混用;要加描述块就只用 decorations。`,
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
export function rebuildControlLosses(baseline, next) {
|
|
1187
|
+
const byType = (face) => {
|
|
1188
|
+
const map = new Map();
|
|
1189
|
+
for (const [key, control] of Object.entries(face ?? {})) {
|
|
1190
|
+
const type = decorationControlType(control);
|
|
1191
|
+
if (type === undefined || !FORM_DECORATION_TYPES.has(type))
|
|
1192
|
+
continue;
|
|
1193
|
+
map.set(type, [...(map.get(type) ?? []), { key, control }]);
|
|
1194
|
+
}
|
|
1195
|
+
return map;
|
|
1196
|
+
};
|
|
1197
|
+
const baselineByType = byType(baseline);
|
|
1198
|
+
const nextByType = byType(next);
|
|
1199
|
+
const lost = [];
|
|
1200
|
+
for (const [type, entries] of baselineByType) {
|
|
1201
|
+
// 未给 next(dry-run 预览重建形状):202 会被保留,200/203 脚手架各重建一个。
|
|
1202
|
+
const kept = next === undefined ? (type === 202 ? entries.length : 1) : (nextByType.get(type)?.length ?? 0);
|
|
1203
|
+
const surplus = Math.max(0, entries.length - kept);
|
|
1204
|
+
if (surplus === 0)
|
|
1205
|
+
continue;
|
|
1206
|
+
const nextKeys = new Set((nextByType.get(type) ?? []).map((entry) => entry.key));
|
|
1207
|
+
// 脚手架生成的 Title<ts>/Group<ts>(Date.now(),≥10 位)会被重建(同 type),
|
|
1208
|
+
// 优先把「用户/CLI 额外加的」控件报为丢失项——否则回执会把自动生成的标题/分组
|
|
1209
|
+
// 说成被丢(真机 2026-12-02:报 Group<13位 ts> 而真正会丢的是后来加的 Group1)。
|
|
1210
|
+
const scaffoldLike = (key) => /^(Title|Group)\d{10,}$/.test(key);
|
|
1211
|
+
const candidates = [
|
|
1212
|
+
...entries.filter((entry) => !scaffoldLike(entry.key)),
|
|
1213
|
+
...entries.filter((entry) => scaffoldLike(entry.key)),
|
|
1214
|
+
];
|
|
1215
|
+
for (const entry of candidates.slice(0, surplus)) {
|
|
1216
|
+
const name = decorationNameOf(entry.control);
|
|
1217
|
+
lost.push({
|
|
1218
|
+
control: entry.key,
|
|
1219
|
+
type,
|
|
1220
|
+
typeName: decorationTypeName(type),
|
|
1221
|
+
...(name !== undefined ? { name: name.length > 80 ? `${name.slice(0, 80)}…` : name } : {}),
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
return lost;
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* 重建保留描述块(type 202):描述块是自包含的展示控件,原样搬回(含
|
|
1229
|
+
* displayFormula/visible/styleInfo/span)不会破坏字段控件;追加到末行保证不
|
|
1230
|
+
* 与脚手架行冲突。200/203 的额外实例不属于「自包含」范围(分组标题会改变后续
|
|
1231
|
+
* 行的语义、标题由脚手架按表单名重建),因此仍由 rebuildControlLosses fail-closed。
|
|
1232
|
+
*/
|
|
1233
|
+
export function preserveDescriptionControls(attributes, rows, previous) {
|
|
1234
|
+
const preserved = [];
|
|
1235
|
+
for (const [key, control] of Object.entries(previous)) {
|
|
1236
|
+
if (decorationControlType(control) !== 202)
|
|
1237
|
+
continue;
|
|
1238
|
+
if (attributes[key] !== undefined)
|
|
1239
|
+
continue;
|
|
1240
|
+
attributes[key] = control;
|
|
1241
|
+
rows.push([key]);
|
|
1242
|
+
preserved.push(key);
|
|
1243
|
+
}
|
|
1244
|
+
return preserved;
|
|
1245
|
+
}
|
|
1246
|
+
function formulaLosses(next, baseline) {
|
|
1247
|
+
const lost = [];
|
|
1248
|
+
for (const [code, optionKeys] of formulaBearingControlOptions(baseline)) {
|
|
1249
|
+
const options = next[code]?.options;
|
|
1250
|
+
const current = options && typeof options === "object" && !Array.isArray(options) ? options : {};
|
|
1251
|
+
for (const key of optionKeys)
|
|
1252
|
+
if (!nonEmptyExpression(current[key]))
|
|
1253
|
+
lost.push({ control: code, option: key });
|
|
1254
|
+
}
|
|
1255
|
+
return lost;
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
* 重建的**统一**写前门:设计器公式(原有)与布局控件(issue #57 新增)一起裁决,
|
|
1259
|
+
* 一次拒绝把两类丢失都列出来(旧实现只列公式,描述块被静默清空)。
|
|
1260
|
+
*/
|
|
1261
|
+
export function assertRebuildPreservesDesignerFace(next, baseline, where) {
|
|
1262
|
+
const lostFormulas = formulaLosses(next, baseline);
|
|
1263
|
+
const lostControls = rebuildControlLosses(baseline, next);
|
|
1264
|
+
if (lostFormulas.length === 0 && lostControls.length === 0)
|
|
1265
|
+
return;
|
|
1266
|
+
const formulaText = lostFormulas.length > 0
|
|
1267
|
+
? `${lostFormulas.length} 处设计器公式(${lostFormulas.map((item) => `${item.control}.${item.option}`).join("、")})`
|
|
1268
|
+
: "";
|
|
1269
|
+
const controlText = lostControls.length > 0
|
|
1270
|
+
? `${lostControls.length} 个布局控件(${lostControls.map((item) => `${item.control}·${item.typeName}`).join("、")})`
|
|
1271
|
+
: "";
|
|
1272
|
+
throw new ToolRefusalError({
|
|
1273
|
+
status: "refused",
|
|
1274
|
+
blocker: lostFormulas.length > 0 ? "form-rebuild-formula-would-be-lost" : "form-rebuild-controls-would-be-lost",
|
|
1275
|
+
schemaCode: where.schemaCode,
|
|
1276
|
+
sheetCode: where.sheetCode,
|
|
1277
|
+
// 旧键原样保留(既有判据/测试按 {control, option} 读);布局控件条目另带
|
|
1278
|
+
// type/typeName/name,二者在同一数组里并列。
|
|
1279
|
+
losing: [...lostFormulas, ...lostControls],
|
|
1280
|
+
...(lostControls.length > 0 ? { losingControls: lostControls } : {}),
|
|
1281
|
+
...(lostFormulas.length > 0 ? { losingFormulas: lostFormulas } : {}),
|
|
1282
|
+
message: `重建表单会清空 ${[formulaText, controlText].filter((part) => part !== "").join(" 与 ")}——脚手架只能按字段元数据重建控件,` +
|
|
1283
|
+
`公式/条件与布局控件(描述说明/分组标题/表单标题)不在字段上。写前零 wire 拒绝,避免「回读 published:true 但内容已空」。` +
|
|
1284
|
+
`先取备份(form.get --full 或表单版本历史 /api/api/app/bizsheet/history/list),或显式传 draftAttributesJson 原布局;只改字段时不要用 cascadeRepublish/rebuild。`,
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
681
1287
|
function childTableParentControl(field) {
|
|
682
1288
|
return {
|
|
683
1289
|
key: field.code,
|
|
@@ -1392,14 +1998,29 @@ export async function lintFormPublishReadOnly(session, args) {
|
|
|
1392
1998
|
if (sheet === null)
|
|
1393
1999
|
return { wouldChange: true, sheetPresent: false, note: "表单不存在:真写会先按已发布字段造默认表单再提拔(预览不建表单)" };
|
|
1394
2000
|
const hasDraft = typeof sheet.draftViewJson === "string" && typeof sheet.draftAttributesJson === "string";
|
|
1395
|
-
if (args.rebuild === true)
|
|
2001
|
+
if (args.rebuild === true) {
|
|
2002
|
+
// issue #57:预览能确定的一件事是「哪些布局控件重建后会没有」——202 由 CLI
|
|
2003
|
+
// 原样保留,200/203 脚手架各重建一个,其余按 type 计数判丢失。真写会用同一
|
|
2004
|
+
// 判据(rebuildControlLosses)fail-closed,所以预览不是猜。
|
|
2005
|
+
const baseline = parseControlFace(sheet.draftAttributesJson) ?? parseControlFace(sheet.publishedAttributesJson);
|
|
2006
|
+
const losingControls = baseline === undefined ? [] : rebuildControlLosses(baseline);
|
|
1396
2007
|
return {
|
|
1397
2008
|
wouldChange: true,
|
|
1398
2009
|
sheetPresent: true,
|
|
1399
2010
|
draftPresent: hasDraft,
|
|
1400
2011
|
publishedControlCount: publishedControls,
|
|
1401
|
-
|
|
2012
|
+
...(losingControls.length > 0
|
|
2013
|
+
? {
|
|
2014
|
+
losingControls,
|
|
2015
|
+
losing: losingControls,
|
|
2016
|
+
rebuildWouldLoseControls: true,
|
|
2017
|
+
note: `rebuild:true 会先丢弃草稿并按已发布字段重建——下列布局控件无法按字段重建,真写会 fail-closed 拒绝(零写入):${losingControls.map((item) => `${item.control}·${item.typeName}`).join("、")}。要保留它们:加/改描述块用 form.draft {decorations},或显式回传 draftAttributesJson 原布局`,
|
|
2018
|
+
}
|
|
2019
|
+
: {
|
|
2020
|
+
note: "rebuild:true 会先丢弃草稿并按已发布字段重建——重建后的控件数预览无法模拟,降级门留给真写(本地其余门与真写同源)",
|
|
2021
|
+
}),
|
|
1402
2022
|
};
|
|
2023
|
+
}
|
|
1403
2024
|
if (!hasDraft)
|
|
1404
2025
|
return { wouldChange: true, sheetPresent: true, draftPresent: false, publishedControlCount: publishedControls, note: "当前无草稿:真写会先按已发布字段造草稿再提拔(预览不建草稿)" };
|
|
1405
2026
|
assertPublishNotDegrading(sheet.draftAttributesJson, sheet.publishedAttributesJson, { schemaCode: args.schemaCode, sheetCode, ...(args.allowDegrade !== undefined ? { allowDegrade: args.allowDegrade } : {}) });
|
|
@@ -1447,6 +2068,8 @@ function hasExplicitDraftIntent(args) {
|
|
|
1447
2068
|
return true;
|
|
1448
2069
|
if (nonEmpty(args.buttons) || nonEmpty(args.buttonScripts) || nonEmpty(args.removeButtonCodes))
|
|
1449
2070
|
return true;
|
|
2071
|
+
if (nonEmpty(args.decorations))
|
|
2072
|
+
return true;
|
|
1450
2073
|
return typeof args.customButtonJson === "string" && args.customButtonJson.trim() !== "";
|
|
1451
2074
|
}
|
|
1452
2075
|
/**
|
|
@@ -1469,10 +2092,12 @@ function hasExplicitDraftIntent(args) {
|
|
|
1469
2092
|
export function refuseEmptyCallerLayout(args) {
|
|
1470
2093
|
if (args.allowEmptyLayout === true)
|
|
1471
2094
|
return;
|
|
1472
|
-
// layout 是增量面:完整 view/attrs 由
|
|
2095
|
+
// layout/decorations 是增量面:完整 view/attrs 由 compose* 从基线组合出来,
|
|
1473
2096
|
// 调用方本来就不传整包面——这不是「没有布局意图」。
|
|
1474
2097
|
if (args.layout !== undefined)
|
|
1475
2098
|
return;
|
|
2099
|
+
if (Array.isArray(args.decorations) && args.decorations.length > 0)
|
|
2100
|
+
return;
|
|
1476
2101
|
const emptyFaces = [];
|
|
1477
2102
|
if (typeof args.draftViewJson === "string" && isEmptyLayoutJson(args.draftViewJson))
|
|
1478
2103
|
emptyFaces.push("draftViewJson");
|
|
@@ -1947,10 +2572,13 @@ export function readFormButtons(options) {
|
|
|
1947
2572
|
* so the high-level orchestrator never bypasses the scaffold.
|
|
1948
2573
|
*/
|
|
1949
2574
|
export async function executeFormDraftWrite(session, args) {
|
|
1950
|
-
// 增量布局面(探针 G F3
|
|
2575
|
+
// 增量布局面(探针 G F3)与布局控件面(issue #57):都与整包布局/重建参数互斥,
|
|
2576
|
+
// 必须在组合之前判(execute 也判一次,直调执行器绕不过去)。
|
|
1951
2577
|
const layoutRequest = args.layout;
|
|
1952
2578
|
if (layoutRequest !== undefined)
|
|
1953
2579
|
assertLayoutRequestConflicts({ ...args });
|
|
2580
|
+
assertDecorationRequestConflicts({ ...args });
|
|
2581
|
+
const decorationRequest = args.decorations;
|
|
1954
2582
|
// 兼容别名:`fieldCodes:["items.category"]` 等价于
|
|
1955
2583
|
// `childColumns:[{parent:"items",fieldCodes:["category"]}]`(issue #24)。
|
|
1956
2584
|
// 点号形式是使用者最自然的写法——子表列在父模型里本来就该这样指代。
|
|
@@ -2078,6 +2706,17 @@ export async function executeFormDraftWrite(session, args) {
|
|
|
2078
2706
|
if (typeLint !== undefined && typeLint.mismatches.length > 0)
|
|
2079
2707
|
controlTypeWarnings = typeLint.mismatches;
|
|
2080
2708
|
}
|
|
2709
|
+
// issue #57:布局控件(描述说明/分组标题/表单标题)增量面。以当前草稿为基线
|
|
2710
|
+
// 组合出整包 view/attrs,再走与整包写同一条形状门。与 layout 一样由 writeLint
|
|
2711
|
+
// 在 dry-run 里跑同一个函数,所以预览与真写逐字同形。
|
|
2712
|
+
// **必须排在默认表单创建之前**:decorations 需要存量控件面,表单不存在时
|
|
2713
|
+
// compose 直接拒(form-decorations-no-baseline),不会先建一张空表再失败。
|
|
2714
|
+
let decorationReceipt;
|
|
2715
|
+
if (decorationRequest !== undefined) {
|
|
2716
|
+
const composed = await composeFormDecorationsDraft(session, { schemaCode: args.schemaCode, sheetCode: args.sheetCode, decorations: decorationRequest });
|
|
2717
|
+
decorationReceipt = composed.receipt;
|
|
2718
|
+
args = { ...args, draftViewJson: composed.viewJson, draftAttributesJson: composed.attributesJson };
|
|
2719
|
+
}
|
|
2081
2720
|
// The default form may not exist yet on a freshly created model
|
|
2082
2721
|
// (bizmodels/create seeds no form) — create it, then scaffold into it.
|
|
2083
2722
|
let pre = await readFormOrNull(session, args.schemaCode, args.sheetCode);
|
|
@@ -2240,6 +2879,7 @@ export async function executeFormDraftWrite(session, args) {
|
|
|
2240
2879
|
code: String(row.code ?? row.propertyCode),
|
|
2241
2880
|
name: String(row.name ?? row.code ?? ""),
|
|
2242
2881
|
type,
|
|
2882
|
+
...(row.propertyEmpty === true ? { propertyEmpty: true } : {}),
|
|
2243
2883
|
...(relativeCode ? { relativeCode } : {}),
|
|
2244
2884
|
...(mappings ? { mappings } : {}),
|
|
2245
2885
|
...(displayField ? { displayField } : {}),
|
|
@@ -2278,6 +2918,7 @@ export async function executeFormDraftWrite(session, args) {
|
|
|
2278
2918
|
attributes = undefined;
|
|
2279
2919
|
}
|
|
2280
2920
|
let rebuildPreservedControls = [];
|
|
2921
|
+
let rebuildPreservedDecorations = [];
|
|
2281
2922
|
let controlsUpdated = 0;
|
|
2282
2923
|
if (typeof view !== "string" || typeof attributes !== "string") {
|
|
2283
2924
|
// Ticket 48: an explicit fieldCodes selection picks (and orders) the
|
|
@@ -2301,6 +2942,10 @@ export async function executeFormDraftWrite(session, args) {
|
|
|
2301
2942
|
const scaffold = buildFormScaffold(scaffoldFields, pre?.name ?? String(args.sheetCode), hidden);
|
|
2302
2943
|
if (previousAttributes)
|
|
2303
2944
|
rebuildPreservedControls = preserveDesignerControlOptions(scaffold.attributes, previousAttributes);
|
|
2945
|
+
// issue #57:描述块(202)不在字段元数据里,脚手架永远重建不出来——原样搬回
|
|
2946
|
+
// (含 displayFormula),否则 rebuild 会把客户加的红色说明静默清空。
|
|
2947
|
+
if (previousAttributes)
|
|
2948
|
+
rebuildPreservedDecorations = preserveDescriptionControls(scaffold.attributes, scaffold.rows, previousAttributes);
|
|
2304
2949
|
view = JSON.stringify(scaffold.rows);
|
|
2305
2950
|
attributes = JSON.stringify(scaffold.attributes);
|
|
2306
2951
|
}
|
|
@@ -2334,7 +2979,7 @@ export async function executeFormDraftWrite(session, args) {
|
|
|
2334
2979
|
if (args.rebuild === true && previousAttributes !== undefined && typeof attributes === "string") {
|
|
2335
2980
|
const composed = decodeJsonObjectColumn(attributes, { invalid: "undefined", array: "reject", object: "accept" });
|
|
2336
2981
|
if (composed !== undefined)
|
|
2337
|
-
|
|
2982
|
+
assertRebuildPreservesDesignerFace(composed, previousAttributes, { schemaCode: args.schemaCode, sheetCode: args.sheetCode });
|
|
2338
2983
|
}
|
|
2339
2984
|
// Form toolbar buttons live on `options.customButtonJson`; the publish step
|
|
2340
2985
|
// turns them into h_biz_button rows (triggerType=FORM). Merge rather than
|
|
@@ -2365,11 +3010,19 @@ export async function executeFormDraftWrite(session, args) {
|
|
|
2365
3010
|
const readback = await wireCall(session, { path: ENDPOINTS.sheetGet, query: { schemaCode: args.schemaCode, sheetCode: args.sheetCode } });
|
|
2366
3011
|
const sheet = (readback.data ?? {});
|
|
2367
3012
|
const formButtons = readFormButtons(sheet.options);
|
|
3013
|
+
// Ticket 62 — control-level requiredFormula written by hand (or by an older
|
|
3014
|
+
// draft) is a derived face that the designer will clear. Read-only warning.
|
|
3015
|
+
const requiredFormulaDrift = await detectRequiredFormulaDrift(session, {
|
|
3016
|
+
schemaCode: args.schemaCode,
|
|
3017
|
+
attributesJson: sheet.draftAttributesJson,
|
|
3018
|
+
...(args.draftAttributesJson === undefined ? { fields: publishedFields } : {}),
|
|
3019
|
+
});
|
|
2368
3020
|
return {
|
|
2369
3021
|
performed: { errcode: performed.errcode },
|
|
2370
3022
|
readback: {
|
|
2371
3023
|
hasDraft: sheet.existDraft === true || typeof sheet.draftViewJson === "string",
|
|
2372
3024
|
...(formButtons !== null ? { formButtons, formButtonCodes: formButtons.map((button) => String(button.code ?? "")) } : {}),
|
|
3025
|
+
...requiredFormulaDriftReadback(requiredFormulaDrift),
|
|
2373
3026
|
// #38 shape lint: the readback must never echo "configured" while the
|
|
2374
3027
|
// stored column is the stringified form the form page refuses to render.
|
|
2375
3028
|
...(customButtonJsonStoredShape(sheet.options) === "string" ? { formButtonsShapeWarning: CUSTOM_BUTTON_JSON_STRING_SHAPE_WARNING } : {}),
|
|
@@ -2392,6 +3045,19 @@ export async function executeFormDraftWrite(session, args) {
|
|
|
2392
3045
|
}
|
|
2393
3046
|
: {}),
|
|
2394
3047
|
...(args.rebuild === true && previousAttributes ? { rebuildPreservedControls } : {}),
|
|
3048
|
+
...(rebuildPreservedDecorations.length > 0
|
|
3049
|
+
? {
|
|
3050
|
+
rebuildPreservedDecorations,
|
|
3051
|
+
rebuildDecorationsNote: "rebuild 原样保留了草稿里的描述块(type 202,含 displayFormula)——它们不在字段元数据里,脚手架无法重建;额外分组标题/表单标题仍会 fail-closed 拒绝",
|
|
3052
|
+
}
|
|
3053
|
+
: {}),
|
|
3054
|
+
...(decorationReceipt !== undefined ? { decorations: decorationReceipt } : {}),
|
|
3055
|
+
...(decorationReceipt !== undefined
|
|
3056
|
+
? (() => {
|
|
3057
|
+
const written = summarizeFormDecorations(sheet.draftAttributesJson, sheet.draftViewJson);
|
|
3058
|
+
return { decorationsReadback: written.decorations, ...(written.note !== undefined ? { decorationsNote: written.note } : {}) };
|
|
3059
|
+
})()
|
|
3060
|
+
: {}),
|
|
2395
3061
|
...(args.refreshFromFields === true ? { refreshFromFields: true, controlsUpdated } : {}),
|
|
2396
3062
|
// r36(2026-11-01):rebuild 后草稿与重建前逐字节一致时明示——rebuild 的
|
|
2397
3063
|
// 语义就是"按已发布字段重搭",一致通常意味着预期的新控件没进来(字段未
|
|
@@ -2566,6 +3232,11 @@ export async function executeFormPublishWrite(session, args) {
|
|
|
2566
3232
|
// 短路也是回执:已发布 ≠ 页面可见。历史 layout 覆盖掉的子表列要在这里点名,
|
|
2567
3233
|
// 否则重跑 form.publish 会得到「published:true」的假确认。
|
|
2568
3234
|
const publishedGaps = await childColumnsMissingFromForm(session, { schemaCode: args.schemaCode, attributesJson: pre.publishedAttributesJson });
|
|
3235
|
+
// Ticket 62:短路回执同样要报条件必填的权威面漂移(只读,仅当控件级有值时读字段面)。
|
|
3236
|
+
const requiredFormulaDrift = await detectRequiredFormulaDrift(session, {
|
|
3237
|
+
schemaCode: args.schemaCode,
|
|
3238
|
+
attributesJson: pre.publishedAttributesJson,
|
|
3239
|
+
});
|
|
2569
3240
|
return {
|
|
2570
3241
|
performed: { skipped: "already-published" },
|
|
2571
3242
|
readback: {
|
|
@@ -2575,6 +3246,7 @@ export async function executeFormPublishWrite(session, args) {
|
|
|
2575
3246
|
? { bindChildColumnsNote: pendingChildColumns === undefined ? "无法核对(field.list 读失败),未执行绑定" : "没有待绑定的子表列" }
|
|
2576
3247
|
: {}),
|
|
2577
3248
|
...childColumnsGapReadback(publishedGaps, args.schemaCode, args.sheetCode),
|
|
3249
|
+
...requiredFormulaDriftReadback(requiredFormulaDrift),
|
|
2578
3250
|
},
|
|
2579
3251
|
};
|
|
2580
3252
|
}
|
|
@@ -2631,6 +3303,12 @@ export async function executeFormPublishWrite(session, args) {
|
|
|
2631
3303
|
const readback = await wireCall(session, { path: ENDPOINTS.sheetGet, query: { schemaCode: args.schemaCode, sheetCode: args.sheetCode } });
|
|
2632
3304
|
const sheet = (readback.data ?? {});
|
|
2633
3305
|
const formButtons = readFormButtons(sheet.options);
|
|
3306
|
+
// Ticket 62 — the promoted publishedAttributesJson is what the portal renders;
|
|
3307
|
+
// a control-level condition without the field-level counterpart is drift.
|
|
3308
|
+
const requiredFormulaDrift = await detectRequiredFormulaDrift(session, {
|
|
3309
|
+
schemaCode: args.schemaCode,
|
|
3310
|
+
attributesJson: sheet.publishedAttributesJson,
|
|
3311
|
+
});
|
|
2634
3312
|
// 探针 J P1(0.8.16):发布成功 ≠ 页面可见。子表列不在顶层控件面/viewJson,
|
|
2635
3313
|
// 只在父 Sheet201 控件的 columns 里;历史 layout 覆盖掉的列、或子表字段新发布
|
|
2636
3314
|
// 而没绑进表单时,这里逐条点名(读不到字段面则不诊断)。
|
|
@@ -2651,6 +3329,7 @@ export async function executeFormPublishWrite(session, args) {
|
|
|
2651
3329
|
? { bindChildColumnsNote: pendingChildColumns === undefined ? "无法核对(field.list 读失败),未执行绑定" : "没有待绑定的子表列" }
|
|
2652
3330
|
: {}),
|
|
2653
3331
|
...childColumnsGapReadback(childColumnGaps, args.schemaCode, args.sheetCode),
|
|
3332
|
+
...requiredFormulaDriftReadback(requiredFormulaDrift),
|
|
2654
3333
|
...(formButtons !== null
|
|
2655
3334
|
? {
|
|
2656
3335
|
formButtons,
|