123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- import { defineFakeRoute } from "vite-plugin-fake-server/client";
- import { faker } from "@faker-js/faker/locale/zh_CN";
- export default defineFakeRoute([
- // 用户管理
- {
- url: "/user",
- method: "post",
- response: ({ body }) => {
- let list = [
- {
- username: "admin",
- nickname: "admin",
- avatar: "https://avatars.githubusercontent.com/u/44761321",
- phone: "15888886789",
- email: faker.internet.email(),
- 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",
- email: faker.internet.email(),
- 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);
- return {
- success: true,
- data: {
- list,
- total: list.length, // 总条目数
- pageSize: 10, // 每页显示条目个数
- currentPage: 1 // 当前页数
- }
- };
- }
- },
- // 用户管理-获取所有角色列表
- {
- 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: []
- };
- }
- }
- },
- // 角色管理
- {
- 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 // 当前页数
- }
- };
- }
- },
- // 部门管理
- {
- url: "/dept",
- method: "post",
- response: () => {
- return {
- success: true,
- data: [
- {
- name: "杭州总公司",
- parentId: 0,
- id: 100,
- sort: 0,
- phone: "15888888888",
- principal: faker.person.firstName(),
- email: faker.internet.email(),
- status: 1, // 状态 1 启用 0 停用
- type: 1, // 1 公司 2 分公司 3 部门
- createTime: 1605456000000,
- remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
- },
- {
- name: "郑州分公司",
- parentId: 100,
- id: 101,
- sort: 1,
- phone: "15888888888",
- principal: faker.person.firstName(),
- email: faker.internet.email(),
- status: 1,
- type: 2,
- createTime: 1605456000000,
- remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
- },
- {
- name: "研发部门",
- parentId: 101,
- id: 103,
- sort: 1,
- phone: "15888888888",
- principal: faker.person.firstName(),
- email: faker.internet.email(),
- status: 1,
- type: 3,
- createTime: 1605456000000,
- remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
- },
- {
- name: "市场部门",
- parentId: 102,
- id: 108,
- sort: 1,
- phone: "15888888888",
- principal: faker.person.firstName(),
- email: faker.internet.email(),
- status: 1,
- type: 3,
- createTime: 1605456000000,
- remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
- },
- {
- name: "深圳分公司",
- parentId: 100,
- id: 102,
- sort: 2,
- phone: "15888888888",
- principal: faker.person.firstName(),
- email: faker.internet.email(),
- status: 1,
- type: 2,
- createTime: 1605456000000,
- remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
- },
- {
- name: "市场部门",
- parentId: 101,
- id: 104,
- sort: 2,
- phone: "15888888888",
- principal: faker.person.firstName(),
- email: faker.internet.email(),
- status: 1,
- type: 3,
- createTime: 1605456000000,
- remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
- },
- {
- name: "财务部门",
- parentId: 102,
- id: 109,
- sort: 2,
- phone: "15888888888",
- principal: faker.person.firstName(),
- email: faker.internet.email(),
- status: 1,
- type: 3,
- createTime: 1605456000000,
- remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
- },
- {
- name: "测试部门",
- parentId: 101,
- id: 105,
- sort: 3,
- phone: "15888888888",
- principal: faker.person.firstName(),
- email: faker.internet.email(),
- status: 0,
- type: 3,
- createTime: 1605456000000,
- remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
- },
- {
- name: "财务部门",
- parentId: 101,
- id: 106,
- sort: 4,
- phone: "15888888888",
- principal: faker.person.firstName(),
- email: faker.internet.email(),
- status: 1,
- type: 3,
- createTime: 1605456000000,
- remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
- },
- {
- name: "运维部门",
- parentId: 101,
- id: 107,
- sort: 5,
- phone: "15888888888",
- principal: faker.person.firstName(),
- email: faker.internet.email(),
- status: 0,
- type: 3,
- createTime: 1605456000000,
- remark: "这里是备注信息这里是备注信息这里是备注信息这里是备注信息"
- }
- ]
- };
- }
- }
- ]);
|