cloud-web-corejs 1.0.54-dev.677 → 1.0.54-dev.678

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.
@@ -128,10 +128,14 @@
128
128
  >{{ i18nt("designer.setting.editAction") }}
129
129
  </el-button>
130
130
  </el-form-item>
131
- <div class="dynamic-column-hint">
132
- 动态列来源<strong>二选一</strong>:前端列脚本(同步算列)或接口动态列(后端拉取)。同时配置时<strong>列脚本优先</strong>。
133
- </div>
134
- <div class="dynamic-column-block">
131
+ <el-form-item label="动态列来源">
132
+ <el-radio-group v-model="optionModel.dynamicColumnSourceType">
133
+ <el-radio label="none">无</el-radio>
134
+ <el-radio label="script">前端列脚本</el-radio>
135
+ <el-radio label="api">接口动态列</el-radio>
136
+ </el-radio-group>
137
+ </el-form-item>
138
+ <div v-if="optionModel.dynamicColumnSourceType === 'script'" class="dynamic-column-block">
135
139
  <div class="form-section-label">前端列脚本</div>
136
140
  <div class="form-section-desc">不调接口,脚本直接 return 列配置</div>
137
141
  <div class="data-table-editor-subsection">
@@ -149,83 +153,78 @@
149
153
  </el-form-item>
150
154
  </div>
151
155
  </div>
152
- <div class="dynamic-column-block">
156
+ <div v-if="optionModel.dynamicColumnSourceType === 'api'" class="dynamic-column-block">
153
157
  <div class="form-section-label">接口动态列</div>
154
158
  <div class="form-section-desc">打开表单时请求后端脚本,返回列配置</div>
155
159
  <div class="data-table-editor-subsection">
156
- <el-form-item label="启用">
157
- <el-switch
158
- v-model="optionModel.dynamicColumnScriptEnabled"
159
- ></el-switch>
160
+ <el-form-item label="脚本编码">
161
+ <el-input
162
+ v-model="optionModel.dynamicColumnScriptCode"
163
+ clearable
164
+ placeholder="如 getDynamicColumns"
165
+ ></el-input>
166
+ </el-form-item>
167
+ <el-form-item label="请求参数">
168
+ <a
169
+ href="javascript:void(0);"
170
+ class="a-link link-oneLind"
171
+ @click="
172
+ editEventHandler('dynamicColumnScriptParam', tableConfigParams)
173
+ "
174
+ >
175
+ <span>{{ optionModel.dynamicColumnScriptParam }}</span>
176
+ <i class="el-icon-edit"></i>
177
+ </a>
178
+ </el-form-item>
179
+ <el-form-item>
180
+ <span slot="label">
181
+ 响应转换
182
+ <el-tooltip effect="light" placement="top">
183
+ <div slot="content" style="line-height: 1.4; max-width: 320px">
184
+ 将接口返回的
185
+ <code>res</code> 转为列数组;不配置则按平台默认结构解析。
186
+ </div>
187
+ <i class="el-icon-info"></i>
188
+ </el-tooltip>
189
+ </span>
190
+ <a
191
+ href="javascript:void(0);"
192
+ class="a-link link-oneLind"
193
+ @click="editEventHandler('onDynamicColumnsConvert', ['res'])"
194
+ >
195
+ <span>{{ optionModel.onDynamicColumnsConvert }}</span>
196
+ <i class="el-icon-edit"></i>
197
+ </a>
198
+ </el-form-item>
199
+ </div>
200
+ </div>
201
+ <div v-if="optionModel.dynamicColumnSourceType !== 'none'" class="dynamic-column-block">
202
+ <div class="data-table-editor-subsection">
203
+ <el-form-item>
204
+ <span slot="label">
205
+ 加载条件
206
+ <el-tooltip effect="light" placement="top">
207
+ <div slot="content" style="line-height: 1.4; max-width: 320px">
208
+ 表格初始化加载动态列前执行。<br />
209
+ <code>return false</code> 时不加载;不配置则默认加载。
210
+ </div>
211
+ <i class="el-icon-info"></i>
212
+ </el-tooltip>
213
+ </span>
214
+ <a
215
+ href="javascript:void(0);"
216
+ class="a-link link-oneLind"
217
+ @click="
218
+ editEventHandler('dynamicColumnLoadScript', tableConfigParams)
219
+ "
220
+ >
221
+ <span>{{ optionModel.dynamicColumnLoadScript }}</span>
222
+ <i class="el-icon-edit"></i>
223
+ </a>
160
224
  </el-form-item>
