CN-801 下钻table的配置增加版本属性

This commit is contained in:
hyx
2022-11-18 14:21:23 +08:00
parent 4975f2425d
commit 4c107704e7
3 changed files with 25 additions and 47 deletions

View File

@@ -3,7 +3,7 @@ import router from '@/router'
import { sortByOrderNum, getWelcomeMenu } from '@/permission' import { sortByOrderNum, getWelcomeMenu } from '@/permission'
import { ElMessage } from 'element-plus' // dependent on utc plugin import { ElMessage } from 'element-plus' // dependent on utc plugin
import { storageKey, dbDrilldownTableConfig } from '@/utils/constants' import { storageKey, dbDrilldownTableConfig } from '@/utils/constants'
import { readDrilldownTableConfigByUser } from '@/utils/tools' import { getConfigVersion } from '@/utils/tools'
import { api } from '@/utils/api' import { api } from '@/utils/api'
import { db } from '@/indexedDB' import { db } from '@/indexedDB'
@@ -94,8 +94,14 @@ const user = {
const defaultConfigs = JSON.parse(res.page.list[0].cvalue) const defaultConfigs = JSON.parse(res.page.list[0].cvalue)
await db[dbDrilldownTableConfig].put({ await db[dbDrilldownTableConfig].put({
id: 'default', id: 'default',
config: defaultConfigs version: defaultConfigs.version,
config: defaultConfigs.config
}) })
let userId = localStorage.getItem(storageKey.userId)
let oldVersion = await getConfigVersion(userId)
if(oldVersion !== defaultConfigs.version ){
db[dbDrilldownTableConfig].delete(userId)
}
} }
}) })
get(api.config, { ckey: 'link_info' }).then(res => { get(api.config, { ckey: 'link_info' }).then(res => {

View File

@@ -932,7 +932,7 @@ export async function getDefaultCurTab (tableType, metric, columnName) {
return curTab return curTab
} }
export async function readDrilldownTableConfigByUser (tableType, curMetric) { export async function readDrilldownTableConfigByUser () {
// 获取用户定制的自定义配置 // 获取用户定制的自定义配置
const userId = localStorage.getItem(storageKey.userId) const userId = localStorage.getItem(storageKey.userId)
const userLocalCongfig = await db[dbDrilldownTableConfig].get({ id: userId }) const userLocalCongfig = await db[dbDrilldownTableConfig].get({ id: userId })
@@ -943,6 +943,17 @@ export async function readDrilldownTableConfigByUser (tableType, curMetric) {
return defaultDrillDownTableConfigs return defaultDrillDownTableConfigs
} }
export async function getConfigVersion (id) {
let defaultCongfigInDb = await db[dbDrilldownTableConfig].get({ id: id })
let version
if(defaultCongfigInDb) {
version = defaultCongfigInDb ? defaultCongfigInDb.version : ''
}else {
defaultCongfigInDb = await db[dbDrilldownTableConfig].get({ id: 'default' })
}
return version
}
export async function combinDrilldownTableWithUserConfig () { export async function combinDrilldownTableWithUserConfig () {
const defaultCongfigInDb = await db[dbDrilldownTableConfig].get({ id: 'default' }) const defaultCongfigInDb = await db[dbDrilldownTableConfig].get({ id: 'default' })
const defaultConfigs = defaultCongfigInDb ? defaultCongfigInDb.config : [] const defaultConfigs = defaultCongfigInDb ? defaultCongfigInDb.config : []
@@ -967,40 +978,6 @@ export async function combinDrilldownTableWithUserConfig () {
return defaultConfigs return defaultConfigs
} }
/*
export async function readDrilldownTableConfigByUser2 (tableType, curMetric) {
let list = []
// 获取用户定制的自定义配置,如果没有,则使用默认的自定义配置
const userId = localStorage.getItem(storageKey.userId)
const userLocalCongfig = await db[dbDrilldownTableConfig].get({ id: userId })
let defaultDrillDownTableConfigs = []
if (userLocalCongfig) {
defaultDrillDownTableConfigs = userLocalCongfig.config
if(defaultDrillDownTableConfigs && defaultDrillDownTableConfigs.length > 0){
const currentTableConfig = defaultDrillDownTableConfigs.find(config => config.route === tableType)
const commonTabList = currentTableConfig ? currentTableConfig.tabs : []
const tables = currentTableConfig ? currentTableConfig.tables : []
if (tables && tables.length > 0) {
const curTableOldConfig = tables.find(table => table.id === tableType)
const curTable = curTableOldConfig || null
if (curTable) {
if (curTable.hasMetricSearch) { // 有metric
const metricsList = curTable ? curTable.metrics : []
if (metricsList && metricsList.length > 0) {
const metricTab = metricsList.find(metric => metric.name === curMetric)
list = metricTab ? metricTab.tabs : []
}
} else { // 无metric
list = curTable ? curTable.tabs : []
}
//combineTabList(tableType, list, commonTabList)
}
}
}
}
return list
}
*/
export async function getUserDrilldownTableConfig (tableType, curMetric) { export async function getUserDrilldownTableConfig (tableType, curMetric) {
let list = [] let list = []
// 获取用户定制的自定义配置,如果没有,则使用默认的自定义配置 // 获取用户定制的自定义配置,如果没有,则使用默认的自定义配置

View File

@@ -199,7 +199,7 @@ import { ref } from 'vue'
import { operationType, unitTypes, networkTable, tableColumnType, networkDefaultLimit, curTabState, storageKey, dbDrilldownTableConfig, fromRoute } from '@/utils/constants' import { operationType, unitTypes, networkTable, tableColumnType, networkDefaultLimit, curTabState, storageKey, dbDrilldownTableConfig, fromRoute } from '@/utils/constants'
import { get } from '@/utils/http' import { get } from '@/utils/http'
import unitConvert from '@/utils/unit-convert' import unitConvert from '@/utils/unit-convert'
import { getChainRatio, computeScore, urlParamsHandler, overwriteUrl, getUserDrilldownTableGeo, readDrilldownTableConfigByUser, combinDrilldownTableWithUserConfig, getDnsMapData,handleSpecialValue } from '@/utils/tools' import { getChainRatio, computeScore, urlParamsHandler, overwriteUrl, getUserDrilldownTableGeo, readDrilldownTableConfigByUser, combinDrilldownTableWithUserConfig, getDnsMapData,handleSpecialValue,getConfigVersion } from '@/utils/tools'
import { getSecond } from '@/utils/date-util' import { getSecond } from '@/utils/date-util'
import chartMixin from '@/views/charts2/chart-mixin' import chartMixin from '@/views/charts2/chart-mixin'
import ChartNoData from '@/views/charts/charts/ChartNoData' import ChartNoData from '@/views/charts/charts/ChartNoData'
@@ -1618,15 +1618,6 @@ export default {
} }
} }
}, },
/*
async getUserLocalConfig () {
const userLocalCongfig = await db[dbDrilldownTableConfig].get({ id: this.userId })
if (userLocalCongfig) {
return userLocalCongfig.config
} else {
return null
}
}, */
isDrilldown () { isDrilldown () {
if (this.getUrlParam(this.curTabState.fourthMenu)) { if (this.getUrlParam(this.curTabState.fourthMenu)) {
return true return true
@@ -1648,6 +1639,7 @@ export default {
let curUserConfigs = await readDrilldownTableConfigByUser() let curUserConfigs = await readDrilldownTableConfigByUser()
const hiddenColumns = this.getHiddenColumnNameGroup() const hiddenColumns = this.getHiddenColumnNameGroup()
this.curTable.hiddenColumns = hiddenColumns this.curTable.hiddenColumns = hiddenColumns
let version = ''
if (curUserConfigs && curUserConfigs.length > 0) { // 当前用户存在缓存配置 if (curUserConfigs && curUserConfigs.length > 0) { // 当前用户存在缓存配置
const currentRouteConfig = curUserConfigs.find(config => config.route === this.tableType) const currentRouteConfig = curUserConfigs.find(config => config.route === this.tableType)
if (currentRouteConfig) { // 用户的缓存中存在当前路径对应的下钻表格对应的配置 if (currentRouteConfig) { // 用户的缓存中存在当前路径对应的下钻表格对应的配置
@@ -1663,13 +1655,16 @@ export default {
} else { // 用户的缓存中不存在当前路径对应的下钻表格对应的配置 } else { // 用户的缓存中不存在当前路径对应的下钻表格对应的配置
curUserConfigs.push(this.handleInitDrilldownTableConfig()) curUserConfigs.push(this.handleInitDrilldownTableConfig())
} }
version = await getConfigVersion(this.userId)
} else { // 当前用户不存在缓存配置 } else { // 当前用户不存在缓存配置
curUserConfigs = [] curUserConfigs = []
curUserConfigs.push(this.handleInitDrilldownTableConfig()) curUserConfigs.push(this.handleInitDrilldownTableConfig())
version = await getConfigVersion('default')
} }
// 更新缓存中的配置 // 更新缓存中的配置
await db[dbDrilldownTableConfig].put({ await db[dbDrilldownTableConfig].put({
id: this.userId, id: this.userId,
version: version,
config: this.$_.cloneDeep(curUserConfigs) config: this.$_.cloneDeep(curUserConfigs)
}) })
// 更新使用的配置 // 更新使用的配置