..
This commit is contained in:
@@ -243,7 +243,6 @@ layout("/layouts/v4/baseLayout.html"){
|
||||
|
||||
|
||||
try {
|
||||
debugger
|
||||
const app = JSON.parse(window.sessionStorage.getItem("zhgh_sub_app"))
|
||||
$("#sub-app-container #sidebar-menu .menu-header .menu-title").text(app?.name)
|
||||
} catch (e) {
|
||||
@@ -324,53 +323,52 @@ layout("/layouts/v4/baseLayout.html"){
|
||||
if (res.code === 0) {
|
||||
this.menus = res.data
|
||||
window.sessionStorage.setItem("zhgh_sub_app_menus", JSON.stringify(res.data))
|
||||
this.echoMenus()
|
||||
this.matchUrlToMenu()
|
||||
this.echoMenus()
|
||||
// this.matchUrlToMenu()
|
||||
} else {
|
||||
this.menus = []
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 按 URL 精准激活
|
||||
matchUrlToMenu() {
|
||||
// 跳转带过来的地址
|
||||
const pathname = window.location.pathname
|
||||
const find = (list, parentIds = []) => {
|
||||
for (const m of list) {
|
||||
if (m.href && pathname.includes(m.href.split('?')[0])) {
|
||||
return { menu: m, parentIds }
|
||||
}
|
||||
if (m.children?.length) {
|
||||
const hit = find(m.children, [...parentIds, m.id])
|
||||
if (hit) return hit
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const hit = find(this.menus)
|
||||
if (hit) {
|
||||
// 激活跳转菜单
|
||||
this.activeMenuIndex = hit.menu.id
|
||||
this.openedMenus = hit.parentIds
|
||||
const app = JSON.parse(window.sessionStorage.getItem("zhgh_sub_app"))
|
||||
$("#sub-app-container #sidebar-menu .menu-header .menu-title").text(app?.name)
|
||||
this.$nextTick(() => {
|
||||
this.menuSelect(hit.menu.id, hit.parentIds)
|
||||
// 保证内容区对应
|
||||
commonUtil.pjaxPush(hit.menu.href)
|
||||
})
|
||||
} else if (!this.activeMenuIndex) {
|
||||
// 没命中且缓存也没有 → 再降级到第一个
|
||||
this.defaultSelect()
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// 按 URL 精准激活
|
||||
matchUrlToMenu() {
|
||||
// 跳转带过来的地址
|
||||
const pathname = window.location.pathname
|
||||
const find = (list, parentIds = []) => {
|
||||
for (const m of list) {
|
||||
if (m.href && pathname.includes(m.href.split('?')[0])) {
|
||||
return {menu: m, parentIds}
|
||||
}
|
||||
if (m.children?.length) {
|
||||
const hit = find(m.children, [...parentIds, m.id])
|
||||
if (hit) return hit
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const hit = find(this.menus)
|
||||
if (hit) {
|
||||
// 激活跳转菜单
|
||||
this.activeMenuIndex = hit.menu.id
|
||||
this.openedMenus = hit.parentIds
|
||||
const app = JSON.parse(window.sessionStorage.getItem("zhgh_sub_app"))
|
||||
$("#sub-app-container #sidebar-menu .menu-header .menu-title").text(app?.name)
|
||||
this.$nextTick(() => {
|
||||
this.menuSelect(hit.menu.id, hit.parentIds)
|
||||
// 保证内容区对应
|
||||
commonUtil.pjaxPush(hit.menu.href)
|
||||
})
|
||||
} else if (!this.activeMenuIndex) {
|
||||
// 没命中且缓存也没有 → 再降级到第一个
|
||||
this.defaultSelect()
|
||||
}
|
||||
},
|
||||
|
||||
// 设置应用信息
|
||||
setAppInfo(app) {
|
||||
if (app) {
|
||||
debugger
|
||||
// 储存到缓存
|
||||
window.sessionStorage.setItem("zhgh_sub_app", JSON.stringify(app))
|
||||
// 储存到div中
|
||||
@@ -388,14 +386,50 @@ layout("/layouts/v4/baseLayout.html"){
|
||||
console.log(this.openedMenus)
|
||||
console.log(this.activeMenuIndex)
|
||||
|
||||
if (!this.activeMenuIndex) {
|
||||
if (!this.activeMenuIndex && '/platform/v4/subApp' === window.location.pathname) {
|
||||
this.defaultSelect()
|
||||
} else {
|
||||
|
||||
this.hrefSelect()
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
}
|
||||
},
|
||||
|
||||
// 地址选中
|
||||
hrefSelect() {
|
||||
function findMenuPath(menus, targetHref) {
|
||||
function search(items, path) {
|
||||
for (const item of items) {
|
||||
// 如果当前项匹配 href,返回路径(包含自己)
|
||||
if (item.href === targetHref) {
|
||||
return [...path, item];
|
||||
}
|
||||
// 如果有子菜单,递归查找
|
||||
if (item.children?.length) {
|
||||
const result = search(item.children, [...path, item]);
|
||||
if (result) return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return search(menus, []);
|
||||
}
|
||||
|
||||
const result = findMenuPath(this.menus, window.location.pathname)
|
||||
|
||||
this.activeMenuIndex = result[result.length-1]
|
||||
this.openedMenus = result.map(v=>v.id)
|
||||
|
||||
this.$nextTick(() => {
|
||||
this.menuSelect(this.activeMenuIndex, this.openedMenus)
|
||||
// 使用pjax跳转
|
||||
commonUtil.pjaxPush(self.href)
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
// 默认选中
|
||||
defaultSelect() {
|
||||
// 查找第一个有href的子菜单
|
||||
|
||||
Reference in New Issue
Block a user