161
- <template v-if="optionModel.dynamicColumnScriptEnabled">
162
- <el-form-item label="脚本编码">
163
- <el-input
164
- v-model="optionModel.dynamicColumnScriptCode"
165
- clearable
166
- placeholder="如 getDynamicColumns"
167
- ></el-input>
168
- </el-form-item>
169
- <el-form-item label="请求参数">
170
- <a
171
- href="javascript:void(0);"
172
- class="a-link link-oneLind"
173
- @click="
174
- editEventHandler('dynamicColumnScriptParam', tableConfigParams)
175
- "
176
- >
177
- <span>{{ optionModel.dynamicColumnScriptParam }}</span>
178
- <i class="el-icon-edit"></i>
179
- </a>
180
- </el-form-item>
181
- <el-form-item>
182
- <span slot="label">
183
- 响应转换
184
- <el-tooltip effect="light" placement="top">
185
- <div slot="content" style="line-height: 1.4; max-width: 320px">
186
- 将接口返回的
187
- <code>res</code> 转为列数组;不配置则按平台默认结构解析。
188
- </div>
189
- <i class="el-icon-info"></i>
190
- </el-tooltip>
191
- </span>
192
- <a
193
- href="javascript:void(0);"
194
- class="a-link link-oneLind"
195
- @click="editEventHandler('onDynamicColumnsConvert', ['res'])"
196
- >
197
- <span>{{ optionModel.onDynamicColumnsConvert }}</span>
198
- <i class="el-icon-edit"></i>
199
- </a>
200
- </el-form-item>
201
- <el-form-item>
202
- <span slot="label">
203
- 默认加载判断
204
- <el-tooltip effect="light" placement="top">
205
- <div slot="content" style="line-height: 1.4; max-width: 320px">
206
- 启用后打开表单时<strong>默认</strong>自动请求动态列。<br />
207
- 同步:仅写 <code>return false</code> /
208
- <code>return null</code> 跳过。<br />
209
- 异步:先写异步逻辑,末尾
210
- <code>return false</code>;条件满足时调用
211
- <code>done()</code>(无参)。
212
- </div>
213
- <i class="el-icon-info"></i>
214
- </el-tooltip>
215
- </span>
216
- <a
217
- href="javascript:void(0);"
218
- class="a-link link-oneLind"
219
- @click="editEventHandler('dynamicColumnAutoLoadScript', ['done'])"
220
- >
221
- <span>{{ optionModel.dynamicColumnAutoLoadScript }}</span>
222
- <i class="el-icon-edit"></i>
223
- </a>
224
- </el-form-item>
225
- </template>
226
225
  </div>
227
226
  </div>
228
- <el-form-item label="动态列模式">
227
+ <el-form-item v-if="optionModel.dynamicColumnSourceType !== 'none'" label="动态列模式">
229
228
  <span slot="label">
230
229
  动态列模式
231
230
  <el-tooltip effect="light" placement="top">
