2023-11-10 12:33:22 +08:00
|
|
|
|
import { defineFakeRoute } from "vite-plugin-fake-server/client";
|
|
|
|
|
import { faker } from "@faker-js/faker/locale/zh_CN";
|
2022-04-10 12:08:19 +08:00
|
|
|
|
|
2023-11-10 12:33:22 +08:00
|
|
|
|
export default defineFakeRoute([
|
2023-08-29 11:18:00 +08:00
|
|
|
|
// 用户管理
|
2022-04-10 12:08:19 +08:00
|
|
|
|
{
|
2023-05-17 11:41:18 +08:00
|
|
|
|
url: "/user",
|
2022-04-10 12:08:19 +08:00
|
|
|
|
method: "post",
|
2023-08-29 11:18:00 +08:00
|
|
|
|
response: ({ body }) => {
|
|
|
|
|
let list = [
|
|
|
|
|
{
|
|
|
|
|
username: "admin",
|
|
|
|
|
nickname: "admin",
|
|
|
|
|
avatar: "https://avatars.githubusercontent.com/u/44761321",
|
|
|
|
|
phone: "15888886789",
|
2023-11-10 12:33:22 +08:00
|
|
|
|
email: faker.internet.email(),
|
2023-08-29 11:18:00 +08:00
|
|
|
|
sex: 0,
|
|
|
|
|
id: 1,
|
|
|
|
|
status: 1,
|
|
|
|
|
dept: {
|
|
|
|
|
// 部门id
|
|
|
|
|
id: 103,
|
|
|
|
|
// 部门名称
|
|
|
|
|
name: "研发部门"
|
|
|
|
|
},
|
|
|
|
|
remark: "管理员",
|
|
|
|
|
createTime: 1605456000000
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
username: "common",
|
|
|
|
|
nickname: "common",
|
|
|
|
|
avatar: "https://avatars.githubusercontent.com/u/52823142",
|
|
|
|
|
phone: "18288882345",
|
2023-11-10 12:33:22 +08:00
|
|
|
|
email: faker.internet.email(),
|
2023-08-29 11:18:00 +08:00
|
|
|
|
sex: 1,
|
|
|
|
|
id: 2,
|
|
|
|
|
status: 1,
|
|
|
|
|
dept: {
|
|
|
|
|
id: 105,
|
|
|
|
|
name: "测试部门"
|
|
|
|
|
},
|
|
|
|
|
remark: "普通用户",
|
|
|
|
|
createTime: 1605456000000
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
list = list.filter(item => item.username.includes(body?.username));
|
|
|
|
|
list = list.filter(item =>
|
|
|
|
|
String(item.status).includes(String(body?.status))
|
|
|
|
|
);
|
|
|
|
|
if (body.phone) list = list.filter(item => item.phone === body.phone);
|
|
|
|
|
if (body.deptId) list = list.filter(item => item.dept.id === body.deptId);
|
2022-04-10 12:08:19 +08:00
|
|
|
|
return {
|
2022-10-25 12:17:13 +08:00
|
|
|
|
success: true,
|
2022-04-10 12:08:19 +08:00
|
|
|
|
data: {
|
2023-08-29 11:18:00 +08:00
|
|
|
|
list,
|
|
|
|
|
total: list.length, // 总条目数
|
|
|
|
|
pageSize: 10, // 每页显示条目个数
|
|
|
|
|
currentPage: 1 // 当前页数
|
2023-05-17 11:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-08-29 11:18:00 +08:00
|
|
|
|
// 用户管理-获取所有角色列表
|
|
|
|
|
{
|
|
|
|
|
url: "/list-all-role",
|
|
|
|
|
method: "get",
|
|
|
|
|
response: () => {
|
|
|
|
|
return {
|
|
|
|
|
success: true,
|
|
|
|
|
data: [
|
|
|
|
|
{ id: 1, name: "超级管理员" },
|
|
|
|
|
{ id: 2, name: "普通角色" }
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 用户管理-根据userId,获取对应角色id列表(userId:用户id)
|
|
|
|
|
{
|
|
|
|
|
url: "/list-role-ids",
|
|
|
|
|
method: "post",
|
|
|
|
|
response: ({ body }) => {
|
|
|
|
|
if (body.userId) {
|
|
|
|
|
if (body.userId == 1) {
|
|
|
|
|
return {
|
|
|
|
|
success: true,
|
|
|
|
|
data: [1]
|
|
|
|
|
};
|
|
|
|
|
} else if (body.userId == 2) {
|
|
|
|
|
return {
|
|
|
|
|
success: true,
|
|
|
|
|
data: [2]
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
success: false,
|
|
|
|
|
data: []
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 角色管理
|
2023-05-17 11:41:18 +08:00
|
|
|
|
{
|
|
|
|
|
url: "/role",
|
|
|
|
|
method: "post",
|
|
|
|
|
response: ({ body }) => {
|
|
|
|
|
let list = [
|
|
|
|
|
{
|
|
|
|
|
createTime: 1605456000000, // 时间戳(毫秒ms)
|
|
|
|
|
updateTime: 1684512000000,
|
|
|
|
|
id: 1,
|
|
|
|
|
name: "超级管理员",
|
|
|
|
|
code: "admin",
|
|
|
|
|
status: 1, // 状态 1 启用 0 停用
|
|
|
|
|
remark: "超级管理员拥有最高权限"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
createTime: 1605456000000,
|
|
|
|
|
updateTime: 1684512000000,
|
|
|
|
|
id: 2,
|
|
|
|
|
name: "普通角色",
|
|
|
|
|
code: "common",
|
|
|
|
|
status: 1,
|
|
|
|
|
remark: "普通角色拥有部分权限"
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
list = list.filter(item => item.name.includes(body?.name));
|
|
|
|
|
list = list.filter(item =>
|
|
|
|
|
String(item.status).includes(String(body?.status))
|
|
|
|
|
);
|
|
|
|
|
if (body.code) list = list.filter(item => item.code === body.code);
|
|
|
|
|
return {
|
|
|
|
|
success: true,
|
|
|
|
|
data: {
|
|
|
|
|
list,
|
|
|
|
|
total: list.length, // 总条目数
|
|
|
|
|
pageSize: 10, // 每页显示条目个数
|
|
|
|
|
currentPage: 1 // 当前页数
|
2022-04-18 00:30:10 +08:00
|
|
|
|
}
|
2022-04-10 12:08:19 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
2022-04-10 23:54:14 +08:00
|
|
|
|
},
|
2023-08-29 11:18:00 +08:00
|
|
|
|
// 部门管理
|
2022-04-10 23:54:14 +08:00
|
|
|
|
{
|
|
|
|
|
url: "/dept",
|
|
|
|
|
method: "post",
|
|
|
|
|
response: () => {
|
|
|
|
|
return {
|
2022-10-25 12:17:13 +08:00
|
|
|
|
success: true,
|
2022-04-10 23:54:14 +08:00
|
|
|
|
data: [
|
|
|
|
|
{
|
2022-04-15 22:07:11 +08:00
|
|
|
|
name: "杭州总公司",
|
2022-04-10 23:54:14 +08:00
|
|
|
|
parentId: 0,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
id: 100,
|
2022-04-10 23:54:14 +08:00
|
|
|
|
sort: 0,
|
|
|
|
|
phone: "15888888888",
|
2023-11-10 12:33:22 +08:00
|
|
|
|
principal: faker.person.firstName(),
|
|
|
|
|
email: faker.internet.email(),
|
2023-05-17 11:41:18 +08:00
|
|
|
|
status: 1, // 状态 1 启用 0 停用
|
2023-05-11 15:11:58 +08:00
|
|
|
|
type: 1, // 1 公司 2 分公司 3 部门
|
|
|
|
|
createTime: 1605456000000,
|
2023-11-10 12:33:22 +08:00
|
|
|
|
remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
|
2022-04-10 23:54:14 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2022-04-15 22:07:11 +08:00
|
|
|
|
name: "郑州分公司",
|
2022-04-10 23:54:14 +08:00
|
|
|
|
parentId: 100,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
id: 101,
|
2022-04-10 23:54:14 +08:00
|
|
|
|
sort: 1,
|
|
|
|
|
phone: "15888888888",
|
2023-11-10 12:33:22 +08:00
|
|
|
|
principal: faker.person.firstName(),
|
|
|
|
|
email: faker.internet.email(),
|
2023-05-11 15:11:58 +08:00
|
|
|
|
status: 1,
|
|
|
|
|
type: 2,
|
|
|
|
|
createTime: 1605456000000,
|
2023-11-10 12:33:22 +08:00
|
|
|
|
remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
|
2022-04-10 23:54:14 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "研发部门",
|
|
|
|
|
parentId: 101,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
id: 103,
|
2022-04-10 23:54:14 +08:00
|
|
|
|
sort: 1,
|
|
|
|
|
phone: "15888888888",
|
2023-11-10 12:33:22 +08:00
|
|
|
|
principal: faker.person.firstName(),
|
|
|
|
|
email: faker.internet.email(),
|
2023-05-11 15:11:58 +08:00
|
|
|
|
status: 1,
|
|
|
|
|
type: 3,
|
|
|
|
|
createTime: 1605456000000,
|
2023-11-10 12:33:22 +08:00
|
|
|
|
remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
|
2022-04-10 23:54:14 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "市场部门",
|
|
|
|
|
parentId: 102,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
id: 108,
|
2022-04-10 23:54:14 +08:00
|
|
|
|
sort: 1,
|
|
|
|
|
phone: "15888888888",
|
2023-11-10 12:33:22 +08:00
|
|
|
|
principal: faker.person.firstName(),
|
|
|
|
|
email: faker.internet.email(),
|
2023-05-11 15:11:58 +08:00
|
|
|
|
status: 1,
|
|
|
|
|
type: 3,
|
|
|
|
|
createTime: 1605456000000,
|
2023-11-10 12:33:22 +08:00
|
|
|
|
remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
|
2022-04-10 23:54:14 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2022-04-15 22:07:11 +08:00
|
|
|
|
name: "深圳分公司",
|
2022-04-10 23:54:14 +08:00
|
|
|
|
parentId: 100,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
id: 102,
|
2022-04-10 23:54:14 +08:00
|
|
|
|
sort: 2,
|
|
|
|
|
phone: "15888888888",
|
2023-11-10 12:33:22 +08:00
|
|
|
|
principal: faker.person.firstName(),
|
|
|
|
|
email: faker.internet.email(),
|
2023-05-11 15:11:58 +08:00
|
|
|
|
status: 1,
|
|
|
|
|
type: 2,
|
|
|
|
|
createTime: 1605456000000,
|
2023-11-10 12:33:22 +08:00
|
|
|
|
remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
|
2022-04-10 23:54:14 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "市场部门",
|
|
|
|
|
parentId: 101,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
id: 104,
|
2022-04-10 23:54:14 +08:00
|
|
|
|
sort: 2,
|
|
|
|
|
phone: "15888888888",
|
2023-11-10 12:33:22 +08:00
|
|
|
|
principal: faker.person.firstName(),
|
|
|
|
|
email: faker.internet.email(),
|
2022-04-10 23:54:14 +08:00
|
|
|
|
status: 1,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
type: 3,
|
|
|
|
|
createTime: 1605456000000,
|
2023-11-10 12:33:22 +08:00
|
|
|
|
remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
|
2022-04-10 23:54:14 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "财务部门",
|
|
|
|
|
parentId: 102,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
id: 109,
|
2022-04-10 23:54:14 +08:00
|
|
|
|
sort: 2,
|
|
|
|
|
phone: "15888888888",
|
2023-11-10 12:33:22 +08:00
|
|
|
|
principal: faker.person.firstName(),
|
|
|
|
|
email: faker.internet.email(),
|
2023-05-11 15:11:58 +08:00
|
|
|
|
status: 1,
|
|
|
|
|
type: 3,
|
|
|
|
|
createTime: 1605456000000,
|
2023-11-10 12:33:22 +08:00
|
|
|
|
remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
|
2022-04-10 23:54:14 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "测试部门",
|
|
|
|
|
parentId: 101,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
id: 105,
|
2022-04-10 23:54:14 +08:00
|
|
|
|
sort: 3,
|
|
|
|
|
phone: "15888888888",
|
2023-11-10 12:33:22 +08:00
|
|
|
|
principal: faker.person.firstName(),
|
|
|
|
|
email: faker.internet.email(),
|
2022-04-10 23:54:14 +08:00
|
|
|
|
status: 0,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
type: 3,
|
|
|
|
|
createTime: 1605456000000,
|
2023-11-10 12:33:22 +08:00
|
|
|
|
remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
|
2022-04-10 23:54:14 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "财务部门",
|
|
|
|
|
parentId: 101,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
id: 106,
|
2022-04-10 23:54:14 +08:00
|
|
|
|
sort: 4,
|
|
|
|
|
phone: "15888888888",
|
2023-11-10 12:33:22 +08:00
|
|
|
|
principal: faker.person.firstName(),
|
|
|
|
|
email: faker.internet.email(),
|
2022-04-10 23:54:14 +08:00
|
|
|
|
status: 1,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
type: 3,
|
|
|
|
|
createTime: 1605456000000,
|
2023-11-10 12:33:22 +08:00
|
|
|
|
remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
|
2022-04-10 23:54:14 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "运维部门",
|
|
|
|
|
parentId: 101,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
id: 107,
|
2022-04-10 23:54:14 +08:00
|
|
|
|
sort: 5,
|
|
|
|
|
phone: "15888888888",
|
2023-11-10 12:33:22 +08:00
|
|
|
|
principal: faker.person.firstName(),
|
|
|
|
|
email: faker.internet.email(),
|
2022-04-10 23:54:14 +08:00
|
|
|
|
status: 0,
|
2023-05-11 15:11:58 +08:00
|
|
|
|
type: 3,
|
|
|
|
|
createTime: 1605456000000,
|
2023-11-10 12:33:22 +08:00
|
|
|
|
remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
|
2022-04-10 23:54:14 +08:00
|
|
|
|
}
|
2022-04-18 00:30:10 +08:00
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-04-10 12:08:19 +08:00
|
|
|
|
}
|
2023-11-10 12:33:22 +08:00
|
|
|
|
]);
|