@yibozhang/pro-table 16.0.5 → 16.0.7

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.
@@ -857,17 +857,19 @@ class ProTableComponent {
857
857
  };
858
858
  });
859
859
  if (res.code === 0) {
860
- if (!isEqual(res.data.tabColumn, initColumns)) {
861
- const initRes = await this.persistRemoteColumns(initColumns);
862
- if (initRes) {
860
+ const serverColumns = Array.isArray(res?.data?.tabColumn)
861
+ ? res.data.tabColumn
862
+ : [];
863
+ // 以远程数据为主:保留远程顺序与显示状态,仅做字段结构合并(新增字段追加、删除字段过滤)
864
+ const merged = this.mergeServerColumnsWithInit(serverColumns, initColumns);
865
+ if (!isEqual(serverColumns, merged)) {
866
+ const persistRes = await this.persistRemoteColumns(merged);
867
+ if (persistRes) {
863
868
  this.queryDynamicColumns();
864
869
  }
865
870
  return false;
866
871
  }
867
- else {
868
- console.log("一致");
869
- return true;
870
- }
872
+ return true;
871
873
  }
872
874
  else if (res.code === 10) {
873
875
  // code === 10 表示未初始化,需要继续执行后续逻辑
@@ -877,6 +879,38 @@ class ProTableComponent {
877
879
  return false;
878
880
  }
879
881
  }
882
+ mergeServerColumnsWithInit(serverColumns, initColumns) {
883
+ const initByField = new Map();
884
+ initColumns.forEach((c) => initByField.set(c.field, c));
885
+ const merged = [];
886
+ const seen = new Set();
887
+ // 1) 保留远程顺序与显示状态;同步 header/sortName;过滤掉前端已不存在的 field
888
+ serverColumns.forEach((sc) => {
889
+ const field = sc?.field;
890
+ if (!field || !initByField.has(field) || seen.has(field))
891
+ return;
892
+ const init = initByField.get(field);
893
+ merged.push({
894
+ ...sc,
895
+ header: init.header,
896
+ sortName: init.sortName ?? null,
897
+ });
898
+ seen.add(field);
899
+ });
900
+ // 2) 新增字段(远程不存在)追加到末尾,默认显示用 initColumns 的 isShow
901
+ initColumns.forEach((ic) => {
902
+ if (seen.has(ic.field))
903
+ return;
904
+ merged.push({
905
+ field: ic.field,
906
+ isShow: ic.isShow,
907
+ header: ic.header,
908
+ sortName: ic.sortName ?? null,
909
+ });
910
+ seen.add(ic.field);
911
+ });
912
+ return merged;
913
+ }
880
914
  async queryDynamicColumns() {
881
915
  if (!this.tableName || !this.columnRemote)
882
916
  return;