@@ -235,12 +235,12 @@ export const containers = [
235
235
  onSearchTable: "",
236
236
  onResetTable: "",
237
237
  dynamicColumnsScript: null,
238
+ dynamicColumnSourceType: "none",
238
239
  dynamicColumnMode: "append",
239
- dynamicColumnScriptEnabled: false,
240
240
  dynamicColumnScriptCode: null,
241
241
  dynamicColumnScriptParam: null,
242
242
  onDynamicColumnsConvert: null,
243
- dynamicColumnAutoLoadScript: null,
243
+ dynamicColumnLoadScript: null,
244
244
  accessType: "1",
245
245
  accessUrl: null,
246
246
  accessReturnType: "1",
@@ -123,6 +123,8 @@ modules = {
123
123
  eventConfig: {},
124
124
  dynamicTableColumns: [],
125
125
  dynamicColumnsPreloaded: false,
126
+ dynamicColumnsInitResolved: false,
127
+ dynamicColumnsInitSkipped: false,
126
128
  };
127
129
  },
128
130
  watch: {
@@ -177,8 +179,8 @@ modules = {
177
179
  if (!this.widget.options.dynamicColumnMode) {
178
180
  this.$set(this.widget.options, "dynamicColumnMode", "append");
179
181
  }
180
- if (this.widget.options.dynamicColumnScriptEnabled === undefined) {
181
- this.$set(this.widget.options, "dynamicColumnScriptEnabled", false);
182
+ if (this.widget.options.dynamicColumnSourceType === undefined) {
183
+ this.$set(this.widget.options, "dynamicColumnSourceType", "none");
182
184
  }
183
185
  this.initRefList();
184
186
  // this.initConfig();
@@ -695,7 +697,13 @@ modules = {
695
697
  getTableColumns() {
696
698
  return this.widget.options.tableColumns || [];
697
699
  },
700
+ getDynamicColumnSourceType() {
701
+ return this.widget.options.dynamicColumnSourceType || "none";
702
+ },
698
703
  getDynamicTableColumnsFromScript() {
704
+ if (this.getDynamicColumnSourceType() !== "script") {
705
+ return undefined;
706
+ }
699
707
  const script = this.widget.options.dynamicColumnsScript;
700
708
  if (!script) {
701
709
  return undefined;
@@ -746,12 +754,16 @@ modules = {
746
754
  }
747
755
  return staticCols;
748
756
  },
749
- getEffectiveTableColumns() {
757
+ getEffectiveTableColumns(forceDynamic = false) {
750
758
  const staticColumns = this.widget.options.tableColumns || [];
751
759
  const runtimeDynamic = this.dynamicTableColumns || [];
752
- const scriptDynamic = this.getDynamicTableColumnsFromScript();
753
- if (scriptDynamic !== undefined) {
754
- return this.mergeDynamicTableColumns(staticColumns, scriptDynamic);
760
+ const applyScriptDynamic =
761
+ forceDynamic || !this.shouldSkipDynamicColumnsOnInit();
762
+ if (applyScriptDynamic) {
763
+ const scriptDynamic = this.getDynamicTableColumnsFromScript();
764
+ if (scriptDynamic !== undefined) {
765
+ return this.mergeDynamicTableColumns(staticColumns, scriptDynamic);
766
+ }
755
767
  }
756
768
  if (runtimeDynamic.length) {
757
769
  if (this.widget.options.dynamicColumnMode === "replace") {
@@ -780,11 +792,16 @@ modules = {
780
792
  this.widget.options.tableColumns = savedColumns;
781
793
  return tableColumns;
782
794
  },
783
- ensureEffectiveColumnWidgets() {
784
- const effectiveColumns = this.getEffectiveTableColumns();
795
+ ensureEffectiveColumnWidgets(forceDynamic = false) {
796
+ const effectiveColumns = this.getEffectiveTableColumns(forceDynamic);
785
797
  this.attachTableColumnWidgets(effectiveColumns);
786
798
  this.syncEffectiveColumnWidgetFieldKeys(effectiveColumns);
787
799
  },
800
+ shouldSkipDynamicColumnsOnInit() {
801
+ return (
802
+ this.dynamicColumnsInitResolved && this.dynamicColumnsInitSkipped
803
+ );
804
+ },
788
805
  getColumnVisible(columnConfig) {
789
806
  if (columnConfig.show === false) {
790
807
  return false;
@@ -800,8 +817,8 @@ modules = {
800
817
  return true;
801
818
  },
802
819
  applyTableColumnsReload() {
803
- this.ensureEffectiveColumnWidgets();
804
- const effectiveColumns = this.getEffectiveTableColumns();
820
+ this.ensureEffectiveColumnWidgets(true);
821
+ const effectiveColumns = this.getEffectiveTableColumns(true);
805
822
  return new Promise((resolve) => {
806
823
  this.initColumnWidgetConfig(() => {
807
824
  const columns = this.createColumns();
@@ -859,11 +876,8 @@ modules = {
859
876
  }
860
877
  );
861
878
  },
862
- refreshTableColumns() {
863
- return this.applyTableColumnsReload();
864
- },
865
879
  refreshColumnVisible() {
866
- return this.refreshTableColumns();
880
+ return this.applyTableColumnsReload();
867
881
  },
868
882
  normalizeDynamicColumnItem(item, index) {
869
883
  if (!item || typeof item !== "object") {
@@ -955,7 +969,19 @@ modules = {
955
969
  }
956
970
  return [];
957
971
  },
958
- loadDynamicColumnsFromApi(options = {}) {
972
+ loadDynamicColumns(options = {}) {
973
+ const source = this.getDynamicColumnSourceType();
974
+ if (source === "script") {
975
+ return this.applyTableColumnsReload().then((columns) => {
976
+ options.success && options.success(null, columns);
977
+ return columns;
978
+ });
979
+ }
980
+ if (source !== "api") {
981
+ const columns = this.getEffectiveTableColumns(true);
982
+ options.success && options.success(null, columns);
983
+ return Promise.resolve(columns);
984
+ }
959
985
  const isLoading = options.isLoading ?? true;
960
986
  const mode = options.mode ?? this.widget.options.dynamicColumnMode;
961
987
  return this.requestDynamicColumnsFromApi({
@@ -971,18 +997,19 @@ modules = {
971
997
  });
972
998
  });
973
999
  },
974
- loadDynamicColumns(options) {
975
- return this.loadDynamicColumnsFromApi(options);
976
- },
977
- fetchDynamicColumns(options) {
978
- return this.loadDynamicColumnsFromApi(options);
979
- },
980
- resolveShouldAutoLoadDynamicColumns() {
1000
+ resolveShouldInitDynamicColumns() {
1001
+ const source = this.getDynamicColumnSourceType();
1002
+ if (source === "none") {
1003
+ return Promise.resolve(false);
1004
+ }
981
1005
  const options = this.widget.options;
982
- if (!options.dynamicColumnScriptEnabled || !options.dynamicColumnScriptCode) {
1006
+ if (source === "api" && !options.dynamicColumnScriptCode) {
983
1007
  return Promise.resolve(false);
984
1008
  }
985
- const script = options.dynamicColumnAutoLoadScript;
1009
+ if (source === "script" && !options.dynamicColumnsScript) {
1010
+ return Promise.resolve(false);
1011
+ }
1012
+ const script = options.dynamicColumnLoadScript;
986
1013
  if (!script) {
987
1014
  return Promise.resolve(true);
988
1015
  }
@@ -990,46 +1017,15 @@ modules = {
990
1017
  if (!formRef || formRef.designState) {
991
1018
  return Promise.resolve(false);
992
1019
  }
993
- return new Promise((resolve) => {
994
- let settled = false;
995
- const finishLoad = () => {
996
- if (settled) {
997
- return;
998
- }
999
- settled = true;
1000
- resolve(true);
1001
- };
1002
- const finishSkip = () => {
1003
- if (settled) {
1004
- return;
1005
- }
1006
- settled = true;
1007
- resolve(false);
1008
- };
1009
- const done = finishLoad;
1010
- try {
1011
- const result = formRef.handleCustomEvent(script, ["done"], [done]);
1012
- if (settled) {
1013
- return;
1014
- }
1015
- if (result === null || result === false) {
1016
- if (result === null) {
1017
- finishSkip();
1018
- return;
1019
- }
1020
- // return false:异步 defer 等待 done();未调用则视为跳过
1021
- setTimeout(() => {
1022
- if (!settled) {
1023
- finishSkip();
1024
- }
1025
- }, 0);
1026
- return;
1027
- }
1028
- finishLoad();
1029
- } catch (e) {
1030
- finishSkip();
1020
+ try {
1021
+ const result = this.handleCustomEvent(script);
1022
+ if (result === false || result === null) {
1023
+ return Promise.resolve(false);
1031
1024
  }
1032
- });
1025
+ return Promise.resolve(true);
1026
+ } catch (e) {
1027
+ return Promise.resolve(false);
1028
+ }
1033
1029
  },
1034
1030
  isTableColumnGridInitialized() {
1035
1031
  return !!this.vxeOption;
@@ -1066,28 +1062,33 @@ modules = {
1066
1062
  });
1067
1063
  },
1068
1064
  bootstrapDynamicColumnsBeforeInit() {
1069
- return this.resolveShouldAutoLoadDynamicColumns().then((shouldLoad) => {
1070
- if (!shouldLoad) {
1065
+ return this.resolveShouldInitDynamicColumns().then((shouldInit) => {
1066
+ this.dynamicColumnsInitResolved = true;
1067
+ this.dynamicColumnsInitSkipped = !shouldInit;
1068
+ if (!shouldInit) {
1069
+ return;
1070
+ }
1071
+ if (this.getDynamicColumnSourceType() !== "api") {
1071
1072
  return;
1072
1073
  }
1073
1074
  this.dynamicColumnsPreloaded = true;
1074
- const mode = this.widget.options.dynamicColumnMode;
1075
- return this.requestDynamicColumnsFromApi({ isLoading: true })
1076
- .then(({ columns }) => this.assignDynamicTableColumns(columns, { mode }))
1077
- .catch(() => {
1078
- this.dynamicColumnsPreloaded = false;
1079
- });
1075
+ return this.loadDynamicColumns({ isLoading: true }).catch(() => {
1076
+ this.dynamicColumnsPreloaded = false;
1077
+ });
1080
1078
  });
1081
1079
  },
1082
1080
  tryAutoLoadDynamicColumns() {
1083
- if (this.dynamicColumnsPreloaded) {
1081
+ if (
1082
+ this.dynamicColumnsPreloaded ||
1083
+ this.getDynamicColumnSourceType() !== "api"
1084
+ ) {
1084
1085
  return Promise.resolve();
1085
1086
  }
1086
- return this.resolveShouldAutoLoadDynamicColumns().then((shouldLoad) => {
1087
+ return this.resolveShouldInitDynamicColumns().then((shouldLoad) => {
1087
1088
  if (!shouldLoad) {
1088
1089
  return;
1089
1090
  }
1090
- return this.loadDynamicColumnsFromApi({ isLoading: true }).catch(() => {});
1091
+ return this.loadDynamicColumns({ isLoading: true }).catch(() => {});
1091
1092
  });
1092
1093
  },
1093
1094
  getTableData: function () {
@@ -1886,6 +1887,9 @@ modules = {
1886
1887
  isQueryAllPage,
1887
1888
  exportItemConfig,
1888
1889
  vform: true,
1890
+ ...(this.getDynamicColumnSourceType() !== "none"
1891
+ ? { visibleSync: false }
1892
+ : {}),
1889
1893
  ...(dataTableConfig.otherConfig || {}),
1890
1894
  config: {
1891
1895
  height: height,