Files
nexusphp/admin/src/App.vue
T

193 lines
5.2 KiB
Vue
Raw Normal View History

2021-03-31 19:39:59 +08:00
<template>
2021-04-22 03:24:59 +08:00
<div class="layout">
<el-container v-if="state.showMenu" class="container">
<el-aside class="aside">
<div class="head">
<div>
<!-- <img src="http://demo.nexusphp.org/favicon.ico" alt="logo">-->
<span>NexusPHP</span>
</div>
</div>
<div class="line" />
<el-menu
:default-openeds="state.defaultOpen"
background-color="#222832"
text-color="#fff"
:router="true"
:default-active='state.currentPath'
>
<el-menu-item index="/"><i class="el-icon-odometer" />Dashboard</el-menu-item>
<el-submenu index="2">
<template #title>
<span>User</span>
</template>
<el-menu-item-group>
<el-menu-item index="/user"><i class="el-icon-user" />User list</el-menu-item>
</el-menu-item-group>
</el-submenu>
<el-submenu index="3">
<template #title>
<span>System</span>
</template>
<el-menu-item-group>
<el-menu-item index="/agent-allow"><i class="el-icon-menu" />Agent allow</el-menu-item>
</el-menu-item-group>
<el-menu-item-group>
<el-menu-item index="/exam"><i class="el-icon-menu" />Exam</el-menu-item>
</el-menu-item-group>
2021-04-25 02:12:14 +08:00
<el-menu-item-group>
<el-menu-item index="/exam-user"><i class="el-icon-menu" />Exam user</el-menu-item>
</el-menu-item-group>
2021-04-22 03:24:59 +08:00
</el-submenu>
</el-menu>
</el-aside>
<el-container class="content">
<Header />
<div class="main">
<router-view />
</div>
<Footer />
</el-container>
</el-container>
<el-container v-else class="container">
<router-view />
</el-container>
2021-04-21 19:54:50 +08:00
</div>
2021-03-31 19:39:59 +08:00
</template>
<script>
2021-04-22 03:24:59 +08:00
import { reactive } from 'vue'
import Header from './components/Header.vue'
import Footer from './components/Footer.vue'
import { useRouter } from 'vue-router'
import { pathMap, localGet } from './utils'
2021-03-31 19:39:59 +08:00
export default {
2021-04-22 03:24:59 +08:00
name: 'App',
2021-04-21 19:54:50 +08:00
components: {
2021-04-22 03:24:59 +08:00
Header,
Footer
2021-04-21 19:54:50 +08:00
},
2021-04-22 03:24:59 +08:00
setup() {
const noMenu = ['/login']
const router = useRouter()
const state = reactive({
defaultOpen: ['1', '2', '3', '4'],
showMenu: true,
currentPath: '/dashboard',
count: {
number: 1
}
})
router.beforeEach((to, from, next) => {
2021-04-25 02:12:14 +08:00
console.log("App beforeEach to", to)
2021-04-22 03:24:59 +08:00
if (to.path == '/login') {
// 如果路径是 /login 则正常执行
next()
} else {
// 如果不是 /login,判断是否有 token
if (!localGet('token')) {
// 如果没有,则跳至登录页面
next({ path: '/login' })
} else {
// 否则继续执行
next()
}
}
state.showMenu = !noMenu.includes(to.path)
state.currentPath = to.path
document.title = pathMap[to.name]
})
2021-04-21 19:54:50 +08:00
return {
2021-04-22 03:24:59 +08:00
state
2021-04-12 20:31:02 +08:00
}
2021-04-01 19:50:41 +08:00
}
2021-03-31 19:39:59 +08:00
}
2021-04-21 19:54:50 +08:00
</script>
2021-04-22 03:24:59 +08:00
<style scoped>
.layout {
min-height: 100vh;
background-color: #ffffff;
}
.container {
height: 100vh;
}
.aside {
width: 200px!important;
background-color: #222832;
overflow: hidden;
overflow-y: auto;
-ms-overflow-style: none;
overflow: -moz-scrollbars-none;
}
.aside::-webkit-scrollbar {
display: none;
}
.head {
display: flex;
align-items: center;
justify-content: center;
height: 50px;
}
.head > div {
display: flex;
align-items: center;
}
.head img {
width: 50px;
height: 50px;
margin-right: 10px;
}
.head span {
font-size: 20px;
color: #ffffff;
}
.line {
border-top: 1px solid hsla(0,0%,100%,.05);
border-bottom: 1px solid rgba(0,0,0,.2);
}
.content {
display: flex;
flex-direction: column;
max-height: 100vh;
overflow: hidden;
}
.main {
height: calc(100vh - 100px);
overflow: auto;
padding: 10px;
}
</style>
2021-04-12 20:31:02 +08:00
<style>
2021-04-22 03:24:59 +08:00
body {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.el-menu {
border-right: none!important;
}
.el-submenu {
border-top: 1px solid hsla(0, 0%, 100%, .05);
border-bottom: 1px solid rgba(0, 0, 0, .2);
}
.el-submenu:first-child {
border-top: none;
}
.el-submenu [class^="el-icon-"] {
vertical-align: -1px!important;
}
a {
color: #409eff;
text-decoration: none;
}
.el-pagination {
text-align: center;
margin-top: 20px;
}
.el-popper__arrow {
display: none;
2021-04-21 19:54:50 +08:00
}
2021-03-31 19:39:59 +08:00
</style>