fix:回退保留状态弃用window,使用store

This commit is contained in:
liuhonghong
2022-11-11 15:17:44 +08:00
parent 323ccae196
commit c322059c97
4 changed files with 18 additions and 10 deletions

View File

@@ -72,6 +72,4 @@ const router = createRouter({
routes: routes
})
window.localRouterHistoryList = []
export default router

View File

@@ -56,7 +56,8 @@ const panel = {
timeRangeFlag: null, // 时间范围标志默认60即一小时-1为手动选择的时间范围
routerPath: '', // 当前路由路径
httpCancel: null, // 终止http请求
rangeEchartsData: {} // 框选echarts图表
rangeEchartsData: {}, // 框选echarts图表
routerHistoryList: [] // 路由跳转记录列表
},
mutations: {
setShowRightBox (state, flag) {
@@ -166,6 +167,9 @@ const panel = {
},
setRangeEchartsData (state, data) {
state.rangeEchartsData = data
},
setRouterHistoryList (state, list) {
state.routerHistoryList = list
}
},
getters: {
@@ -258,6 +262,9 @@ const panel = {
},
getRouterPath (state) {
return state.routerPath
},
getRouterHistoryList (state) {
return state.routerHistoryList
}
},
actions: {

View File

@@ -204,7 +204,7 @@ export default {
let { params, query, path } = useRoute()
// 获取路由跳转过的历史状态,赋值给当前界面,起到保留状态的作用,如浏览器的回退前进等
const routerObj = window.localRouterHistoryList.find(item => item.t === query.t)
const routerObj = store.getters.getRouterHistoryList.find(item => item.t === query.t)
if (routerObj) {
params = routerObj.params
query = routerObj.query
@@ -386,7 +386,8 @@ export default {
*/
beforeUnmount () {
const query = this.$_.cloneDeep(this.$route.query)
const routerObj = window.localRouterHistoryList.find(item => item.t === query.t)
const routerObj = this.$store.getters.getRouterHistoryList.find(item => item.t === query.t)
// const routerObj = window.localRouterHistoryList.find(item => item.t === query.t)
if (routerObj !== undefined) {
if (Object.getOwnPropertyNames(query).length >= Object.getOwnPropertyNames(routerObj.query).length) {
routerObj.query = query

View File

@@ -1198,6 +1198,7 @@ export default {
*/
beforeRouterPush () {
const currentRouter = this.$_.cloneDeep(this.$route.query)
const historyList = this.$_.cloneDeep(this.$store.getters.getRouterHistoryList)
const tempObj = {
t: currentRouter.t,
@@ -1205,21 +1206,22 @@ export default {
path: this.$_.cloneDeep(this.$route.path),
params: this.$_.cloneDeep(this.$route.params)
}
if (window.localRouterHistoryList.length > 0) {
if (historyList.length > 0) {
let flag = true
window.localRouterHistoryList.forEach((item, index) => {
historyList.forEach((item, index) => {
if (item.t === currentRouter.t) {
window.localRouterHistoryList[index] = tempObj
historyList[index] = tempObj
flag = false
}
if (!flag) {
return true
}
})
if (flag) window.localRouterHistoryList.push(tempObj)
if (flag) historyList.push(tempObj)
} else {
window.localRouterHistoryList.push(tempObj)
historyList.push(tempObj)
}
this.$store.commit('setRouterHistoryList', historyList)
},
handleSearchParams (columnValue) {
columnValue = columnValue.replaceAll("'", "\\\\'")