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 routes: routes
}) })
window.localRouterHistoryList = []
export default router export default router

View File

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

View File

@@ -204,7 +204,7 @@ export default {
let { params, query, path } = useRoute() 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) { if (routerObj) {
params = routerObj.params params = routerObj.params
query = routerObj.query query = routerObj.query
@@ -386,7 +386,8 @@ export default {
*/ */
beforeUnmount () { beforeUnmount () {
const query = this.$_.cloneDeep(this.$route.query) 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 (routerObj !== undefined) {
if (Object.getOwnPropertyNames(query).length >= Object.getOwnPropertyNames(routerObj.query).length) { if (Object.getOwnPropertyNames(query).length >= Object.getOwnPropertyNames(routerObj.query).length) {
routerObj.query = query routerObj.query = query

View File

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