Commit 20e71af6 by liimin

调整

1 parent 72d4bde6
......@@ -4,7 +4,7 @@
* @Author: limin
* @Date: 2021-08-25 14:52:15
* @LastEditors: limin
* @LastEditTime: 2023-09-19 11:18:00
* @LastEditTime: 2023-09-19 15:03:49
* @FilePath: \scrm-base\src\global\history.js
*/
import store from '@/store'
......@@ -36,8 +36,10 @@ function push(menu) {
if (!url) {
throw new Error('history.push:必须传入URL')
}
const to = utils.array.valInDeep(store.getters.app.menuList, url, 'path', 'children') || []
// const to = store.getters.app.flatten.find(mod => url === mod.path || '/' + url === mod.path)
if (!url.startsWith('/')) {
url = '/' + url
}
let to = findObjTo(url)
to[0] && val(to[0])
if (!url) {
throw new Error('跳转页面失败,请检查页面参数是否正确')
......@@ -48,6 +50,10 @@ function push(menu) {
window.history.pushState(stateObj, title, url)
}
function findObjTo(url) {
return utils.array.valInDeep(store.getters.app.menuList, url, 'path', 'children')
}
export {
push // 跨应用路由跳转
}
......@@ -15,16 +15,21 @@ export default {
mixins: [currentId],
inject: ['bus'],
created() {
this.bus.$on('current', this.handleCurrentChange)
this.bus.$on('menuOpenedsChanged', this.handleMenuOpenedsChanged)
},
mounted() {
this.handleCurrentChange(this.current)
},
beforeDestroy() {
this.bus.$off('current', this.handleCurrentChange)
this.bus.$off('menuOpenedsChanged', this.handleMenuOpenedsChanged)
},
watch: {
current: {
handler(n) {
this.handleCurrentChange(n)
}
}
},
data() {
return {
cur: {
......
......@@ -37,6 +37,11 @@ export default {
handler(n) {
!n && this.reload()
}
},
current: {
handler() {
this.reload()
}
}
},
mounted() {
......@@ -54,7 +59,9 @@ export default {
return children.noHidden().length == 0
},
handleMenuChanged({ menus = [], isReload = false }) {
if (this.menus[0]?.pid == menus[0]?.pid) return
const pid1 = this.menus[0]?.id?.split('-')
const pid2 = menus[0]?.id?.split('-')
if (pid1 == pid2) return
if (isReload) {
this.reload()
return
......
......@@ -21,6 +21,13 @@ export default {
nav4: []
}
},
watch: {
current: {
handler() {
this.onLoad()
}
}
},
mounted() {
this.bus.$on('menu3Changed', this.onMenu3Changed)
this.onLoad()
......@@ -50,7 +57,6 @@ export default {
const { lv1, lv2, lv3, lv4 } = this.current
const lv3id = `${lv1}-${lv2}-${lv3}`
const lv4id = `${lv3id}-${lv4}`
console.log(lv4id)
const sub = this.find(lv3id)?.children
if (sub?.length) {
const nav4 = sub.noHidden()
......
......@@ -7,7 +7,6 @@ export const currentId = {
if (this.app.currentPage) {
const [lv1, lv2, lv3, lv4] = this.app.currentPage.id.split('-')
Object.assign(_current, { lv1, lv2, lv3, lv4 })
this.bus?.$emit('current', _current)
}
return _current
}
......
......@@ -18,7 +18,7 @@ const app = {
},
SET_MENU_LIST(state, list) {
state.menuList = list
state.flatten = utils.array.flattenDeep(list)
// state.flatten = utils.array.flattenDeep(list)
},
SET_ROUTES(state, payload) {
state.routers = payload
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!