cloud-web-corejs 1.0.54-dev.703 → 1.0.54-dev.704

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.
@@ -1,6 +1,7 @@
1
1
  import { generateId } from "../../../../components/xform/utils/util";
2
2
  import {
3
3
  buildDynamicSchemaRequestData,
4
+ extractDynamicSchemaItems,
4
5
  getDynamicSchemaOption,
5
6
  normalizeDynamicFieldKey,
6
7
  resolveDynamicSchemaResponse,
@@ -10,7 +11,7 @@ import {
10
11
  * 表格布局容器(table/h5-table)专用混入。
11
12
  *
12
13
  * 提供两类「布局表格」特有能力(动态字段状态控制已统一收敛到表单设置,见 formDynamicFieldMixin):
13
- * 1. 后台字段定义(dynamicSchemaEnabled):字段定义由后台查询下发,运行时生成并插入到行布局中。
14
+ * 1. 动态字段(dynamicSchemaSourceType):字段定义由脚本或接口下发,运行时生成并插入到行布局中。
14
15
  * 2. 行折叠(默认行为):整行字段均隐藏时折叠该行(响应式,随字段显隐自动更新)。
15
16
  *
16
17
  * 依赖宿主组件已混入:containerItemMixin(formModel/formHttp/handleCustomEvent/designState)
@@ -67,23 +68,102 @@ const dynamicFieldMixin = {
67
68
  },
68
69
 
69
70
  /* ------------------- 后台字段定义模式(行布局容器) ------------------- */
71
+ getDynamicSchemaSourceType() {
72
+ const options = this.widget.options || {};
73
+ const sourceType = getDynamicSchemaOption(options, "sourceType");
74
+ if (sourceType) {
75
+ return sourceType;
76
+ }
77
+ // 兼容旧配置:dynamicSchemaEnabled
78
+ if (options.dynamicSchemaEnabled) {
79
+ return "api";
80
+ }
81
+ return "none";
82
+ },
83
+
84
+ resolveShouldInitDynamicSchema() {
85
+ const source = this.getDynamicSchemaSourceType();
86
+ if (source === "none") {
87
+ return Promise.resolve(false);
88
+ }
89
+ const options = this.widget.options;
90
+ if (source === "api" && !getDynamicSchemaOption(options, "scriptCode")) {
91
+ return Promise.resolve(false);
92
+ }
93
+ if (source === "script" && !getDynamicSchemaOption(options, "frontendScript")) {
94
+ return Promise.resolve(false);
95
+ }
96
+ const script = getDynamicSchemaOption(options, "loadScript");
97
+ if (!script) {
98
+ return Promise.resolve(true);
99
+ }
100
+ const formRef = this.getFormRef();
101
+ if (!formRef || formRef.designState) {
102
+ return Promise.resolve(false);
103
+ }
104
+ try {
105
+ const result = this.handleCustomEvent(script);
106
+ if (result === false || result === null) {
107
+ return Promise.resolve(false);
108
+ }
109
+ return Promise.resolve(true);
110
+ } catch (e) {
111
+ return Promise.resolve(false);
112
+ }
113
+ },
114
+
70
115
  initDynamicSchema() {
71
116
  if (this.designState || !this.widget) return;
72
- const options = this.widget.options || {};
73
- if (!options.dynamicSchemaEnabled || !this.supportsRowLayout()) return;
117
+ if (!this.supportsRowLayout()) return;
118
+ if (this.getDynamicSchemaSourceType() === "none") return;
74
119
  this.$nextTick(() => {
75
- this.loadDynamicSchema();
120
+ this.resolveShouldInitDynamicSchema().then((shouldInit) => {
121
+ if (shouldInit) {
122
+ this.loadDynamicSchema();
123
+ }
124
+ });
76
125
  });
77
126
  },
78
127
 
79
128
  loadDynamicSchema() {
129
+ if (this.designState || !this.supportsRowLayout()) {
130
+ return Promise.resolve();
131
+ }
132
+ const source = this.getDynamicSchemaSourceType();
133
+ if (source === "script") {
134
+ return this.loadDynamicSchemaFromScript();
135
+ }
136
+ if (source === "api") {
137
+ return this.loadDynamicSchemaFromApi();
138
+ }
139
+ return Promise.resolve();
140
+ },
141
+
142
+ loadDynamicSchemaFromScript() {
143
+ const script = getDynamicSchemaOption(this.widget.options, "frontendScript");
144
+ if (!script) {
145
+ return Promise.resolve();
146
+ }
147
+ try {
148
+ const result = this.handleCustomEvent(script);
149
+ const defs = this.normalizeSchemaScriptResult(result);
150
+ this.buildDynamicRows(defs);
151
+ return Promise.resolve();
152
+ } catch (e) {
153
+ return Promise.resolve();
154
+ }
155
+ },
156
+
157
+ normalizeSchemaScriptResult(result) {
158
+ if (result === null || result === undefined) {
159
+ return [];
160
+ }
161
+ return extractDynamicSchemaItems(result);
162
+ },
163
+
164
+ loadDynamicSchemaFromApi() {
80
165
  const options = this.widget.options;
81
- if (
82
- this.designState
83
- || !options.dynamicSchemaEnabled
84
- || !getDynamicSchemaOption(options, "scriptCode")
85
- || !this.supportsRowLayout()
86
- ) {
166
+ if (!getDynamicSchemaOption(options, "scriptCode")) {
87
167
  return Promise.resolve();
88
168
  }
89
169
  const requestData = buildDynamicSchemaRequestData(
@@ -50,6 +50,9 @@ export const DYNAMIC_SCHEMA_OPTION_KEYS = {
50
50
  scriptParam: ["dynamicSchemaScriptParam", "dynamicColumnScriptParam"],
51
51
  convert: ["dynamicSchemaConvert"],
52
52
  mode: ["dynamicSchemaMode", "dynamicColumnMode"],
53
+ sourceType: ["dynamicSchemaSourceType", "dynamicColumnSourceType"],
54
+ loadScript: ["dynamicSchemaLoadScript", "dynamicColumnLoadScript"],
55
+ frontendScript: ["dynamicSchemaScript", "dynamicColumnsScript"],
53
56
  };
54
57
 
55
58
  export const widgetTypeToEditFormatMap = {