From 8e461e8aede09e9a319d8d1db1e74634196f8be9 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 25 Feb 2025 16:55:15 +0800 Subject: [PATCH] perf: update quick filter expand setting --- src/components/Table/ListTable/index.vue | 22 ++++++++++---- src/layout/components/TabPage/index.vue | 4 +-- src/utils/common.js | 37 ++++++++++++++++++++++++ src/views/pam/Account/index.vue | 4 +-- 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/components/Table/ListTable/index.vue b/src/components/Table/ListTable/index.vue index a9fa76b65..2c0fe20b1 100644 --- a/src/components/Table/ListTable/index.vue +++ b/src/components/Table/ListTable/index.vue @@ -43,6 +43,7 @@ import Emitter from '@/mixins/emitter' import AutoDataTable from '../AutoDataTable/index.vue' import QuickFilter from './TableAction/QuickFilter.vue' import { getDayEnd, getDaysAgo } from '@/utils/time' +import { ObjectLocalStorage } from '@/utils/common' export default { name: 'ListTable', @@ -100,11 +101,25 @@ export default { extraQuery: extraQuery, actionInit: this.headerActions.has === false, initQuery: {}, - filterExpand: localStorage.getItem('filterExpand') !== '0' + tablePath: new URL(this.tableConfig.url || '', 'http://127.0.0.1').pathname, + objStorage: new ObjectLocalStorage('filterExpand'), + iFilterExpand: null } }, computed: { ...mapGetters(['currentOrgIsRoot']), + filterExpand: { + get() { + if (this.iFilterExpand !== null) { + return this.iFilterExpand + } + return this.objStorage.get(this.tablePath) + }, + set(val) { + this.iFilterExpand = val + this.objStorage.set(this.tablePath, val) + } + }, iHasQuickFilter() { const has = (this.quickFilters && this.quickFilters.length > 0) || @@ -213,11 +228,6 @@ export default { this.$log.debug('ListTable: found colConfig change') }, deep: true - }, - filterExpand: { - handler(val) { - localStorage.setItem('filterExpand', val ? '1' : '0') - } } }, mounted() { diff --git a/src/layout/components/TabPage/index.vue b/src/layout/components/TabPage/index.vue index bd3c377d0..89ff31cd8 100644 --- a/src/layout/components/TabPage/index.vue +++ b/src/layout/components/TabPage/index.vue @@ -132,14 +132,14 @@ export default { handleTabClick(tab) { this.$emit('tab-click', tab) this.iActiveMenu = tab.name - // this.$cookie.set(this.$route.name, tab.name, 1) + this.$cookie.set('activeTab', tab.name, 1) }, getPropActiveTab() { let activeTab = '' const preActiveTabs = [ this.$route.query['tab'], - // this.$cookie.get(this.$route.name), + this.$cookie.get('activeTab'), this.activeMenu ] diff --git a/src/utils/common.js b/src/utils/common.js index 0630f18b8..3e2187d5a 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -370,3 +370,40 @@ export function openNewWindow(url) { window.sessionStorage.setItem('newWindowCount', `${count + 1}`) window.open(url, '_blank', params) } + +export class ObjectLocalStorage { + constructor(key) { + this.key = key + } + + b64(val) { + return btoa(unescape(encodeURIComponent(val))) + } + + getObject() { + const stored = window.localStorage.getItem(this.key) + let value = {} + try { + value = JSON.parse(stored) + } catch (e) { + console.warn('localStorage value is not a valid JSON: ', this.key) + } + if (typeof value !== 'object') { + value = {} + } + return value + } + + get(attr) { + const obj = this.getObject(this.key) + const attrSafe = this.b64(attr) + return obj[attrSafe] + } + + set(attr, value) { + const obj = this.getObject(this.key) + const attrSafe = this.b64(attr) + obj[attrSafe] = value + window.localStorage.setItem(this.key, JSON.stringify(obj)) + } +} diff --git a/src/views/pam/Account/index.vue b/src/views/pam/Account/index.vue index c42d9dc92..b5dc70d7d 100644 --- a/src/views/pam/Account/index.vue +++ b/src/views/pam/Account/index.vue @@ -24,13 +24,13 @@ export default { submenu: [ { name: 'account', - title: this.$t('Account'), + title: this.$t('Accounts'), icon: 'fa-key', component: () => import('@/views/pam/Account/AccountList.vue') }, { name: 'asset', - title: this.$t('Asset'), + title: this.$t('Assets'), icon: 'fa-inbox', component: () => import('@/views/pam/Account/AssetList.vue') },