@lx-frontend/wrap-element-ui 1.0.23 → 1.0.24-beta.2

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@lx-frontend/wrap-element-ui",
3
- "version": "1.0.23",
3
+ "version": "1.0.24-beta.2",
4
4
  "description": "wrap-element-ui",
5
5
  "author": "",
6
6
  "main": "src/components/index.ts",
@@ -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[]>
@@ -14,6 +14,38 @@ interface IViewSettingParams {
14
14
  }
15
15
  }
16
16
 
17
+ /** 默认迁移配置 */
18
+ const storgeSchemaMigrationConfig: Record<number, {
19
+ /** 迁移方法 */
20
+ migration: (
21
+ /** 当前本地配置 */
22
+ currentConfig: any,
23
+ /** 当前的列配置 */
24
+ columns: IColumnConfig[]
25
+ ) => ({ schemaVersion: number, config: any, version?: string })
26
+ /** 迁移到的下一个版本号 */
27
+ nextSchemaVersion?: 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 : true,
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
+ schemaVersion: 1,
43
+ }
44
+ },
45
+ nextSchemaVersion: 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
- showingColumns: showingColumns.value,
37
- leftFixedColumnCount: leftFixedColumnCount.value
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
+ schemaVersion: 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,35 @@ export function useViewSetting({
75
115
  } else {
76
116
  try {
77
117
  // 缓存数据字段可能随着更新导致对不上,清理无效数据,防止出问题
78
- const cache = JSON.parse(_cache);
79
- if (!cache.showingColumns || !Array.isArray(cache.showingColumns)) {
80
- setColumns();
81
- } else {
82
- updateShowingColumns(cache.showingColumns.filter(key => _keys.has(key)))
118
+ const handleMigration = (_cache: any) => {
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)
130
+ }
131
+
132
+ return storgeSchemaMigrationConfig[schemaVersion].nextSchemaVersion
133
+ ? handleMigration(__cache)
134
+ : __cache
83
135
  }
84
- const _leftFixedColumnCount = Number(cache?.leftFixedColumnCount)
136
+
137
+ const cache = handleMigration(JSON.parse(_cache)) as SettingStorgeConfig;
138
+
139
+ updateShowingColumns(
140
+ Object.entries(cache.config.fields)
141
+ .filter(v => !v[1].hidden)
142
+ .sort((a, b) => a[1].order - b[1].order)
143
+ .map(v => v[0])
144
+ )
145
+
146
+ const _leftFixedColumnCount = Number(cache?.config?.leftFixedColumnCount)
85
147
  leftFixedColumnCount.value = isNaN(_leftFixedColumnCount) ? (props.leftFixedCount as number) : _leftFixedColumnCount;
86
148
  // 写入清理后的数据
87
149
  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
- v-model="editingRowData[column.prop]"
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
- v-model="editingRowData[column.prop]"
269
+ :value="editingRowData[column.prop]"
271
270
  :column="column"
271
+ @input="val => { editingRowData[column.prop] = val }"
272
272
  />
273
273
  <!-- 当前行编辑中,自定义编辑类型 -->
274
274
  <slot
@@ -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