@lx-frontend/wrap-element-ui 1.0.24-beta.1 → 1.0.24-beta.3
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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ref, watch, Ref, computed, nextTick } from "vue"
|
|
2
|
-
import { IColumnConfig, IProps } from "../types"
|
|
2
|
+
import { IColumnConfig, IProps, SettingStorgeConfig } from "../types"
|
|
3
3
|
|
|
4
4
|
interface IViewSettingParams {
|
|
5
5
|
showingColumns: Ref<string[]>
|
|
@@ -15,16 +15,16 @@ interface IViewSettingParams {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/** 默认迁移配置 */
|
|
18
|
-
const
|
|
18
|
+
const storgeSchemaMigrationConfig: Record<number, {
|
|
19
19
|
/** 迁移方法 */
|
|
20
20
|
migration: (
|
|
21
21
|
/** 当前本地配置 */
|
|
22
22
|
currentConfig: any,
|
|
23
23
|
/** 当前的列配置 */
|
|
24
24
|
columns: IColumnConfig[]
|
|
25
|
-
) => ({
|
|
25
|
+
) => ({ schemaVersion: number, config: any, version?: string })
|
|
26
26
|
/** 迁移到的下一个版本号 */
|
|
27
|
-
|
|
27
|
+
nextSchemaVersion?: number
|
|
28
28
|
}> = {
|
|
29
29
|
'0': {
|
|
30
30
|
migration: (config: { showingColumns: string[], leftFixedColumnCount: number }, columns: IColumnConfig[]) => {
|
|
@@ -32,17 +32,17 @@ const defaultStorgeMigrationConfig: Record<number, {
|
|
|
32
32
|
config: {
|
|
33
33
|
fields: columns.reduce((acc, curr) => {
|
|
34
34
|
acc[curr.prop] = {
|
|
35
|
-
hidden: config.showingColumns.find(v => v === curr.prop) ? false :
|
|
35
|
+
hidden: config.showingColumns.find(v => v === curr.prop) ? false : true,
|
|
36
36
|
order: config.showingColumns.findIndex(v => v === curr.prop) ?? 0,
|
|
37
37
|
}
|
|
38
38
|
return acc;
|
|
39
39
|
}, {} as Record<string, { hidden: boolean, order: number }>),
|
|
40
40
|
leftFixedColumnCount: config.leftFixedColumnCount,
|
|
41
41
|
},
|
|
42
|
-
|
|
42
|
+
schemaVersion: 1,
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
|
-
|
|
45
|
+
nextSchemaVersion: 1,
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -75,7 +75,7 @@ export function useViewSetting({
|
|
|
75
75
|
}, {} as Record<string, { hidden: boolean, order: number }>),
|
|
76
76
|
leftFixedColumnCount: leftFixedColumnCount.value,
|
|
77
77
|
},
|
|
78
|
-
|
|
78
|
+
schemaVersion: 1
|
|
79
79
|
}))
|
|
80
80
|
};
|
|
81
81
|
|
|
@@ -116,26 +116,25 @@ export function useViewSetting({
|
|
|
116
116
|
try {
|
|
117
117
|
// 缓存数据字段可能随着更新导致对不上,清理无效数据,防止出问题
|
|
118
118
|
const handleMigration = (_cache: any) => {
|
|
119
|
-
const
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
119
|
+
const schemaVersion = _cache?.schemaVersion ?? 0
|
|
120
|
+
if (!storgeSchemaMigrationConfig[schemaVersion]) return _cache
|
|
121
|
+
let __cache = storgeSchemaMigrationConfig[schemaVersion].migration(_cache, val)
|
|
122
|
+
|
|
123
|
+
// 处理当前schema版本需要处理的变更
|
|
124
|
+
const bizMigrationConfigs = (props.settingStorgeMigrationConfigs ?? []).filter(v => (v.schemaVersion ?? 1) === __cache.schemaVersion)
|
|
125
|
+
if (bizMigrationConfigs.length) {
|
|
126
|
+
__cache = bizMigrationConfigs.reduce((acc, curr) => ({
|
|
127
|
+
...curr.migration(acc.config, val),
|
|
128
|
+
schemaVersion: __cache.schemaVersion,
|
|
129
|
+
}), __cache)
|
|
129
130
|
}
|
|
131
|
+
|
|
132
|
+
return storgeSchemaMigrationConfig[schemaVersion].nextSchemaVersion
|
|
133
|
+
? handleMigration(__cache)
|
|
134
|
+
: __cache
|
|
130
135
|
}
|
|
131
136
|
|
|
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
|
-
};
|
|
137
|
+
const cache = handleMigration(JSON.parse(_cache)) as SettingStorgeConfig;
|
|
139
138
|
|
|
140
139
|
updateShowingColumns(
|
|
141
140
|
Object.entries(cache.config.fields)
|
|
@@ -339,7 +339,7 @@ import {
|
|
|
339
339
|
useDragSort,
|
|
340
340
|
} from './bizHooks'
|
|
341
341
|
|
|
342
|
-
import { ITableDataItem, IColumnConfig, IDefaultOperationType, IColorList } from './types';
|
|
342
|
+
import { ITableDataItem, IColumnConfig, IDefaultOperationType, IColorList, SettingStorgeMigrationConfigs } from './types';
|
|
343
343
|
|
|
344
344
|
// defineProps泛型参数如果从外部传入,编译报错
|
|
345
345
|
interface IProps {
|
|
@@ -382,6 +382,8 @@ interface IProps {
|
|
|
382
382
|
pageSizes?: number[]
|
|
383
383
|
/** 分页器展示数量 */
|
|
384
384
|
pagerCount?: number;
|
|
385
|
+
/** 设置的迁移配置 */
|
|
386
|
+
settingStorgeMigrationConfigs?: SettingStorgeMigrationConfigs
|
|
385
387
|
}
|
|
386
388
|
|
|
387
389
|
interface IEmits {
|
|
@@ -159,6 +159,20 @@ export type ITableDataItem = {
|
|
|
159
159
|
[k: string]: any;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
export type SettingStorgeConfig = {
|
|
163
|
+
version: string,
|
|
164
|
+
config: {
|
|
165
|
+
fields: Record<string, { hidden: boolean, order: number }>,
|
|
166
|
+
leftFixedColumnCount: number
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export type SettingStorgeMigrationConfigs = {
|
|
171
|
+
schemaVersion?: number
|
|
172
|
+
version: string
|
|
173
|
+
migration: (currentConfig: any, columns: IColumnConfig[]) => SettingStorgeConfig
|
|
174
|
+
}[]
|
|
175
|
+
|
|
162
176
|
export interface IProps {
|
|
163
177
|
dataList: ITableDataItem[];
|
|
164
178
|
columnConfig: IColumnConfig[];
|
|
@@ -174,6 +188,7 @@ export interface IProps {
|
|
|
174
188
|
dragSemiRange?: number;
|
|
175
189
|
loading?: boolean;
|
|
176
190
|
settingStorgeKey?: string
|
|
191
|
+
settingStorgeMigrationConfigs?: SettingStorgeMigrationConfigs
|
|
177
192
|
localSort?: boolean
|
|
178
193
|
localFilter?: boolean
|
|
179
194
|
currentPage: number
|