cloud-web-corejs 1.0.54-dev.674 → 1.0.54-dev.675

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.
@@ -30,6 +30,22 @@ const baseRefUtil = {
30
30
  getReportGlobalMap,
31
31
  };
32
32
 
33
+ const DYNAMIC_COLUMN_EDIT_FORMATS = [
34
+ "editInput",
35
+ "editNumber",
36
+ "editDate",
37
+ "editSelect",
38
+ "editSearch",
39
+ "editAttachment",
40
+ "editDelete",
41
+ "editButton",
42
+ "addSiblingEditRow",
43
+ "addChildTreeRow",
44
+ "moveUpRow",
45
+ "moveDownRow",
46
+ "removeTreeRow",
47
+ ];
48
+
33
49
  modules = {
34
50
  mixins: [
35
51
  baseRefUtil.emitter,
@@ -120,6 +136,8 @@ modules = {
120
136
  fieldSchemaMap: {},
121
137
  fieldSchemaData: [],
122
138
  eventConfig: {},
139
+ dynamicTableColumns: [],
140
+ dynamicColumnsPreloaded: false,
123
141
  };
124
142
  },
125
143
  watch: {
@@ -171,6 +189,15 @@ modules = {
171
189
  created: function () {
172
190
  if (!this.formModel[this.fieldKeyName])
173
191
  this.formModel[this.fieldKeyName] = [];
192
+ if (!this.widget.options.dynamicColumnMode) {
193
+ this.$set(this.widget.options, "dynamicColumnMode", "append");
194
+ }
195
+ if (this.widget.options.dynamicColumnScriptEnabled === undefined) {
196
+ this.$set(this.widget.options, "dynamicColumnScriptEnabled", false);
197
+ }
198
+ if (this.widget.options.dynamicColumnAutoLoad === undefined) {
199
+ this.$set(this.widget.options, "dynamicColumnAutoLoad", false);
200
+ }
174
201
  this.initRefList();
175
202
  // this.initConfig();
176
203
  this.initTableCustomEvent();
@@ -180,8 +207,10 @@ modules = {
180
207
  },
181
208
  mounted: async function () {
182
209
  this.handleOnMounted();
183
- this.initColumnWidgetConfig(() => {
184
- this.initTableList();
210
+ this.bootstrapDynamicColumnsBeforeInit().then(() => {
211
+ this.initColumnWidgetConfig(() => {
212
+ this.initTableList();
213
+ });
185
214
  });
186
215
  },
187
216
  beforeDestroy: function () {
@@ -218,27 +247,97 @@ modules = {
218
247
  let widget = this.getTableColumnWidget(obj);
219
248
  return widget ? this.getFieldKeyName(widget) : null;
220
249
  },
221
- initColumnWidgetConfig(callback) {
222
- let tableColumns = this.widget.options.tableColumns;
223
- let requests = [];
250
+ collectColumnWidgetConfigRequests(tableColumns, options = {}) {
251
+ const { forceRefresh = false } = options;
252
+ const requests = [];
224
253
  this.loodHandleColumns(tableColumns, (row) => {
254
+ if (forceRefresh) {
255
+ this.resetColumnWidgetSyncFlag(row.widget);
256
+ this.resetColumnWidgetSyncFlag(row.editWidget);
257
+ }
225
258
  requests.push(this.handleColumnWidgetConfig(row.widget));
226
259
  requests.push(this.handleColumnWidgetConfig(row.editWidget));
227
260
  let widgetList = row.widgetList;
228
261
  if (widgetList && widgetList.length) {
229
262
  traverseAllWidgetsNew(widgetList, (widget) => {
263
+ if (forceRefresh) {
264
+ this.resetColumnWidgetSyncFlag(widget);
265
+ }
230
266
  requests.push(this.handleColumnWidgetConfig(widget));
231
267
  });
232
268
  }
233
269
  });
270
+ return requests.filter(Boolean);
271
+ },
272
+ resetColumnWidgetSyncFlag(widget) {
273
+ if (widget) {
274
+ widget._syncInited = false;
275
+ }
276
+ },
277
+ syncColumnWidgetFieldKey(columnRow, widget) {
278
+ if (!widget || !columnRow?.prop) {
279
+ return;
280
+ }
281
+ const prop = columnRow.prop;
282
+ if (Object.prototype.hasOwnProperty.call(widget.options, "keyName")) {
283
+ widget.options.keyName = prop;
284
+ widget.options.keyNameEnabled = true;
285
+ } else {
286
+ widget.options.name = prop;
287
+ }
288
+ },
289
+ syncEffectiveColumnWidgetFieldKeys(tableColumns) {
290
+ this.loodHandleColumns(tableColumns, (row) => {
291
+ this.syncColumnWidgetFieldKey(row, row.widget);
292
+ this.syncColumnWidgetFieldKey(row, row.editWidget);
293
+ });
294
+ },
295
+ initColumnWidgetConfig(callback, options = {}) {
296
+ const tableColumns =
297
+ options.columns ?? this.getEffectiveTableColumns();
298
+ const requests = this.collectColumnWidgetConfigRequests(
299
+ tableColumns,
300
+ options
301
+ );
234
302
  if (requests.length) {
235
303
  Promise.all(requests).then(() => {
236
- callback();
304
+ callback && callback();
237
305
  });
238
306
  } else {
239
- callback();
307
+ callback && callback();
240
308
  }
241
309
  },
310
+ refreshColumnWidgetConfig(options = {}) {
311
+ const tableColumns =
312
+ options.columns ?? this.getEffectiveTableColumns();
313
+ const forceRefresh = options.forceRefresh !== false;
314
+ return new Promise((resolve, reject) => {
315
+ const requests = this.collectColumnWidgetConfigRequests(tableColumns, {
316
+ forceRefresh,
317
+ });
318
+ const finish = () => {
319
+ this.initFieldSchemaData(true);
320
+ const $grid = this.getGridTable();
321
+ if ($grid?.refreshColumn) {
322
+ $grid.refreshColumn();
323
+ }
324
+ options.success && options.success();
325
+ resolve();
326
+ };
327
+ if (requests.length) {
328
+ Promise.all(requests).then(finish).catch((err) => {
329
+ options.fail && options.fail(err);
330
+ options.error && options.error(err);
331
+ reject(err);
332
+ });
333
+ } else {
334
+ finish();
335
+ }
336
+ });
337
+ },
338
+ reloadColumnWidgetOptions(options) {
339
+ return this.refreshColumnWidgetConfig(options);
340
+ },
242
341
  fillColumnWidgetOptionItems(widget, rows) {
243
342
  let widgetType = widget.type;
244
343
  let formScriptEnabledTypes = ["select", "checkbox", "radio"];
@@ -609,15 +708,330 @@ modules = {
609
708
  getRowIndex: function (e) {
610
709
  return this.widget.options.tableData.lastIndexOf(e);
611
710
  },
612
- setTableColumns: function (e) {
613
- let t = this;
614
- (this.widget.options.tableColumns = e),
615
- this.$nextTick(function () {
616
- t.$refs.dataTable.doLayout();
711
+ getTableColumns() {
712
+ return this.widget.options.tableColumns || [];
713
+ },
714
+ getDynamicTableColumnsFromScript() {
715
+ const script = this.widget.options.onDynamicColumns;
716
+ if (!script) {
717
+ return undefined;
718
+ }
719
+ const result = this.handleCustomEvent(script);
720
+ if (result === null || result === undefined) {
721
+ return undefined;
722
+ }
723
+ return result;
724
+ },
725
+ mergeDynamicTableColumns(staticColumns, dynamicResult) {
726
+ const staticCols = staticColumns || [];
727
+ if (dynamicResult === undefined || dynamicResult === null) {
728
+ return staticCols;
729
+ }
730
+ if (Array.isArray(dynamicResult)) {
731
+ if (this.widget.options.dynamicColumnMode === "replace") {
732
+ return dynamicResult;
733
+ }
734
+ return staticCols.concat(dynamicResult);
735
+ }
736
+ if (dynamicResult.replace) {
737
+ return dynamicResult.columns || [];
738
+ }
739
+ if (dynamicResult.columns) {
740
+ return staticCols.concat(dynamicResult.columns);
741
+ }
742
+ return staticCols;
743
+ },
744
+ getEffectiveTableColumns() {
745
+ const staticColumns = this.widget.options.tableColumns || [];
746
+ const runtimeDynamic = this.dynamicTableColumns || [];
747
+ const scriptDynamic = this.getDynamicTableColumnsFromScript();
748
+ if (scriptDynamic !== undefined) {
749
+ return this.mergeDynamicTableColumns(staticColumns, scriptDynamic);
750
+ }
751
+ if (runtimeDynamic.length) {
752
+ if (this.widget.options.dynamicColumnMode === "replace") {
753
+ return runtimeDynamic;
754
+ }
755
+ return staticColumns.concat(runtimeDynamic);
756
+ }
757
+ return staticColumns;
758
+ },
759
+ ensureEffectiveColumnWidgets() {
760
+ const effectiveColumns = this.getEffectiveTableColumns();
761
+ const formRef = this.getFormRef();
762
+ if (!formRef?.handleTableColumnWidget) {
763
+ return;
764
+ }
765
+ const savedColumns = this.widget.options.tableColumns;
766
+ this.widget.options.tableColumns = effectiveColumns;
767
+ formRef.handleTableColumnWidget(this.widget);
768
+ this.syncEffectiveColumnWidgetFieldKeys(effectiveColumns);
769
+ this.widget.options.tableColumns = savedColumns;
770
+ },
771
+ getColumnVisible(columnConfig) {
772
+ if (columnConfig.show === false) {
773
+ return false;
774
+ }
775
+ if (columnConfig.columnShow) {
776
+ const result = this.handleCustomEvent(columnConfig.columnShow);
777
+ return result !== false && result !== null;
778
+ }
779
+ return true;
780
+ },
781
+ applyTableColumnsReload() {
782
+ this.ensureEffectiveColumnWidgets();
783
+ const effectiveColumns = this.getEffectiveTableColumns();
784
+ return new Promise((resolve) => {
785
+ this.initColumnWidgetConfig(() => {
786
+ const columns = this.createColumns();
787
+ this.widgets = columns
788
+ .filter((column) => !!column?.params?.widget)
789
+ .map((column) => column.params.widget);
790
+ this.editWidgets = columns
791
+ .filter((column) => !!column?.params?.editWidget)
792
+ .map((column) => column.params.editWidget);
793
+ if (this.vxeOption) {
794
+ this.$set(this.vxeOption, "columns", columns);
795
+ }
796
+ const $grid = this.getGridTable();
797
+ if ($grid?.reloadColumn) {
798
+ const reloadResult = $grid.reloadColumn(columns);
799
+ const finish = () => {
800
+ this.initFieldSchemaData(true);
801
+ resolve(columns);
802
+ };
803
+ if (reloadResult?.then) {
804
+ reloadResult.then(finish).catch(finish);
805
+ } else {
806
+ finish();
807
+ }
808
+ } else {
809
+ resolve(columns);
810
+ }
811
+ }, { columns: effectiveColumns, forceRefresh: true });
812
+ });
813
+ },
814
+ reloadTableColumns(tableColumns) {
815
+ if (Array.isArray(tableColumns)) {
816
+ this.dynamicTableColumns = [];
817
+ this.widget.options.tableColumns = tableColumns;
818
+ }
819
+ return this.applyTableColumnsReload();
820
+ },
821
+ setTableColumns(tableColumns) {
822
+ return this.reloadTableColumns(tableColumns);
823
+ },
824
+ setTableColumn(tableColumns) {
825
+ return this.setTableColumns(tableColumns);
826
+ },
827
+ setDynamicTableColumns(tableColumns, options = {}) {
828
+ const { mode, deferReload } = options;
829
+ return this.assignDynamicTableColumns(tableColumns, { mode }).then(
830
+ (columns) => {
831
+ const shouldDeferReload =
832
+ deferReload === true ||
833
+ (deferReload !== false && !this.isTableColumnGridInitialized());
834
+ if (shouldDeferReload) {
835
+ return columns;
836
+ }
837
+ return this.applyTableColumnsReload().then(() => columns);
838
+ }
839
+ );
840
+ },
841
+ refreshTableColumns() {
842
+ return this.applyTableColumnsReload();
843
+ },
844
+ refreshColumnVisible() {
845
+ return this.refreshTableColumns();
846
+ },
847
+ normalizeDynamicColumnItem(item, index) {
848
+ if (!item || typeof item !== "object") {
849
+ return null;
850
+ }
851
+ const prop =
852
+ item.prop || item.field || item.name || item.key || `dynamicCol_${index}`;
853
+ const label = item.label || item.title || item.name || prop;
854
+ let formatS = item.formatS || item.format || null;
855
+ let editFormatS = item.editFormatS || null;
856
+ let columnOption = item.columnOption;
857
+ let editColumnOption = item.editColumnOption;
858
+
859
+ // 接口列字段与设计器一致;未配 editFormatS 时,从 formatS(edit*)兼容复制
860
+ if (
861
+ !editFormatS &&
862
+ formatS &&
863
+ DYNAMIC_COLUMN_EDIT_FORMATS.includes(formatS)
864
+ ) {
865
+ editFormatS = formatS;
866
+ }
867
+ if (editFormatS && !editColumnOption && columnOption) {
868
+ editColumnOption = columnOption;
869
+ }
870
+
871
+ return {
872
+ ...item,
873
+ columnId: item.columnId || `${Date.now()}_${index}`,
874
+ prop,
875
+ label,
876
+ width: item.width ?? 150,
877
+ show: item.show !== false,
878
+ sortable: item.sortable !== false,
879
+ filterable: item.filterable !== false,
880
+ align: item.align || "left",
881
+ formatS,
882
+ editFormatS: editFormatS || undefined,
883
+ columnOption,
884
+ editColumnOption,
885
+ };
886
+ },
887
+ normalizeDynamicColumns(columns) {
888
+ if (!Array.isArray(columns)) {
889
+ return [];
890
+ }
891
+ return columns
892
+ .map((item, index) => this.normalizeDynamicColumnItem(item, index))
893
+ .filter(Boolean);
894
+ },
895
+ buildDynamicColumnRequestData(options = {}) {
896
+ if (options.data !== undefined) {
897
+ return options.data;
898
+ }
899
+ const paramScript = this.widget.options.dynamicColumnScriptParam;
900
+ let customParam = {};
901
+ if (paramScript) {
902
+ customParam =
903
+ (this.handleCustomParam &&
904
+ this.handleCustomParam(paramScript)) ||
905
+ this.handleCustomEvent(paramScript) ||
906
+ {};
907
+ }
908
+ const formRef = this.getFormRef();
909
+ const reportTemplate = formRef.reportTemplate || {};
910
+ return {
911
+ formCode: reportTemplate.formCode,
912
+ formVersion: reportTemplate.formVersion,
913
+ taBm: this.fieldKeyName,
914
+ data: {
915
+ dataId: this.formDataId,
916
+ formData: this.globalModel?.formModel || {},
917
+ ...customParam,
918
+ },
919
+ };
920
+ },
921
+ convertDynamicColumnResponse(res, options = {}) {
922
+ const convertScript =
923
+ options.convertScript ?? this.widget.options.onDynamicColumnsConvert;
924
+ if (convertScript) {
925
+ const result = this.handleCustomEvent(convertScript, ["res"], [res]);
926
+ if (Array.isArray(result)) {
927
+ return this.normalizeDynamicColumns(result);
928
+ }
929
+ if (result?.columns) {
930
+ return this.normalizeDynamicColumns(result.columns);
931
+ }
932
+ return [];
933
+ }
934
+ const objx = res?.objx;
935
+ if (Array.isArray(objx)) {
936
+ return this.normalizeDynamicColumns(objx);
937
+ }
938
+ if (objx?.columns && Array.isArray(objx.columns)) {
939
+ return this.normalizeDynamicColumns(objx.columns);
940
+ }
941
+ if (objx?.tableColumns && Array.isArray(objx.tableColumns)) {
942
+ return this.normalizeDynamicColumns(objx.tableColumns);
943
+ }
944
+ return [];
945
+ },
946
+ loadDynamicColumnsFromApi(options = {}) {
947
+ const isLoading = options.isLoading ?? true;
948
+ const mode = options.mode ?? this.widget.options.dynamicColumnMode;
949
+ return this.requestDynamicColumnsFromApi({
950
+ ...options,
951
+ isLoading,
952
+ }).then(({ res, columns }) => {
953
+ return this.setDynamicTableColumns(columns, {
954
+ mode,
955
+ deferReload: options.deferReload,
956
+ }).then((resultColumns) => {
957
+ options.success && options.success(res, resultColumns);
958
+ return resultColumns;
959
+ });
960
+ });
961
+ },
962
+ loadDynamicColumns(options) {
963
+ return this.loadDynamicColumnsFromApi(options);
964
+ },
965
+ fetchDynamicColumns(options) {
966
+ return this.loadDynamicColumnsFromApi(options);
967
+ },
968
+ isDynamicColumnAutoLoadEnabled() {
969
+ const options = this.widget.options;
970
+ return !!(
971
+ options.dynamicColumnScriptEnabled &&
972
+ options.dynamicColumnScriptCode &&
973
+ options.dynamicColumnAutoLoad
974
+ );
975
+ },
976
+ isTableColumnGridInitialized() {
977
+ return !!this.vxeOption;
978
+ },
979
+ assignDynamicTableColumns(tableColumns, options = {}) {
980
+ const { mode } = options;
981
+ if (mode) {
982
+ this.widget.options.dynamicColumnMode = mode;
983
+ }
984
+ this.dynamicTableColumns = Array.isArray(tableColumns)
985
+ ? tableColumns
986
+ : [];
987
+ this.ensureEffectiveColumnWidgets();
988
+ return Promise.resolve(this.dynamicTableColumns);
989
+ },
990
+ requestDynamicColumnsFromApi(options = {}) {
991
+ const scriptCode =
992
+ options.scriptCode ?? this.widget.options.dynamicColumnScriptCode;
993
+ if (!scriptCode) {
994
+ return Promise.reject(new Error("dynamicColumnScriptCode is required"));
995
+ }
996
+ const data = this.buildDynamicColumnRequestData(options);
997
+ const isLoading = options.isLoading ?? true;
998
+ return this.formHttp({
999
+ scriptCode,
1000
+ data,
1001
+ isLoading,
1002
+ fail: options.fail,
1003
+ error: options.error,
1004
+ }).then((res) => {
1005
+ const columns = this.convertDynamicColumnResponse(res, options);
1006
+ options.onFetchSuccess && options.onFetchSuccess(res, columns);
1007
+ return { res, columns };
1008
+ });
1009
+ },
1010
+ bootstrapDynamicColumnsBeforeInit() {
1011
+ if (!this.isDynamicColumnAutoLoadEnabled()) {
1012
+ return Promise.resolve();
1013
+ }
1014
+ this.dynamicColumnsPreloaded = true;
1015
+ const mode = this.widget.options.dynamicColumnMode;
1016
+ return this.requestDynamicColumnsFromApi({ isLoading: true })
1017
+ .then(({ columns }) => this.assignDynamicTableColumns(columns, { mode }))
1018
+ .catch(() => {
1019
+ this.dynamicColumnsPreloaded = false;
617
1020
  });
618
1021
  },
619
- setTableColumn: function (e) {
620
- this.setTableColumns(e);
1022
+ tryAutoLoadDynamicColumns() {
1023
+ if (this.dynamicColumnsPreloaded) {
1024
+ return Promise.resolve();
1025
+ }
1026
+ const options = this.widget.options;
1027
+ if (
1028
+ !options.dynamicColumnScriptEnabled ||
1029
+ !options.dynamicColumnScriptCode ||
1030
+ !options.dynamicColumnAutoLoad
1031
+ ) {
1032
+ return Promise.resolve();
1033
+ }
1034
+ return this.loadDynamicColumnsFromApi({ isLoading: true }).catch(() => {});
621
1035
  },
622
1036
  getTableData: function () {
623
1037
  return this.widget.options.tableData;
@@ -709,7 +1123,7 @@ modules = {
709
1123
  },
710
1124
  createColumns() {
711
1125
  let rowWidgetList = [];
712
- let tableColumns = this.widget.options.tableColumns;
1126
+ let tableColumns = this.getEffectiveTableColumns();
713
1127
  let newColumns = [];
714
1128
  if (!this.widget.options.hideGridCheckBox) {
715
1129
  newColumns.push({
@@ -748,7 +1162,7 @@ modules = {
748
1162
  : false,
749
1163
  columnConfig: t,
750
1164
  },
751
- visible: t.show,
1165
+ visible: this.getColumnVisible(t),
752
1166
  slots: {},
753
1167
  };
754
1168
  applyColumnLabelIcon(col, t);
@@ -1114,6 +1528,7 @@ modules = {
1114
1528
  let dataTableConfig = formRef.$attrs.dataTableOption || {};
1115
1529
  this.dataTableConfig = dataTableConfig;
1116
1530
 
1531
+ this.ensureEffectiveColumnWidgets();
1117
1532
  let columns = this.createColumns();
1118
1533
  this.widgets = columns
1119
1534
  .filter((column) => !!column?.params?.widget)
@@ -1717,11 +2132,13 @@ modules = {
1717
2132
  }
1718
2133
  this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
1719
2134
  this.vxeOption = opts;
1720
- if (!isQueryTable) {
1721
- setTimeout(() => {
1722
- this.loadAccessData(1);
1723
- }, 20);
1724
- }
2135
+ this.tryAutoLoadDynamicColumns().finally(() => {
2136
+ if (!isQueryTable) {
2137
+ setTimeout(() => {
2138
+ this.loadAccessData(1);
2139
+ }, 20);
2140
+ }
2141
+ });
1725
2142
  });
1726
2143
  },
1727
2144
  loodHandleColumns(columns, callback) {