324 lines
9.9 KiB
HTML
324 lines
9.9 KiB
HTML
<!--#
|
|
layout("/layouts/v4/baseLayout.html"){
|
|
#-->
|
|
|
|
<style>
|
|
.sub-app-container {
|
|
margin: 0 auto;
|
|
background: #fff;
|
|
display: flex;
|
|
overflow: hidden;
|
|
min-height: calc(100vh - 64px);
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.sidebar-menu {
|
|
width: 250px;
|
|
background: rgb(35 85 120);
|
|
color: #fff;
|
|
flex-shrink: 0;
|
|
height: calc(100vh - 64px);
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.menu-header {
|
|
padding: 20px;
|
|
background: rgba(0, 0, 0, 0.1);
|
|
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.menu-title {
|
|
font-size: 18px;
|
|
font-weight: 600;
|
|
margin: 0;
|
|
}
|
|
|
|
#sidebar-menu .el-scrollbar {
|
|
flex: 1;
|
|
}
|
|
|
|
#sidebar-menu .el-scrollbar .el-scrollbar__wrap {
|
|
overflow-x: hidden;
|
|
margin-bottom: 0 !important;
|
|
}
|
|
|
|
#sidebar-menu .el-menu {
|
|
background: transparent;
|
|
border: none;
|
|
}
|
|
|
|
#sidebar-menu .el-menu .el-submenu__title {
|
|
color: #ffffff;
|
|
}
|
|
|
|
#sidebar-menu .el-menu .el-submenu__title i,
|
|
#sidebar-menu .el-menu .el-menu-item i {
|
|
color: inherit;
|
|
}
|
|
|
|
#sidebar-menu .el-menu .el-submenu__title:hover {
|
|
background: rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
#sidebar-menu .el-menu .el-menu-item {
|
|
color: inherit;
|
|
}
|
|
|
|
#sidebar-menu .el-menu .el-menu-item.is-active {
|
|
background: rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
#sidebar-menu .el-menu .el-menu-item:focus,
|
|
.el-menu-item:hover {
|
|
background: rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
#sidebar-menu .el-menu .el-menu-item a {
|
|
text-decoration: none;
|
|
color: inherit;
|
|
display: inline-block;
|
|
width: 100%;
|
|
}
|
|
|
|
.sub-app-container-main-content {
|
|
flex: 1;
|
|
padding: 10px;
|
|
background: #f6f6f6;
|
|
box-sizing: border-box;
|
|
overflow: auto;
|
|
height: calc(100vh - 64px);
|
|
}
|
|
|
|
.content-header {
|
|
margin-bottom: 30px;
|
|
padding-bottom: 20px;
|
|
border-bottom: 1px solid #eee;
|
|
}
|
|
|
|
.content-title {
|
|
font-size: 24px;
|
|
font-weight: 600;
|
|
color: #2c3e50;
|
|
margin: 0;
|
|
}
|
|
|
|
.content-subtitle {
|
|
color: #7f8c8d;
|
|
margin-top: 5px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.content-body {
|
|
min-height: 400px;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.sub-app-container {
|
|
flex-direction: column;
|
|
}
|
|
|
|
.sidebar-menu {
|
|
width: 100%;
|
|
}
|
|
|
|
.sub-app-container-main-content {
|
|
padding: 20px;
|
|
}
|
|
}
|
|
</style>
|
|
|
|
<div class="sub-app-container" id="sub-app-container">
|
|
<!-- 左侧菜单区域 -->
|
|
<nav class="sidebar-menu" id="sidebar-menu">
|
|
<div class="menu-header">
|
|
<h2 class="menu-title">子系统</h2>
|
|
</div>
|
|
|
|
<el-scrollbar>
|
|
<el-menu unique-opened :default-active="activeMenuIndex" :default-openeds="openedMenus" @select="menuSelect">
|
|
<menu-list :menus="leftMenus" :depth="0"></menu-list>
|
|
</el-menu>
|
|
</el-scrollbar>
|
|
</nav>
|
|
|
|
<!-- 右侧主体区域 -->
|
|
<main class="sub-app-container-main-content" id="sub-app-container-main-content">
|
|
<!-- <header class="content-header">-->
|
|
<!-- <h1 class="content-title"></h1>-->
|
|
<!-- <!– <p class="content-subtitle"></p>–>-->
|
|
<!-- </header>-->
|
|
|
|
<div class="content-body" id="sub-app-container-main-content-body">${layoutContent!}</div>
|
|
</main>
|
|
|
|
<!-- 子应用ID -->
|
|
<div id="sub-app-id" style="display: none"></div>
|
|
</div>
|
|
|
|
<script>
|
|
// 初始化pjax加载
|
|
;(function initPjax() {
|
|
$(document).pjax("#sidebar-menu a[data-pjax]", "#sub-app-container-main-content-body", {
|
|
maxCacheLength: 0,
|
|
push: true,
|
|
replace: false,
|
|
fragment: "#sub-app-container-main-content-body",
|
|
timeout: 8000
|
|
})
|
|
|
|
$(document).on("pjax:send", function () {
|
|
NProgress.configure({ parent: ".sub-app-container-main-content" })
|
|
NProgress.start()
|
|
$("#sub-app-container-main-content").hide()
|
|
})
|
|
|
|
$(document).on("pjax:complete", function () {
|
|
NProgress.done()
|
|
$("#sub-app-container-main-content").show()
|
|
setContentTitle()
|
|
})
|
|
|
|
setContentTitle()
|
|
})()
|
|
|
|
// 设置内容标题
|
|
function setContentTitle() {
|
|
// const menu = store.state.user.menus.find((v) => v.href === window.location.pathname)
|
|
// $("#sub-app-container-main-content .content-title").text(menu?.name)
|
|
try {
|
|
const app = JSON.parse(window.sessionStorage.getItem("zhgh_sub_app"))
|
|
$("#sub-app-container #sidebar-menu .menu-header .menu-title").text(app?.name)
|
|
} catch (e) {}
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
const menuLinks = document.querySelectorAll("#sidebar-menu a")
|
|
menuLinks.forEach((link) => {
|
|
link.addEventListener("click", function (e) {
|
|
const pjax = this.hasAttribute("data-pjax")
|
|
e.preventDefault()
|
|
})
|
|
})
|
|
})
|
|
|
|
new Vue({
|
|
el: "#sidebar-menu",
|
|
components: {
|
|
"menu-list": {
|
|
name: "menu-list",
|
|
template:
|
|
/*language=HTML*/
|
|
`
|
|
<div>
|
|
<template v-for="(item, index) in menus">
|
|
<el-submenu :index="item.id" v-if="item.children && item.children.length > 0">
|
|
<template #title>
|
|
<i :class="item.icon" v-if="item.icon" :size="18"></i>
|
|
<i v-else class="el-icon-paperclip"></i>
|
|
<span>{{ item.name }}</span>
|
|
</template>
|
|
<menu-list :menus="item.children" :depth="depth + 1" />
|
|
</el-submenu>
|
|
<el-menu-item :index="item.id" v-else>
|
|
<a :href="item.href" data-pjax>
|
|
<i :class="item.icon" v-if="item.icon" :size="18"></i>
|
|
<i v-else :class="item.icon ? item.icon : 'el-icon-menu'"></i>
|
|
<span>{{ item.name }}</span>
|
|
</a>
|
|
</el-menu-item>
|
|
</template>
|
|
</div>
|
|
`,
|
|
props: ["menus", "depth"]
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
menus: [],
|
|
activeMenuIndex: null,
|
|
openedMenus: []
|
|
}
|
|
},
|
|
computed: {
|
|
leftMenus() {
|
|
if (this.menus) {
|
|
return this.menus
|
|
} else {
|
|
try {
|
|
return JSON.parse(window.sessionStorage.getItem("zhgh_sub_app_menus"))
|
|
} catch (e) {
|
|
return []
|
|
}
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
menuSelect(index, indexPath) {
|
|
try {
|
|
const app = JSON.parse(window.sessionStorage.getItem("zhgh_sub_app"))
|
|
window.sessionStorage.setItem("zhgh_sub_app_left_menu_active_index-" + app.id, index)
|
|
window.sessionStorage.setItem("zhgh_sub_app_left_menu_opens-" + app.id, JSON.stringify(indexPath))
|
|
} catch (e) {}
|
|
},
|
|
// 获取菜单
|
|
getMenus(appId) {
|
|
if (!appId) return
|
|
$.get("/platform/sys/user/subAppMenus", { appId }).then((res) => {
|
|
if (res.code === 0) {
|
|
this.menus = res.data
|
|
window.sessionStorage.setItem("zhgh_sub_app_menus", JSON.stringify(res.data))
|
|
} else {
|
|
this.menus = []
|
|
}
|
|
this.echoMenus()
|
|
})
|
|
},
|
|
|
|
setAppInfo(app) {
|
|
if (app) {
|
|
// 储存到缓存
|
|
window.sessionStorage.setItem("zhgh_sub_app", JSON.stringify(app))
|
|
// 储存到div中
|
|
document.getElementById("sub-app-id").innerText = app.id
|
|
}
|
|
// document.querySelector("#sub-app-container .content-title").innerText = app.name
|
|
},
|
|
|
|
// 菜单回显
|
|
echoMenus() {
|
|
try {
|
|
const app = JSON.parse(window.sessionStorage.getItem("zhgh_sub_app"))
|
|
this.activeMenuIndex = window.sessionStorage.getItem("zhgh_sub_app_left_menu_active_index-" + app.id)
|
|
this.openedMenus = JSON.parse(window.sessionStorage.getItem("zhgh_sub_app_left_menu_opens-" + app.id)) || []
|
|
console.log(this.openedMenus)
|
|
console.log(this.activeMenuIndex)
|
|
} catch (e) {}
|
|
}
|
|
},
|
|
mounted() {
|
|
// 页面加载时获取到正确的菜单
|
|
const pathname = window.location.pathname
|
|
if (!pathname.startsWith("/platform/v4/subApp")) {
|
|
$.get("/platform/sys/user/rootMenuByPath", { pathname }).then((res) => {
|
|
if (res.code === 0) {
|
|
this.setAppInfo(res.data)
|
|
this.getMenus(res.data?.id)
|
|
}
|
|
})
|
|
} else {
|
|
const appId = GetQueryString("appId")
|
|
if (!appId) {
|
|
return
|
|
}
|
|
this.getMenus(appId)
|
|
}
|
|
}
|
|
})
|
|
</script>
|
|
|
|
<!--#
|
|
}
|
|
#-->
|