fix(BasicTable): showIndexColumn/showRowSelection cache should by route name (#3489)

This commit is contained in:
xachary 2024-01-02 09:46:41 +08:00 committed by GitHub
parent 98e2e4c89a
commit d88f455cd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 16 deletions

View File

@ -210,7 +210,9 @@
// showIndexColumn // showIndexColumn
showIndexColumnUpdate(e.target.checked); showIndexColumnUpdate(e.target.checked);
// showIndexColumn // showIndexColumn
props.cache && tableSettingStore.setShowIndexColumn(e.target.checked); props.cache &&
typeof route.name === 'string' &&
tableSettingStore.setShowIndexColumn(route.name, e.target.checked);
}; };
// //
@ -220,7 +222,9 @@
// showRowSelection // showRowSelection
showRowSelectionUpdate(e.target.checked); showRowSelectionUpdate(e.target.checked);
// showRowSelection // showRowSelection
props.cache && tableSettingStore.setShowRowSelection(e.target.checked); props.cache &&
typeof route.name === 'string' &&
tableSettingStore.setShowRowSelection(route.name, e.target.checked);
}; };
// //
@ -435,12 +439,18 @@
// //
const restore = () => { const restore = () => {
// if (typeof route.name === 'string') {
if (typeof tableSettingStore.getShowIndexColumn === 'boolean') { const isIndexColumnShowCache = tableSettingStore.getShowIndexColumn(route.name);
isIndexColumnShow.value = defaultIsIndexColumnShow && tableSettingStore.getShowIndexColumn; //
} if (typeof isIndexColumnShowCache === 'boolean') {
if (typeof tableSettingStore.getShowRowSelection === 'boolean') { isIndexColumnShow.value = defaultIsIndexColumnShow && isIndexColumnShowCache;
isRowSelectionShow.value = defaultIsRowSelectionShow && tableSettingStore.getShowRowSelection; }
const isRowSelectionShowCache = tableSettingStore.getShowRowSelection(route.name);
//
if (typeof isRowSelectionShowCache === 'boolean') {
isRowSelectionShow.value = defaultIsRowSelectionShow && isRowSelectionShowCache;
}
} }
// //
onIndexColumnShowChange({ onIndexColumnShowChange({

View File

@ -26,11 +26,15 @@ export const useTableSettingStore = defineStore({
}, },
// //
getShowIndexColumn(state) { getShowIndexColumn(state) {
return state.setting?.showIndexColumn; return (routerName: string) => {
return state.setting?.showIndexColumn?.[routerName];
};
}, },
// //
getShowRowSelection(state) { getShowRowSelection(state) {
return state.setting?.showRowSelection; return (routerName: string) => {
return state.setting?.showRowSelection?.[routerName];
};
}, },
// //
getColumns(state) { getColumns(state) {
@ -59,18 +63,24 @@ export const useTableSettingStore = defineStore({
); );
}, },
// //
setShowIndexColumn(show: boolean) { setShowIndexColumn(routerName: string, show: boolean) {
this.setTableSetting( this.setTableSetting(
Object.assign({}, this.setting, { Object.assign({}, this.setting, {
showIndexColumn: show, showIndexColumn: {
...this.setting?.showIndexColumn,
[routerName]: show,
},
}), }),
); );
}, },
// //
setShowRowSelection(show: boolean) { setShowRowSelection(routerName: string, show: boolean) {
this.setTableSetting( this.setTableSetting(
Object.assign({}, this.setting, { Object.assign({}, this.setting, {
showRowSelection: show, showRowSelection: {
...this.setting?.showRowSelection,
[routerName]: show,
},
}), }),
); );
}, },

4
types/store.d.ts vendored
View File

@ -54,7 +54,7 @@ export interface BeforeMiniState {
export interface TableSetting { export interface TableSetting {
size: Nullable<SizeType>; size: Nullable<SizeType>;
showIndexColumn: Nullable<boolean>; showIndexColumn: Recordable<Nullable<boolean>>;
columns: Recordable<Nullable<Array<ColumnOptionsType>>>; columns: Recordable<Nullable<Array<ColumnOptionsType>>>;
showRowSelection: Nullable<boolean>; showRowSelection: Recordable<Nullable<boolean>>;
} }