feat: 补充`mock`接口

Former-commit-id: 9e1a5128d6
This commit is contained in:
hxr 2023-08-09 07:22:34 +08:00
parent 8c60fb2a23
commit 7725bd0792
4 changed files with 318 additions and 0 deletions

30
mock/dept.ts Normal file
View File

@ -0,0 +1,30 @@
import { MockMethod } from "vite-plugin-mock";
export default [
{
url: "/api/v1/dept/options",
method: "get",
response: () => {
return {
code: "00000",
data: [
{
value: 1,
label: "有来技术",
children: [
{
value: 2,
label: "研发部门",
},
{
value: 3,
label: "测试部门",
},
],
},
],
msg: "一切ok",
};
},
},
] as MockMethod[];

36
mock/dict.ts Normal file
View File

@ -0,0 +1,36 @@
import { MockMethod } from "vite-plugin-mock";
export default [
{
url: "/api/v1/dict/:code/options",
method: "get",
response: ({ url }) => {
const typeCode = url.match(/\/api\/v1\/dict\/(\w+)\/options/)[1];
let list = null;
if (typeCode == "gender") {
list = [
{
value: "1",
label: "男",
},
{
value: "2",
label: "女",
},
{
value: "0",
label: "未知",
},
];
}
return {
code: "00000",
data: list,
msg: "一切ok",
};
},
},
] as MockMethod[];

165
mock/role.ts Normal file
View File

@ -0,0 +1,165 @@
import { MockMethod } from "vite-plugin-mock";
export default [
{
url: "/api/v1/roles/options",
method: "get",
response: () => {
return {
code: "00000",
data: [
{
value: 2,
label: "系统管理员",
},
{
value: 4,
label: "系统管理员1",
},
{
value: 5,
label: "系统管理员2",
},
{
value: 6,
label: "系统管理员3",
},
{
value: 7,
label: "系统管理员4",
},
{
value: 8,
label: "系统管理员5",
},
{
value: 9,
label: "系统管理员6",
},
{
value: 10,
label: "系统管理员7",
},
{
value: 11,
label: "系统管理员8",
},
{
value: 12,
label: "系统管理员9",
},
{
value: 3,
label: "访问游客",
},
],
msg: "一切ok",
};
},
},
{
url: "/api/v1/roles/page",
method: "get",
response: () => {
return {
code: "00000",
data: {
list: [
{
id: 2,
name: "系统管理员",
code: "ADMIN",
status: 1,
sort: 2,
createTime: "2021-03-25 12:39:54",
updateTime: null,
},
{
id: 3,
name: "访问游客",
code: "GUEST",
status: 1,
sort: 3,
createTime: "2021-05-26 15:49:05",
updateTime: "2019-05-05 16:00:00",
},
{
id: 4,
name: "系统管理员1",
code: "ADMIN1",
status: 1,
sort: 2,
createTime: "2021-03-25 12:39:54",
updateTime: null,
},
{
id: 5,
name: "系统管理员2",
code: "ADMIN1",
status: 1,
sort: 2,
createTime: "2021-03-25 12:39:54",
updateTime: null,
},
{
id: 6,
name: "系统管理员3",
code: "ADMIN1",
status: 1,
sort: 2,
createTime: "2021-03-25 12:39:54",
updateTime: null,
},
{
id: 7,
name: "系统管理员4",
code: "ADMIN1",
status: 1,
sort: 2,
createTime: "2021-03-25 12:39:54",
updateTime: null,
},
{
id: 8,
name: "系统管理员5",
code: "ADMIN1",
status: 1,
sort: 2,
createTime: "2021-03-25 12:39:54",
updateTime: null,
},
{
id: 9,
name: "系统管理员6",
code: "ADMIN1",
status: 1,
sort: 2,
createTime: "2021-03-25 12:39:54",
updateTime: null,
},
{
id: 10,
name: "系统管理员7",
code: "ADMIN1",
status: 1,
sort: 2,
createTime: "2021-03-25 12:39:54",
updateTime: null,
},
{
id: 11,
name: "系统管理员8",
code: "ADMIN1",
status: 1,
sort: 2,
createTime: "2021-03-25 12:39:54",
updateTime: null,
},
],
total: 11,
},
msg: "一切ok",
};
},
},
] as MockMethod[];

View File

@ -92,4 +92,91 @@ export default [
}; };
}, },
}, },
{
url: "/api/v1/users/page",
method: "get",
response: () => {
return {
code: "00000",
data: {
list: [
{
id: 2,
username: "admin",
nickname: "系统管理员",
mobile: "17621210366",
genderLabel: "男",
avatar:
"https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif",
email: null,
status: 1,
deptName: "有来技术",
roleNames: "系统管理员",
createTime: "2019-10-10",
},
{
id: 3,
username: "test",
nickname: "测试小用户",
mobile: "17621210366",
genderLabel: "男",
avatar:
"https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif",
email: null,
status: 1,
deptName: "测试部门",
roleNames: "访问游客",
createTime: "2021-06-04",
},
],
total: 2,
},
msg: "一切ok",
};
},
},
{
url: "/api/v1/users/:id/form",
method: "get",
response: ({ url }) => {
const id = url.match(/\/api\/v1\/users\/(\d+)\/form/)[1];
let formData = null;
if (id == 2) {
formData = {
id: 2,
username: "admin",
nickname: "系统管理员",
mobile: "17621210366",
gender: 1,
avatar:
"https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif",
email: "",
status: 1,
deptId: 1,
roleIds: [2],
};
} else if (id == 3) {
formData = {
id: 3,
username: "test",
nickname: "测试小用户",
mobile: "17621210366",
gender: 1,
avatar:
"https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif",
email: "youlaitech@163.com",
status: 1,
deptId: 3,
roleIds: [3],
};
}
return {
code: "00000",
data: formData,
msg: "一切ok",
};
},
},
] as MockMethod[]; ] as MockMethod[];