mirror of
https://github.com/wangdage12/Snap.Server.Web.git
synced 2026-02-17 10:02:08 +08:00
添加部分用户管理功能和公告管理功能
This commit is contained in:
@@ -19,7 +19,7 @@ const routes = [
|
||||
},
|
||||
{
|
||||
path: 'user',
|
||||
component: () => import('@/views/dashboard/index.vue'),
|
||||
component: () => import('@/views/user/index.vue'),
|
||||
meta: { title: '用户管理', icon: 'User' },
|
||||
},
|
||||
{
|
||||
@@ -36,6 +36,11 @@ const routes = [
|
||||
component: () => import('@/views/dashboard/index.vue'),
|
||||
meta: { title: '角色管理', icon: 'UserFilled' },
|
||||
},
|
||||
{
|
||||
path: 'announcement',
|
||||
component: () => import('@/views/announcement/index.vue'),
|
||||
meta: { title: '公告管理', icon: 'Bell' },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
37
src/router/permission.ts
Normal file
37
src/router/permission.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import router from './index'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
const userStore = useUserStore()
|
||||
|
||||
// 未登录
|
||||
if (!userStore.token) {
|
||||
if (to.path === '/login') {
|
||||
next()
|
||||
} else {
|
||||
next('/login')
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 已登录还去 login
|
||||
if (to.path === '/login') {
|
||||
next('/')
|
||||
return
|
||||
}
|
||||
|
||||
// 如果没有用户信息,尝试获取
|
||||
if (!userStore.userInfo) {
|
||||
try {
|
||||
await userStore.fetchUserInfo()
|
||||
} catch (error) {
|
||||
// 获取用户信息失败,可能token已过期,跳转到登录页
|
||||
console.error('获取用户信息失败:', error)
|
||||
userStore.logout()
|
||||
next('/login')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
next()
|
||||
})
|
||||
Reference in New Issue
Block a user