From 9e1a5128d6ac9d8161240d224324b79c5e4f3dcc Mon Sep 17 00:00:00 2001 From: hxr <1490493387@qq.com> Date: Wed, 9 Aug 2023 07:22:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20:sparkles:=20=E8=A1=A5=E5=85=85`mock`?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mock/dept.ts | 30 ++++++++++ mock/dict.ts | 36 +++++++++++ mock/role.ts | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++ mock/user.ts | 87 +++++++++++++++++++++++++++ 4 files changed, 318 insertions(+) create mode 100644 mock/dept.ts create mode 100644 mock/dict.ts create mode 100644 mock/role.ts diff --git a/mock/dept.ts b/mock/dept.ts new file mode 100644 index 0000000..91746f4 --- /dev/null +++ b/mock/dept.ts @@ -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[]; diff --git a/mock/dict.ts b/mock/dict.ts new file mode 100644 index 0000000..4ee38c3 --- /dev/null +++ b/mock/dict.ts @@ -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[]; diff --git a/mock/role.ts b/mock/role.ts new file mode 100644 index 0000000..6c3419f --- /dev/null +++ b/mock/role.ts @@ -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[]; diff --git a/mock/user.ts b/mock/user.ts index 6f0cadc..71d4468 100644 --- a/mock/user.ts +++ b/mock/user.ts @@ -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[];