@lx-frontend/wrap-element-ui 1.0.23-beta.1 → 1.0.24-beta.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.
package/package.json
CHANGED
|
@@ -14,6 +14,38 @@ interface IViewSettingParams {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/** 默认迁移配置 */
|
|
18
|
+
const defaultStorgeMigrationConfig: Record<number, {
|
|
19
|
+
/** 迁移方法 */
|
|
20
|
+
migration: (
|
|
21
|
+
/** 当前本地配置 */
|
|
22
|
+
currentConfig: any,
|
|
23
|
+
/** 当前的列配置 */
|
|
24
|
+
columns: IColumnConfig[]
|
|
25
|
+
) => ({ version: number, config: any })
|
|
26
|
+
/** 迁移到的下一个版本号 */
|
|
27
|
+
nextVersion?: number
|
|
28
|
+
}> = {
|
|
29
|
+
'0': {
|
|
30
|
+
migration: (config: { showingColumns: string[], leftFixedColumnCount: number }, columns: IColumnConfig[]) => {
|
|
31
|
+
return {
|
|
32
|
+
config: {
|
|
33
|
+
fields: columns.reduce((acc, curr) => {
|
|
34
|
+
acc[curr.prop] = {
|
|
35
|
+
hidden: config.showingColumns.find(v => v === curr.prop) ? false : curr.defaultHide ?? false,
|
|
36
|
+
order: config.showingColumns.findIndex(v => v === curr.prop) ?? 0,
|
|
37
|
+
}
|
|
38
|
+
return acc;
|
|
39
|
+
}, {} as Record<string, { hidden: boolean, order: number }>),
|
|
40
|
+
leftFixedColumnCount: config.leftFixedColumnCount,
|
|
41
|
+
},
|
|
42
|
+
version: 1,
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
nextVersion: 1,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
17
49
|
export function useViewSetting({
|
|
18
50
|
showingColumns,
|
|
19
51
|
actualColumns,
|
|
@@ -33,8 +65,17 @@ export function useViewSetting({
|
|
|
33
65
|
const saveSettingToStorge = async() => {
|
|
34
66
|
await nextTick()
|
|
35
67
|
localStorage.setItem(storageKey.value, JSON.stringify({
|
|
36
|
-
|
|
37
|
-
|
|
68
|
+
config: {
|
|
69
|
+
fields: props.columnConfig.reduce((acc, curr) => {
|
|
70
|
+
acc[curr.prop] = {
|
|
71
|
+
hidden: showingColumns.value.find(v => v === curr.prop) ? false : curr.defaultHide ?? false,
|
|
72
|
+
order: showingColumns.value.findIndex(v => v === curr.prop) ?? 0,
|
|
73
|
+
}
|
|
74
|
+
return acc;
|
|
75
|
+
}, {} as Record<string, { hidden: boolean, order: number }>),
|
|
76
|
+
leftFixedColumnCount: leftFixedColumnCount.value,
|
|
77
|
+
},
|
|
78
|
+
version: 1
|
|
38
79
|
}))
|
|
39
80
|
};
|
|
40
81
|
|
|
@@ -66,7 +107,6 @@ export function useViewSetting({
|
|
|
66
107
|
watch(
|
|
67
108
|
() => props.columnConfig,
|
|
68
109
|
async(val) => {
|
|
69
|
-
const _keys = new Set(val.map(c => (c.prop)));
|
|
70
110
|
const _cache = localStorage.getItem(storageKey.value);
|
|
71
111
|
const setColumns = () => updateShowingColumns(val.filter(v => !v.defaultHide).map(c => c.prop));
|
|
72
112
|
if (!_cache) {
|
|
@@ -75,13 +115,36 @@ export function useViewSetting({
|
|
|
75
115
|
} else {
|
|
76
116
|
try {
|
|
77
117
|
// 缓存数据字段可能随着更新导致对不上,清理无效数据,防止出问题
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
118
|
+
const handleMigration = (_cache: any) => {
|
|
119
|
+
const version = _cache?.version ?? 0
|
|
120
|
+
if (defaultStorgeMigrationConfig[version]) {
|
|
121
|
+
const __cache = defaultStorgeMigrationConfig[version].migration(_cache, val)
|
|
122
|
+
if (defaultStorgeMigrationConfig[version].nextVersion) {
|
|
123
|
+
return handleMigration(__cache)
|
|
124
|
+
} else {
|
|
125
|
+
return __cache
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
return _cache
|
|
129
|
+
}
|
|
83
130
|
}
|
|
84
|
-
|
|
131
|
+
|
|
132
|
+
const cache = handleMigration(JSON.parse(_cache)) as {
|
|
133
|
+
version: number,
|
|
134
|
+
config: {
|
|
135
|
+
fields: Record<string, { hidden: boolean, order: number }>,
|
|
136
|
+
leftFixedColumnCount: number
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
updateShowingColumns(
|
|
141
|
+
Object.entries(cache.config.fields)
|
|
142
|
+
.filter(v => !v[1].hidden)
|
|
143
|
+
.sort((a, b) => a[1].order - b[1].order)
|
|
144
|
+
.map(v => v[0])
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
const _leftFixedColumnCount = Number(cache?.config?.leftFixedColumnCount)
|
|
85
148
|
leftFixedColumnCount.value = isNaN(_leftFixedColumnCount) ? (props.leftFixedCount as number) : _leftFixedColumnCount;
|
|
86
149
|
// 写入清理后的数据
|
|
87
150
|
saveSettingToStorge();
|
|
@@ -110,7 +110,6 @@
|
|
|
110
110
|
v-if="colorFilterConfig"
|
|
111
111
|
:head-active="isColumnHeadActive(colorFilterConfig)"
|
|
112
112
|
:column="colorFilterConfig"
|
|
113
|
-
:showing-columns="showingColumns"
|
|
114
113
|
:temp-summary-list="tempSummaryList"
|
|
115
114
|
:temp-sort-prop="tempSortProp"
|
|
116
115
|
:temp-sort-type="tempSortType"
|
|
@@ -155,7 +154,6 @@
|
|
|
155
154
|
<biz-table-header-popover
|
|
156
155
|
:head-active="isColumnHeadActive(column)"
|
|
157
156
|
:column="column"
|
|
158
|
-
:showing-columns="showingColumns"
|
|
159
157
|
:temp-summary-list="tempSummaryList"
|
|
160
158
|
:temp-sort-prop="tempSortProp"
|
|
161
159
|
:temp-sort-type="tempSortType"
|
|
@@ -248,8 +246,9 @@
|
|
|
248
246
|
<!-- 内置编辑类型 -->
|
|
249
247
|
<biz-edit-cell
|
|
250
248
|
v-else-if="column.editType"
|
|
251
|
-
|
|
249
|
+
:value="editingRowData[column.prop]"
|
|
252
250
|
:column="column"
|
|
251
|
+
@input="val => { editingRowData[column.prop] = val }"
|
|
253
252
|
/>
|
|
254
253
|
<!-- 不支持编辑 -->
|
|
255
254
|
<slot
|
|
@@ -267,8 +266,9 @@
|
|
|
267
266
|
<!-- 当前行编辑中,内置编辑类型 -->
|
|
268
267
|
<biz-edit-cell
|
|
269
268
|
v-if="editingRowIndex === scope.$index && column.editType"
|
|
270
|
-
|
|
269
|
+
:value="editingRowData[column.prop]"
|
|
271
270
|
:column="column"
|
|
271
|
+
@input="val => { editingRowData[column.prop] = val }"
|
|
272
272
|
/>
|
|
273
273
|
<!-- 当前行编辑中,自定义编辑类型 -->
|
|
274
274
|
<slot
|