You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
3.8 KiB
158 lines
3.8 KiB
<template>
|
|
<div class="main-layout">
|
|
<el-container>
|
|
<el-header class="header">
|
|
<div class="header-left">
|
|
<h1 class="logo">小型CA系统</h1>
|
|
<el-menu
|
|
:default-active="activeMenu"
|
|
mode="horizontal"
|
|
router
|
|
class="nav-menu"
|
|
>
|
|
<el-menu-item index="/certificates">我的证书</el-menu-item>
|
|
<el-menu-item index="/certificate/register">注册证书</el-menu-item>
|
|
<el-menu-item index="/certificate/verify">验证证书</el-menu-item>
|
|
<el-sub-menu v-if="isAdmin" index="/admin">
|
|
<template #title>管理后台</template>
|
|
<el-menu-item index="/admin/requests">证书审核</el-menu-item>
|
|
<el-menu-item index="/admin/certificates">证书管理</el-menu-item>
|
|
</el-sub-menu>
|
|
</el-menu>
|
|
</div>
|
|
<div class="header-right">
|
|
<el-dropdown @command="handleCommand">
|
|
<span class="user-info">
|
|
<el-icon><User /></el-icon>
|
|
{{ userInfo?.username }}
|
|
<el-icon class="el-icon--right"><ArrowDown /></el-icon>
|
|
</span>
|
|
<template #dropdown>
|
|
<el-dropdown-menu>
|
|
<el-dropdown-item command="logout">退出登录</el-dropdown-item>
|
|
</el-dropdown-menu>
|
|
</template>
|
|
</el-dropdown>
|
|
</div>
|
|
</el-header>
|
|
<el-main class="main-content">
|
|
<router-view />
|
|
</el-main>
|
|
</el-container>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { ref, computed, onMounted } from 'vue'
|
|
import { useRouter, useRoute } from 'vue-router'
|
|
import { logout, getCurrentUser } from '@/api/auth'
|
|
import { removeToken, getUserInfo, setUserInfo } from '@/utils/auth'
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
import { User, ArrowDown } from '@element-plus/icons-vue'
|
|
|
|
export default {
|
|
name: 'MainLayout',
|
|
setup() {
|
|
const router = useRouter()
|
|
const route = useRoute()
|
|
const userInfo = ref(getUserInfo())
|
|
const isAdmin = computed(() => userInfo.value?.authority === 1)
|
|
const activeMenu = computed(() => route.path)
|
|
|
|
onMounted(async () => {
|
|
try {
|
|
const res = await getCurrentUser()
|
|
setUserInfo(res.data)
|
|
userInfo.value = res.data
|
|
} catch (error) {
|
|
console.error(error)
|
|
}
|
|
})
|
|
|
|
const handleCommand = async (command) => {
|
|
if (command === 'logout') {
|
|
try {
|
|
ElMessageBox.confirm('确定要退出登录吗?', '提示', {
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
}).then(async () => {
|
|
try {
|
|
await logout()
|
|
} catch (error) {
|
|
console.error(error)
|
|
}
|
|
removeToken()
|
|
ElMessage.success('已退出登录')
|
|
router.push('/login')
|
|
})
|
|
} catch (error) {
|
|
// 用户取消
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
userInfo,
|
|
isAdmin,
|
|
activeMenu,
|
|
handleCommand,
|
|
User,
|
|
ArrowDown
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.main-layout {
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.header {
|
|
background: white;
|
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 0 20px;
|
|
}
|
|
|
|
.header-left {
|
|
display: flex;
|
|
align-items: center;
|
|
flex: 1;
|
|
}
|
|
|
|
.logo {
|
|
margin: 0;
|
|
margin-right: 30px;
|
|
font-size: 20px;
|
|
color: #409eff;
|
|
}
|
|
|
|
.nav-menu {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.header-right {
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.user-info {
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 5px;
|
|
color: #333;
|
|
}
|
|
|
|
.main-content {
|
|
padding: 20px;
|
|
background: #f5f5f5;
|
|
min-height: calc(100vh - 60px);
|
|
}
|
|
</style>
|
|
|