1. 重构权限码规范,将系统权限前缀从perm:system改为system: 2. 扩展系统设置模型,支持string/image/select/boolean四种配置类型 3. 新增设置项选项配置、图片上传功能 4. 重构初始化权限数据,拆分权限与系统设置权限结构 5. 重写前端系统设置页面,支持按类型渲染不同配置表单 6. 添加python-multipart依赖支持文件上传 遗留问题: 1.系统设置页面的添加设置按钮无法使用
103 lines
2.8 KiB
TypeScript
103 lines
2.8 KiB
TypeScript
import { createRouter, createWebHistory } from "vue-router";
|
|
import { useAuthStore } from "@/modules/admin/stores/auth";
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
|
routes: [
|
|
{
|
|
path: "/",
|
|
name: "public-home",
|
|
meta: { title: "首页" },
|
|
component: () => import("@/modules/public/views/PublicHome.vue"),
|
|
},
|
|
{
|
|
path: "/admin/login",
|
|
name: "admin-login",
|
|
meta: { title: "管理后台登录", guestOnly: true },
|
|
component: () => import("@/modules/admin/views/LoginView.vue"),
|
|
},
|
|
{
|
|
path: "/admin",
|
|
component: () => import("@/modules/admin/layout/AdminLayout.vue"),
|
|
meta: { requiresAuth: true },
|
|
children: [
|
|
{
|
|
path: "",
|
|
redirect: { name: "admin-users" },
|
|
},
|
|
{
|
|
path: "users",
|
|
name: "admin-users",
|
|
meta: { title: "用户管理", permission: "perm:user" },
|
|
component: () => import("@/modules/admin/views/users/UserManage.vue"),
|
|
},
|
|
{
|
|
path: "roles",
|
|
name: "admin-roles",
|
|
meta: { title: "角色管理", permission: "perm:role" },
|
|
component: () => import("@/modules/admin/views/roles/RoleManage.vue"),
|
|
|
|
},
|
|
{
|
|
path: "permissions",
|
|
name: "admin-permissions",
|
|
meta: { title: "权限管理", permission: "perm:config" },
|
|
component: () =>
|
|
import("@/modules/admin/views/permissions/PermissionManage.vue"),
|
|
},
|
|
{
|
|
path: "settings",
|
|
name: "admin-settings",
|
|
meta: { title: "系统设置", permission: "system:" },
|
|
component: () =>
|
|
import("@/modules/admin/views/settings/SettingManage.vue"),
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
|
|
router.beforeEach(async (to, _from, next) => {
|
|
const auth = useAuthStore();
|
|
const title = (to.meta.title as string) || "BookSystem";
|
|
document.title = `${title} · BookSystem`;
|
|
|
|
if (to.meta.requiresAuth && !auth.isAuthenticated) {
|
|
next({
|
|
name: "admin-login",
|
|
query: { redirect: to.fullPath },
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (to.meta.guestOnly && auth.isAuthenticated) {
|
|
if (!auth.user || auth.permissions.length === 0) {
|
|
try {
|
|
await auth.fetchProfile();
|
|
await auth.fetchPermissions();
|
|
} catch {
|
|
auth.logout();
|
|
next({ name: "admin-login" });
|
|
return;
|
|
}
|
|
}
|
|
next({ name: "admin-users" });
|
|
return;
|
|
}
|
|
|
|
const requiredPermission = to.meta.permission as string;
|
|
if (requiredPermission && auth.isAuthenticated && auth.permissions.length > 0) {
|
|
const hasPermission = auth.permissions.some(p =>
|
|
p.code.startsWith(requiredPermission)
|
|
);
|
|
if (!hasPermission) {
|
|
next({ name: "admin-users" });
|
|
return;
|
|
}
|
|
}
|
|
|
|
next();
|
|
});
|
|
|
|
export default router;
|