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 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() {

View File

@@ -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
]

View File

@@ -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))
}
}

View File

@@ -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')
},