fix: 添加下钻前保存参数,回退时保留状态方法

This commit is contained in:
刘洪洪
2023-09-22 15:07:06 +08:00
parent 22eddbb536
commit eb704b8d8e
5 changed files with 44 additions and 69 deletions

View File

@@ -5,6 +5,7 @@ import { storageKey, iso36112, topDomain, echartsFontSize, dbGeoDataTableName, n
import { getIso36112JsonData, getDictList } from '@/utils/api'
import { format } from 'echarts'
import router from '@/router'
import store from '@/store'
import indexedDBUtils from '@/indexedDB'
export const tableSort = {
@@ -1317,3 +1318,34 @@ export function switchStatus (status) {
return 'Enabled'
}
}
/**
* 在路由跳转前,即下钻前将路由数据保存起来,确保回退和前进保留当时状态
*/
export function beforeRouterPush () {
const currentRouter = _.cloneDeep(router.currentRoute.value.query)
const historyList = _.cloneDeep(store.getters.getRouterHistoryList)
const tempObj = {
t: currentRouter.t,
query: currentRouter,
path: _.cloneDeep(router.currentRoute.value.path),
params: _.cloneDeep(router.currentRoute.value.params)
}
if (historyList.length > 0) {
let flag = true
historyList.forEach((item, index) => {
if (item.t === currentRouter.t) {
historyList[index] = tempObj
flag = false
}
if (!flag) {
return true
}
})
if (flag) historyList.push(tempObj)
} else {
historyList.push(tempObj)
}
store.commit('setRouterHistoryList', historyList)
}

View File

@@ -116,7 +116,7 @@ import chartMixin from '@/views/charts2/chart-mixin'
import { useRoute } from 'vue-router'
import { ref } from 'vue'
import { api } from '@/utils/api'
import { colorGradientCalculation } from '@/utils/tools'
import { colorGradientCalculation, beforeRouterPush } from '@/utils/tools'
import unitConvert from '@/utils/unit-convert'
import { drillDownPanelTypeMapping, storageKey, unitTypes } from '@/utils/constants'
import { getSecond } from '@/utils/date-util'
@@ -372,6 +372,7 @@ export default {
},
drillLinkId (item) {
const queryCondition = `common_out_link_id = ${item.outLinkId} or common_in_link_id = ${item.inLinkId}`
beforeRouterPush()
this.$router.push({
query: {
...this.$route.query,

View File

@@ -32,7 +32,7 @@ import { getSecond } from '@/utils/date-util'
import ChartNoData from '@/views/charts/charts/ChartNoData'
import chartMixin from '@/views/charts2/chart-mixin'
import ChartError from '@/components/common/Error'
import { getIndexByEventSeverity } from '@/utils/tools'
import { getIndexByEventSeverity, beforeRouterPush } from '@/utils/tools'
export default {
name: 'NetworkOverviewPerformanceEvent',
setup () {
@@ -153,6 +153,7 @@ export default {
this.toggleLoading(false)
},
routerJump () {
beforeRouterPush()
const params = {
startTime: this.timeFilter.startTime,
endTime: this.timeFilter.endTime,

View File

@@ -293,7 +293,7 @@ import {
} from '@/utils/constants'
import axios from 'axios'
import unitConvert, { valueToRangeValue } from '@/utils/unit-convert'
import { getChainRatio, computeScore, urlParamsHandler, overwriteUrl, readDrilldownTableConfigByUser, combineDrilldownTableWithUserConfig, getDnsMapData, handleSpecialValue, getConfigVersion } from '@/utils/tools'
import { getChainRatio, computeScore, urlParamsHandler, overwriteUrl, readDrilldownTableConfigByUser, combineDrilldownTableWithUserConfig, getDnsMapData, handleSpecialValue, getConfigVersion, beforeRouterPush } from '@/utils/tools'
import { getSecond } from '@/utils/date-util'
import chartMixin from '@/views/charts2/chart-mixin'
import _ from 'lodash'
@@ -1449,7 +1449,7 @@ export default {
overwriteUrl(newUrl)
}
// 下钻前保存当前路由状态
this.beforeRouterPush()
beforeRouterPush()
const clickTab = this.getTabByName(columnName)// 下钻后显示的下钻tab对应的drilldownTabs
const tabLable = clickTab.label
const tabName = clickTab.name
@@ -1539,36 +1539,6 @@ export default {
}
})
},
/**
* 在路由跳转前,即下钻前将路由数据保存起来,确保回退和前进保留当时状态
*/
beforeRouterPush () {
const currentRouter = this.$_.cloneDeep(this.$route.query)
const historyList = this.$_.cloneDeep(this.$store.getters.getRouterHistoryList)
const tempObj = {
t: currentRouter.t,
query: currentRouter,
path: this.$_.cloneDeep(this.$route.path),
params: this.$_.cloneDeep(this.$route.params)
}
if (historyList.length > 0) {
let flag = true
historyList.forEach((item, index) => {
if (item.t === currentRouter.t) {
historyList[index] = tempObj
flag = false
}
if (!flag) {
return true
}
})
if (flag) historyList.push(tempObj)
} else {
historyList.push(tempObj)
}
this.$store.commit('setRouterHistoryList', historyList)
},
handleSearchParams (columnValue) {
columnValue = handleSpecialValue(columnValue)// columnValue.replaceAll("'", "\\\\'")
const queryCondition = []

View File

@@ -56,6 +56,7 @@ import { ref } from 'vue'
import ChartError from '@/components/common/Error'
import axios from 'axios'
import { dataForNpmRecentEvents } from '@/utils/static-data'
import { beforeRouterPush } from '@/utils/tools'
export default {
name: 'NpmRecentEvents',
@@ -144,7 +145,7 @@ export default {
return name
},
jumpPage (item) {
this.beforeRouterPush()
beforeRouterPush()
this.$router.push({
path: '/detection/performanceEvent',
query: {
@@ -153,36 +154,6 @@ export default {
}
})
},
/**
* 在路由跳转前,即下钻前将路由数据保存起来,确保回退和前进保留当时状态
*/
beforeRouterPush () {
const currentRouter = this.$_.cloneDeep(this.$route.query)
const historyList = this.$_.cloneDeep(this.$store.getters.getRouterHistoryList)
const tempObj = {
t: currentRouter.t,
query: currentRouter,
path: this.$_.cloneDeep(this.$route.path),
params: this.$_.cloneDeep(this.$route.params)
}
if (historyList.length > 0) {
let flag = true
historyList.forEach((item, index) => {
if (item.t === currentRouter.t) {
historyList[index] = tempObj
flag = false
}
if (!flag) {
return true
}
})
if (flag) historyList.push(tempObj)
} else {
historyList.push(tempObj)
}
this.$store.commit('setRouterHistoryList', historyList)
},
httpError (res) {
this.isNoData = false
this.showError = true