diff --git a/src/components/AutoDataTable/index.vue b/src/components/AutoDataTable/index.vue index 26ea2428c..b1a74c196 100644 --- a/src/components/AutoDataTable/index.vue +++ b/src/components/AutoDataTable/index.vue @@ -26,7 +26,7 @@ import { ObjectRelatedFormatter } from '@/components/TableFormatters' import i18n from '@/i18n/i18n' -import { newURL } from '@/utils/common' +import { newURL, replaceAllUUID } from '@/utils/common' import ColumnSettingPopover from './components/ColumnSettingPopover' export default { @@ -323,7 +323,8 @@ export default { const _tableConfig = localStorage.getItem('tableConfig') ? JSON.parse(localStorage.getItem('tableConfig')) : {} - const tableName = this.config.name || this.$route.name + '_' + newURL(this.iConfig.url).pathname + let tableName = this.config.name || this.$route.name + '_' + newURL(this.iConfig.url).pathname + tableName = replaceAllUUID(tableName) const configShowColumnsNames = _.get(_tableConfig[tableName], 'showColumns', null) let showColumnsNames = configShowColumnsNames || defaultColumnsNames if (showColumnsNames.length === 0) { @@ -371,7 +372,10 @@ export default { const _tableConfig = localStorage.getItem('tableConfig') ? JSON.parse(localStorage.getItem('tableConfig')) : {} - const tableName = this.config.name || this.$route.name + '_' + newURL(url).pathname + let tableName = this.config.name || this.$route.name + '_' + newURL(url).pathname + // 替换url中的uuid,避免同一个类型接口生成多个key,localStorage中的数据无法共用 + tableName = replaceAllUUID(tableName) + _tableConfig[tableName] = { 'showColumns': columns } diff --git a/src/utils/common.js b/src/utils/common.js index 845e2d285..dc3be3411 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -168,6 +168,13 @@ export function replaceUUID(s, n) { return s.replace(uuidPattern, n) } +export function replaceAllUUID(string, replacement = '*') { + if (hasUUID(string)) { + string = string.replace(/[0-9a-zA-Z\-]{36}/g, replacement) + } + return string +} + export function getDaysAgo(days, now) { if (!now) { now = new Date()