Commit 20e71af6 by liimin

调整

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