后台管理页面权限管理优化,权限管理细化
This commit is contained in:
@@ -18,35 +18,14 @@
|
||||
theme="dark"
|
||||
@click="handleMenuClick"
|
||||
>
|
||||
<a-menu-item key="/admin/dashboard">
|
||||
<a-menu-item
|
||||
v-for="item in menuItems"
|
||||
:key="item.key"
|
||||
>
|
||||
<template #icon>
|
||||
<DashboardOutlined />
|
||||
<component :is="item.icon" />
|
||||
</template>
|
||||
<span>仪表盘</span>
|
||||
</a-menu-item>
|
||||
<a-menu-item key="/admin/users">
|
||||
<template #icon>
|
||||
<UserOutlined />
|
||||
</template>
|
||||
<span>用户管理</span>
|
||||
</a-menu-item>
|
||||
<a-menu-item key="/admin/products">
|
||||
<template #icon>
|
||||
<ShopOutlined />
|
||||
</template>
|
||||
<span>商品管理</span>
|
||||
</a-menu-item>
|
||||
<a-menu-item key="/admin/shops">
|
||||
<template #icon>
|
||||
<HomeOutlined />
|
||||
</template>
|
||||
<span>店铺管理</span>
|
||||
</a-menu-item>
|
||||
<a-menu-item key="/admin/permissions">
|
||||
<template #icon>
|
||||
<SafetyCertificateOutlined />
|
||||
</template>
|
||||
<span>权限管理</span>
|
||||
<span>{{ item.label }}</span>
|
||||
</a-menu-item>
|
||||
</a-menu>
|
||||
</a-layout-sider>
|
||||
@@ -100,7 +79,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { ref, computed, onMounted, watch } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import {
|
||||
MenuFoldOutlined,
|
||||
@@ -117,14 +96,44 @@ import { message, Modal } from 'ant-design-vue'
|
||||
import { userApi, type UserVO } from '@/api/user'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const collapsed = ref(false)
|
||||
const userInfo = ref<UserVO | null>(null)
|
||||
const { loadUserPermissions, hasPermission, clearPermissions } = usePermission()
|
||||
|
||||
const selectedKeys = computed(() => [route.path])
|
||||
const menuItems = [
|
||||
{
|
||||
key: '/admin/dashboard',
|
||||
icon: DashboardOutlined,
|
||||
label: '仪表盘'
|
||||
},
|
||||
{
|
||||
key: '/admin/users',
|
||||
icon: UserOutlined,
|
||||
label: '用户管理'
|
||||
},
|
||||
{
|
||||
key: '/admin/products',
|
||||
icon: ShopOutlined,
|
||||
label: '商品管理'
|
||||
},
|
||||
{
|
||||
key: '/admin/shops',
|
||||
icon: HomeOutlined,
|
||||
label: '店铺管理'
|
||||
},
|
||||
{
|
||||
key: '/admin/permissions',
|
||||
icon: SafetyCertificateOutlined,
|
||||
label: '权限管理'
|
||||
}
|
||||
]
|
||||
|
||||
const selectedKeys = ref<string[]>([route.path])
|
||||
|
||||
const toggleCollapsed = () => {
|
||||
collapsed.value = !collapsed.value
|
||||
@@ -150,7 +159,10 @@ const handleLogout = () => {
|
||||
} finally {
|
||||
localStorage.removeItem('accessToken')
|
||||
localStorage.removeItem('refreshToken')
|
||||
localStorage.removeItem('adminAccessToken')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
clearPermissions()
|
||||
message.success('已退出登录')
|
||||
router.push('/auth')
|
||||
}
|
||||
@@ -167,8 +179,15 @@ const fetchUserInfo = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
watch(() => route.path, (newPath) => {
|
||||
selectedKeys.value = [newPath]
|
||||
}, { immediate: true })
|
||||
|
||||
onMounted(async () => {
|
||||
await Promise.all([
|
||||
fetchUserInfo(),
|
||||
loadUserPermissions()
|
||||
])
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user