gxxc-util 1.0.0 → 1.0.1

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.
@@ -90,41 +90,43 @@ const tem_compare_version = (version1, version2) => {
90
90
  * @param {TableHeaderItem} initial 默认
91
91
  */
92
92
  const tem_get_tableHeader = (keyVal, cache, initial) => {
93
+ /// 原始 map
94
+ const _initialMap = {};
95
+ initial.map(item => {
96
+ _initialMap[item.key ?? ""] = { ...item };
97
+ });
98
+ /// 缓存 map
99
+ const _cacheMap = {};
100
+ cache.map(item => {
101
+ _cacheMap[item.key ?? ""] = { ...item };
102
+ });
93
103
  const returnList = [];
94
- const transformList = [];
104
+ /// 通过服务端返回 key 筛选选显示项
95
105
  if (keyVal) {
96
106
  Object.keys(keyVal)?.forEach((key) => {
97
- const item = {};
98
- item.key = key;
99
- item.name = keyVal[key];
100
- transformList.push(item);
101
- });
102
- }
103
- transformList.forEach((i) => {
104
- initial?.forEach((j) => {
105
- if (cache?.length > 0 && initial?.length === cache?.length) {
106
- cache?.forEach((k) => {
107
- if (i?.key === j?.key && i?.key === k?.key) {
108
- i = { ...i, ...j, ...k };
109
- i.width = j?.width;
110
- i.sort = k?.sort ? k?.sort : j.sort;
111
- i.selected = k?.selected === undefined ? true : k?.selected;
112
- returnList.push(i);
113
- }
114
- });
107
+ let _item = _initialMap[key];
108
+ const _cacheItem = _cacheMap[key ?? ""];
109
+ const name = keyVal[key];
110
+ /// 有缓冲并且 服务端 返回表头
111
+ if (_item && _cacheItem) {
112
+ _cacheItem.name = name;
113
+ returnList.push(_cacheItem);
114
+ }
115
+ else if (_item) {
116
+ _item.name = name;
117
+ returnList.push(_item);
115
118
  }
116
119
  else {
117
- if (i?.key === j?.key) {
118
- i = { ...i, ...j };
119
- i.selected = true;
120
- returnList.push(i);
121
- }
120
+ console.warn("列表服务端返回" + key + "未配置");
122
121
  }
123
122
  });
124
- });
125
- if (initial[initial.length - 1]?.key === "operate") {
126
- returnList.push(initial[initial.length - 1]);
127
123
  }
124
+ /// 添加 操作项
125
+ const operateItem = _initialMap["operate"];
126
+ if (operateItem) {
127
+ returnList.push(operateItem);
128
+ }
129
+ /// 排序
128
130
  returnList.sort((a, b) => {
129
131
  return (a?.sort ?? 1) - (b?.sort ?? 2);
130
132
  });
@@ -69,41 +69,43 @@ const tem_compare_version = (version1, version2) => {
69
69
  * @param {TableHeaderItem} initial 默认
70
70
  */
71
71
  const tem_get_tableHeader = (keyVal, cache, initial) => {
72
+ /// 原始 map
73
+ const _initialMap = {};
74
+ initial.map(item => {
75
+ _initialMap[item.key ?? ""] = { ...item };
76
+ });
77
+ /// 缓存 map
78
+ const _cacheMap = {};
79
+ cache.map(item => {
80
+ _cacheMap[item.key ?? ""] = { ...item };
81
+ });
72
82
  const returnList = [];
73
- const transformList = [];
83
+ /// 通过服务端返回 key 筛选选显示项
74
84
  if (keyVal) {
75
85
  Object.keys(keyVal)?.forEach((key) => {
76
- const item = {};
77
- item.key = key;
78
- item.name = keyVal[key];
79
- transformList.push(item);
80
- });
81
- }
82
- transformList.forEach((i) => {
83
- initial?.forEach((j) => {
84
- if (cache?.length > 0 && initial?.length === cache?.length) {
85
- cache?.forEach((k) => {
86
- if (i?.key === j?.key && i?.key === k?.key) {
87
- i = { ...i, ...j, ...k };
88
- i.width = j?.width;
89
- i.sort = k?.sort ? k?.sort : j.sort;
90
- i.selected = k?.selected === undefined ? true : k?.selected;
91
- returnList.push(i);
92
- }
93
- });
86
+ let _item = _initialMap[key];
87
+ const _cacheItem = _cacheMap[key ?? ""];
88
+ const name = keyVal[key];
89
+ /// 有缓冲并且 服务端 返回表头
90
+ if (_item && _cacheItem) {
91
+ _cacheItem.name = name;
92
+ returnList.push(_cacheItem);
93
+ }
94
+ else if (_item) {
95
+ _item.name = name;
96
+ returnList.push(_item);
94
97
  }
95
98
  else {
96
- if (i?.key === j?.key) {
97
- i = { ...i, ...j };
98
- i.selected = true;
99
- returnList.push(i);
100
- }
99
+ console.warn("列表服务端返回" + key + "未配置");
101
100
  }
102
101
  });
103
- });
104
- if (initial[initial.length - 1]?.key === "operate") {
105
- returnList.push(initial[initial.length - 1]);
106
102
  }
103
+ /// 添加 操作项
104
+ const operateItem = _initialMap["operate"];
105
+ if (operateItem) {
106
+ returnList.push(operateItem);
107
+ }
108
+ /// 排序
107
109
  returnList.sort((a, b) => {
108
110
  return (a?.sort ?? 1) - (b?.sort ?? 2);
109
111
  });
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.52.8"
8
+ "packageVersion": "7.52.13"
9
9
  }
10
10
  ]
11
11
  }