|
@@ -37,7 +37,13 @@ export default {
|
|
|
async getTabColumns() {
|
|
async getTabColumns() {
|
|
|
const res = await this.getByTableId(this.cacheKeyUrl);
|
|
const res = await this.getByTableId(this.cacheKeyUrl);
|
|
|
if (res?.columnConfig?.length > 0) {
|
|
if (res?.columnConfig?.length > 0) {
|
|
|
- this.setStorage(this.cacheKeyUrl + 'Cols', res.columnConfig);
|
|
|
|
|
|
|
+ //对比接口返回和本地columns
|
|
|
|
|
+ let { nlist, type } = this.columnsContrast(res.columnConfig);
|
|
|
|
|
+ //有更新则更新服务缓存配置
|
|
|
|
|
+ if (type) {
|
|
|
|
|
+ this.saveColumns(nlist);
|
|
|
|
|
+ }
|
|
|
|
|
+ this.setStorage(this.cacheKeyUrl + 'Cols', nlist);
|
|
|
// 更新列
|
|
// 更新列
|
|
|
if (this._computedWatchers && this._computedWatchers.columns) {
|
|
if (this._computedWatchers && this._computedWatchers.columns) {
|
|
|
// console.log('columns 是计算属性');
|
|
// console.log('columns 是计算属性');
|
|
@@ -49,6 +55,46 @@ export default {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
+ //服务器和本地配置columns对比
|
|
|
|
|
+ columnsContrast(list) {
|
|
|
|
|
+ const key = 'label';
|
|
|
|
|
+ var updateType = 0;
|
|
|
|
|
+ let sList = list.filter((d, i, r) => {
|
|
|
|
|
+ return d[key];
|
|
|
|
|
+ });
|
|
|
|
|
+ let devColumns =
|
|
|
|
|
+ this.newColumns?.length > 0 ? this.newColumns : this.columns;
|
|
|
|
|
+ let dList = devColumns.filter((d, i, r) => {
|
|
|
|
|
+ return d[key] && d[key] !== '序号';
|
|
|
|
|
+ });
|
|
|
|
|
+ const keysA = new Set(sList.map((item) => item[key]));
|
|
|
|
|
+ const keysB = new Set(dList.map((item) => item[key]));
|
|
|
|
|
+ // 本地 比 缓存服务端 多的对象(新增)
|
|
|
|
|
+ const added = dList.filter((item) => !keysA.has(item[key]));
|
|
|
|
|
+ // 本地 比 缓存服务端 少的对象(删除)
|
|
|
|
|
+ const removed = sList.filter((item) => !keysB.has(item[key]));
|
|
|
|
|
+ const removedPropSet = new Set(removed.map((item) => item[key]));
|
|
|
|
|
+ // 删除 缓存中 中被移除的对象
|
|
|
|
|
+ const keptA = list.filter((item) => !removedPropSet.has(item[key]));
|
|
|
|
|
+ added.forEach((item) => {
|
|
|
|
|
+ //新增columns字段prop参数为必填
|
|
|
|
|
+ if (item.prop) {
|
|
|
|
|
+ item.id = item.prop;
|
|
|
|
|
+ } else if (item.columnKey) {
|
|
|
|
|
+ item.id = item.columnKey;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ item.prop = item.label;
|
|
|
|
|
+ item.id = item.label;
|
|
|
|
|
+ }
|
|
|
|
|
+ item.checked = true;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (added.length > 0 || removed.length > 0) {
|
|
|
|
|
+ updateType = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 合并保留的对象和新增的对象
|
|
|
|
|
+ return { nlist: [...keptA, ...added], type: updateType };
|
|
|
|
|
+ },
|
|
|
|
|
|
|
|
// 提交columns配置
|
|
// 提交columns配置
|
|
|
async saveColumns(e) {
|
|
async saveColumns(e) {
|