fix: 只有admin才可以看到并配置管理后台
This commit is contained in:
1 parent
2e9a70933d
commit
489c79758d
2 files changed
+13
No files matched your search
@@ -7,6 +7,7 @@ import AdminView from '../views/AdminView.vue';
|
|||||||
import ProfileView from '../views/ProfileView.vue';
|
import ProfileView from '../views/ProfileView.vue';
|
||||||
import ResetPasswordView from '../views/ResetPasswordView.vue';
|
import ResetPasswordView from '../views/ResetPasswordView.vue';
|
||||||
import { config } from '../config';
|
import { config } from '../config';
|
||||||
|
import { getStoredAuthUser } from '../utils/auth';
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{
|
{
|
||||||
@@ -52,6 +53,17 @@ const router = createRouter({
|
|||||||
routes
|
routes
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.beforeEach((to, _from, next) => {
|
||||||
|
if (to.path === '/admin') {
|
||||||
|
const user = getStoredAuthUser();
|
||||||
|
if (!user || user.role !== 'admin') {
|
||||||
|
next('/workspace');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
router.afterEach((to) => {
|
router.afterEach((to) => {
|
||||||
const baseTitle = config.appTitle || 'AI工作台';
|
const baseTitle = config.appTitle || 'AI工作台';
|
||||||
if (to.meta.title) {
|
if (to.meta.title) {
|
||||||
|
|||||||
@@ -1407,6 +1407,7 @@ onMounted(async () => {
|
|||||||
<span>返回聊天</span>
|
<span>返回聊天</span>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
|
v-if="currentUser?.role === 'admin'"
|
||||||
@click="openAdminPanel"
|
@click="openAdminPanel"
|
||||||
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium text-slate-600 transition-all hover:bg-slate-50 hover:text-slate-900"
|
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium text-slate-600 transition-all hover:bg-slate-50 hover:text-slate-900"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in new issue
Block a user