|
|
@@ -0,0 +1,149 @@
|
|
|
+import type { MockMethod } from "vite-plugin-mock";
|
|
|
+
|
|
|
+export default [
|
|
|
+ // 登录接口
|
|
|
+ {
|
|
|
+ url: "/api/auth/login",
|
|
|
+ method: "post",
|
|
|
+ response: ({ body }) => {
|
|
|
+ const { username, password } = body;
|
|
|
+
|
|
|
+ if (username === "admin" && password === "123456") {
|
|
|
+ return {
|
|
|
+ code: 200,
|
|
|
+ message: "登录成功",
|
|
|
+ data: {
|
|
|
+ token: "mock_token_" + Date.now(),
|
|
|
+ userInfo: {
|
|
|
+ id: "1",
|
|
|
+ username: "admin",
|
|
|
+ nickname: "管理员",
|
|
|
+ avatar: "",
|
|
|
+ roles: ["admin"],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ code: 401,
|
|
|
+ message: "用户名或密码错误",
|
|
|
+ data: null,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取用户信息
|
|
|
+ {
|
|
|
+ url: "/api/user/info",
|
|
|
+ method: "get",
|
|
|
+ response: () => {
|
|
|
+ return {
|
|
|
+ code: 200,
|
|
|
+ message: "success",
|
|
|
+ data: {
|
|
|
+ id: "1",
|
|
|
+ username: "admin",
|
|
|
+ nickname: "管理员",
|
|
|
+ avatar: "",
|
|
|
+ roles: ["admin"],
|
|
|
+ email: "admin@example.com",
|
|
|
+ phone: "13800138000",
|
|
|
+ },
|
|
|
+ };
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取菜单列表
|
|
|
+ {
|
|
|
+ url: "/api/menu/list",
|
|
|
+ method: "get",
|
|
|
+ response: () => {
|
|
|
+ return {
|
|
|
+ code: 200,
|
|
|
+ message: "success",
|
|
|
+ data: [
|
|
|
+ {
|
|
|
+ id: "1",
|
|
|
+ name: "仪表盘",
|
|
|
+ path: "/dashboard",
|
|
|
+ icon: "Odometer",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: "2",
|
|
|
+ name: "用户管理",
|
|
|
+ path: "/user",
|
|
|
+ icon: "User",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: "3",
|
|
|
+ name: "系统管理",
|
|
|
+ path: "/system",
|
|
|
+ icon: "Setting",
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ id: "3-1",
|
|
|
+ name: "菜单管理",
|
|
|
+ path: "/system/menu",
|
|
|
+ icon: "Menu",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: "3-2",
|
|
|
+ name: "角色管理",
|
|
|
+ path: "/system/role",
|
|
|
+ icon: "UserFilled",
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: "4",
|
|
|
+ name: "数据统计",
|
|
|
+ path: "/statistics",
|
|
|
+ icon: "TrendCharts",
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ };
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
+ // 用户列表
|
|
|
+ {
|
|
|
+ url: "/api/user/list",
|
|
|
+ method: "get",
|
|
|
+ response: ({ query }) => {
|
|
|
+ const { page = 1, size = 10 } = query;
|
|
|
+
|
|
|
+ // 生成模拟数据
|
|
|
+ const list = Array.from({ length: size }, (_, i) => ({
|
|
|
+ id: String((page - 1) * size + i + 1),
|
|
|
+ username: `user${(page - 1) * size + i + 1}`,
|
|
|
+ nickname: `用户${(page - 1) * size + i + 1}`,
|
|
|
+ email: `user${(page - 1) * size + i + 1}@example.com`,
|
|
|
+ status: Math.random() > 0.3 ? 1 : 0,
|
|
|
+ createTime: "2024-01-01 12:00:00",
|
|
|
+ }));
|
|
|
+
|
|
|
+ return {
|
|
|
+ code: 200,
|
|
|
+ message: "success",
|
|
|
+ data: {
|
|
|
+ list,
|
|
|
+ total: 100,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ },
|
|
|
+ },
|
|
|
+
|
|
|
+ // 退出登录
|
|
|
+ {
|
|
|
+ url: "/api/auth/logout",
|
|
|
+ method: "post",
|
|
|
+ response: () => {
|
|
|
+ return {
|
|
|
+ code: 200,
|
|
|
+ message: "退出成功",
|
|
|
+ data: null,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ },
|
|
|
+] as MockMethod[];
|