perf: update quick filter expand setting

This commit is contained in:
ibuler
2025-02-25 16:55:15 +08:00
committed by 老广
parent b6ae2aa2f8
commit 8e461e8aed
4 changed files with 57 additions and 10 deletions

View File

@@ -43,6 +43,7 @@ import Emitter from '@/mixins/emitter'
import AutoDataTable from '../AutoDataTable/index.vue' import AutoDataTable from '../AutoDataTable/index.vue'
import QuickFilter from './TableAction/QuickFilter.vue' import QuickFilter from './TableAction/QuickFilter.vue'
import { getDayEnd, getDaysAgo } from '@/utils/time' import { getDayEnd, getDaysAgo } from '@/utils/time'
import { ObjectLocalStorage } from '@/utils/common'
export default { export default {
name: 'ListTable', name: 'ListTable',
@@ -100,11 +101,25 @@ export default {
extraQuery: extraQuery, extraQuery: extraQuery,
actionInit: this.headerActions.has === false, actionInit: this.headerActions.has === false,
initQuery: {}, 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: { computed: {
...mapGetters(['currentOrgIsRoot']), ...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() { iHasQuickFilter() {
const has = const has =
(this.quickFilters && this.quickFilters.length > 0) || (this.quickFilters && this.quickFilters.length > 0) ||
@@ -213,11 +228,6 @@ export default {
this.$log.debug('ListTable: found colConfig change') this.$log.debug('ListTable: found colConfig change')
}, },
deep: true deep: true
},
filterExpand: {
handler(val) {
localStorage.setItem('filterExpand', val ? '1' : '0')
}
} }
}, },
mounted() { mounted() {

View File

@@ -132,14 +132,14 @@ export default {
handleTabClick(tab) { handleTabClick(tab) {
this.$emit('tab-click', tab) this.$emit('tab-click', tab)
this.iActiveMenu = tab.name this.iActiveMenu = tab.name
// this.$cookie.set(this.$route.name, tab.name, 1) this.$cookie.set('activeTab', tab.name, 1)
}, },
getPropActiveTab() { getPropActiveTab() {
let activeTab = '' let activeTab = ''
const preActiveTabs = [ const preActiveTabs = [
this.$route.query['tab'], this.$route.query['tab'],
// this.$cookie.get(this.$route.name), this.$cookie.get('activeTab'),
this.activeMenu this.activeMenu
] ]

View File

@@ -370,3 +370,40 @@ export function openNewWindow(url) {
window.sessionStorage.setItem('newWindowCount', `${count + 1}`) window.sessionStorage.setItem('newWindowCount', `${count + 1}`)
window.open(url, '_blank', params) 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))
}
}

View File

@@ -24,13 +24,13 @@ export default {
submenu: [ submenu: [
{ {
name: 'account', name: 'account',
title: this.$t('Account'), title: this.$t('Accounts'),
icon: 'fa-key', icon: 'fa-key',
component: () => import('@/views/pam/Account/AccountList.vue') component: () => import('@/views/pam/Account/AccountList.vue')
}, },
{ {
name: 'asset', name: 'asset',
title: this.$t('Asset'), title: this.$t('Assets'),
icon: 'fa-inbox', icon: 'fa-inbox',
component: () => import('@/views/pam/Account/AssetList.vue') component: () => import('@/views/pam/Account/AssetList.vue')
}, },