feat: 初始化智能物联网设备管理系统前后端基础项目
完成项目整体结构搭建,包含: 1. 前端Vue3+TS+Vite+Antd项目基础配置与核心依赖 2. 后端MidwayJS+TypeORM+JWT权限认证框架 3. 完整的用户、角色、权限、日志数据库表结构 4. 核心业务模块API与基础服务实现 5. 全局样式、路由、状态管理配置
This commit is contained in:
commit
3d7eb12103
89 files changed
+16085
No files matched your search
@@ -0,0 +1,132 @@
|
||||
import { createRouter, createWebHistory, type RouteRecordRaw } from "vue-router";
|
||||
import { usePermissionStore } from "@/stores/permission";
|
||||
import { getToken } from "@/utils/auth";
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: "/login",
|
||||
name: "Login",
|
||||
component: () => import("@/views/login/index.vue"),
|
||||
meta: { requiresAuth: false, title: "登录" }
|
||||
},
|
||||
{
|
||||
path: "/",
|
||||
component: () => import("@/layouts/index.vue"),
|
||||
redirect: "/dashboard",
|
||||
children: [
|
||||
{
|
||||
path: "dashboard",
|
||||
name: "Dashboard",
|
||||
component: () => import("@/views/dashboard/index.vue"),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
title: "仪表盘",
|
||||
permission: "dashboard"
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "system/user",
|
||||
name: "UserList",
|
||||
component: () => import("@/views/system/user/index.vue"),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
title: "用户管理",
|
||||
permission: "user:list"
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "system/role",
|
||||
name: "RoleList",
|
||||
component: () => import("@/views/system/role/index.vue"),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
title: "角色管理",
|
||||
permission: "role:list"
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "settings/basic",
|
||||
name: "BasicSettings",
|
||||
component: () => import("@/views/settings/basic.vue"),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
title: "基本设置",
|
||||
permission: "system:basicSetting"
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "settings/security",
|
||||
name: "SecuritySettings",
|
||||
component: () => import("@/views/settings/security.vue"),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
title: "安全设置",
|
||||
permission: "system:securitySetting"
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "log/operation",
|
||||
name: "OperationLog",
|
||||
component: () => import("@/views/log/operation.vue"),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
title: "操作日志",
|
||||
permission: "log:operation"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: "/:pathMatch(.*)*",
|
||||
redirect: "/login"
|
||||
}
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes
|
||||
});
|
||||
|
||||
router.beforeEach(async (to, _from, next) => {
|
||||
document.title = to.meta.title ? `${to.meta.title} - 智能物联网设备管理系统` : "智能物联网设备管理系统";
|
||||
|
||||
const permissionStore = usePermissionStore();
|
||||
const token = getToken();
|
||||
|
||||
if (to.meta.requiresAuth === false) {
|
||||
if (to.path === "/login" && token) {
|
||||
next({ path: "/" });
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
next({
|
||||
path: "/login",
|
||||
query: { redirect: to.fullPath }
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!permissionStore.userInfo) {
|
||||
try {
|
||||
await permissionStore.fetchUserInfo();
|
||||
} catch (error) {
|
||||
permissionStore.logout();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (to.meta.permission) {
|
||||
if (!permissionStore.hasPermission(to.meta.permission as string)) {
|
||||
next({ path: "/403" });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in new issue
Block a user