Skip to content

Mock 数据说明

Mock 目录
bash
  ├── src
   ├── mock                                 # Mock 定义
                                    #
   ├── auth                             # 认证接口
   ├── login.ts                     # 认证接口 - 系统登录 (提供 mock 数据)
   ├── loginUserInfo.ts             # 认证接口 - 获取用户信息 (提供 mock 数据)
   ├── loginUserMenu.ts             # 认证接口 - 获取用户菜单 (提供 mock 数据)
   ├── logout.ts                    # 认证接口 - 系统退出
   ├── modifyPassword.ts            # 认证接口 - 修改密码
                                    #
   ├── base                             # 字典接口
   ├── getOptionById.ts             # 字典接口 - 查询 Option 下拉框 (提供 mock 数据)
   ├── getTreeById.ts               # 字典接口 - 查询 Tree 下拉框 (提供 mock 数据)
                                    #
   ├── organize                         # 组织接口
   ├── addOrganizeInfo.ts           # 组织接口 - 新增组织信息
   ├── deleteOrganizeInfo.ts        # 组织接口 - 删除组织信息
   ├── getOrganizeInfoList.ts       # 组织接口 - 获取组织列表 (提供 mock 数据)
   ├── getOrganizeInfoTree.ts       # 组织接口 - 获取组织 Tree 列表 (提供 mock 数据)
   ├── modifyOrganizeInfo.ts        # 组织接口 - 修改组织信息
                                    #
   ├── resource                         # 资源接口
   ├── addResourceInfo.ts           # 资源接口 - 新增资源信息
   ├── deleteResourceInfo.ts        # 资源接口 - 删除资源信息
   ├── getResourceButtonByRole.ts   # 资源接口 - 根据角色查询按钮资源 (提供 mock 数据)
   ├── getResourceListInfo.ts       # 资源接口 - 查询资源信息 (提供 mock 数据)
   ├── getResourceMenuByRole.ts     # 资源接口 - 根据角色查询菜单资源 (提供 mock 数据)
   ├── getResourceTreeInfo.ts       # 资源接口 - 查询所有菜单资源 (提供 mock 数据)
   ├── modifyResourceInfo.ts        # 资源接口 - 修改资源信息
   ├── modifyResoureInfoByRole.ts   # 资源接口 - 修改角色资源配置
                                    #
   ├── role                             # 角色接口
   ├── addRoleInfo.ts               # 角色接口 - 新增角色信息
   ├── deleteRoleInfo.ts            # 角色接口 - 删除角色信息
   ├── getRoleInfoByPages.ts        # 角色接口 - 分页获取角色列表 (提供 mock 数据)
   ├── getRoleInfoList.ts           # 角色接口 - 获取所有角色列表 (提供 mock 数据)
   ├── modifyRoleInfo.ts            # 角色接口 - 修改角色信息
                                    #
   ├── user                             # 用户接口
   ├── addUserInfo.ts               # 用户接口 - 新增用户信息
   ├── deleteUserInfo.ts            # 用户接口 - 删除用户信息
   ├── getUserInfoList.ts           # 用户接口 - 获取用户列表 (提供 mock 数据)
   ├── modifyUserInfo.ts            # 用户接口 - 修改用户信息
                                    #
   ├── index.ts                         # 按需导入 上述 mock 接口服务
   ├── setup.ts                         # 定义 setupWorker (配合 public/msw.js 实现 Mock Service)
                                        #
   ├── main.ts                              # 主入口文件 (通过 `import '@/mock'` 启用 Mock 服务)

认证接口

系统登录 /api/auth/login
typescript
// 范例:
const result = {
  data: {
    userNo: "admin", // 用户账号
    userName: "admin", // 用户名称
    mobilePhone: "182588xxx88", // 用户手机号
    orgId: "101.100.131", // 用户所属组织 ID
    orgName: "北仑网安通信有限公司", // 用户所属组织 Name
    deptId: "1126534161135795132", // 用户所属部门 ID
    deptName: "软件部", // 用户所属部门 Name
    activity: "Y", // 启用用户账号
  },
  token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.xxxxxxxxxxx-xxx", // 用户 token
};
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "系统登录";
const url = resolver("/auth/login");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    let resource: any = null;

    if (
      body.username !== "admin" ||
      body.password !== "25d55ad283aa400af464c76d713c07ad"
    ) {
      resource = {
        code: "9999",
        message: "用户名密码错误",
        result: null,
      };
    }

    if (
      body.username === "admin" &&
      body.password === "25d55ad283aa400af464c76d713c07ad"
    ) {
      resource = {
        code: "0000",
        message: null,
        result: {
          data: {
            userNo: "admin",
            userName: "admin",
            mobilePhone: "182588xxx88",
            orgId: "101.100.131",
            orgName: "北仑网安通信有限公司",
            deptId: "1126534161135795132",
            deptName: "软件部",
            activity: "Y",
          },
          token:
            "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxODI1ODc2NDMyMSIsImV4cCI6MTY0MjQ4NTQwNX0.gFrCkMY5OlheC7sF7elhb8cF2fvkD-dj950xklyI14Q",
        },
      };
    }

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);
获取用户信息 /api/auth/loginUserInfo
typescript
// 范例:
const result = {
  userNo: "admin", // 用户账号
  userName: "admin", // 用户名称
  postName: "系统管理", // 用户职位
  mobilePhone: "182588xxx88", // 用户手机号
  orgId: "101.100.131", // 用户所属组织 ID
  orgName: "北仑网安通信有限公司", // 用户所属组织 Name
  deptId: "1126534161135795132", // 用户所属部门 ID
  deptName: "软件部", // 用户所属部门 Name
  dataFlag: "2", // 数据范围 flag
  activity: "Y", // 启用用户账号
  role: {
    permissions: [
      {
        permissionId: "ResourceManage", // 资源管理页面
        actionEntitySet: [
          { action: "add", defaultCheck: false, describe: "新增" }, // 按钮权限 - 新增 v-action:add
          { action: "del", defaultCheck: false, describe: "删除" }, // 按钮权限 - 删除 v-action:del
        ],
      },
    ],
  },
};
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "获取用户信息";
const url = resolver("/auth/loginUserInfo");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    const resource = {
      code: "0000",
      message: null,
      result: {
        userNo: "admin",
        userName: "admin",
        mobilePhone: "182588xxx88",
        postName: "系统管理",
        orgId: "101.100.131",
        orgName: "北仑网安通信有限公司",
        deptId: "1126534161135795132",
        deptName: "软件部",
        dataFlag: "2",
        activity: "Y",
        role: {
          permissions: [
            {
              permissionId: "ResourceManage", // 资源管理页面
              actionEntitySet: [
                { action: "add", defaultCheck: false, describe: "新增" },
                { action: "del", defaultCheck: false, describe: "删除" },
              ],
            },
            {
              permissionId: "RoleManage", // 角色管理页面
              actionEntitySet: [
                { action: "add", defaultCheck: false, describe: "新增" },
                { action: "del", defaultCheck: false, describe: "删除" },
                { action: "edit", defaultCheck: false, describe: "修改" },
                { action: "query", defaultCheck: false, describe: "查询" },
              ],
            },
            {
              permissionId: "OrganizeManage", // 组织管理页面
              actionEntitySet: [
                { action: "add", defaultCheck: false, describe: "新增" },
                { action: "del", defaultCheck: false, describe: "删除" },
                { action: "edit", defaultCheck: false, describe: "修改" },
                { action: "query", defaultCheck: false, describe: "查询" },
              ],
            },
            {
              permissionId: "UserManage", // 用户管理页面
              actionEntitySet: [
                { action: "add", defaultCheck: false, describe: "新增" },
                { action: "del", defaultCheck: false, describe: "删除" },
                { action: "edit", defaultCheck: false, describe: "修改" },
                { action: "query", defaultCheck: false, describe: "查询" },
              ],
            },
          ],
        },
      },
    };

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);
获取用户菜单 /api/auth/loginUserMenu
typescript
// 范例:
const result = {
  id: "27245863256459422", // 路由 ID
  sort: 1000000, // 菜单排序
  name: "system", // 路由 name
  path: "", // 路由 path
  parentId: "0", // 父路由 ID
  component: "PageView", // 路由组件
  redirect: "/system/OrganizeManage", // 路由重定向
  meta: {
    icon: "", // 菜单 icon
    title: "系统管理", // 菜单 title
    hideChildInMenu: "N", // 是否隐藏子菜单
    hideInMenu: "N", // 是否隐藏当前菜单
    allowCache: "Y", // 是否启用缓存
  },
};
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "获取用户菜单";
const url = resolver("/auth/loginUserMenu");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    const resource = {
      code: "0000",
      message: null,
      result: [
        {
          sort: 1000000,
          id: "27245863256459422",
          name: "system",
          path: "",
          parentId: "0",
          component: "PageView",
          redirect: "/system/OrganizeManage",
          meta: {
            icon: "CodepenOutlined",
            title: "系统管理",
            hideChildInMenu: "N",
            hideInMenu: "N",
            allowCache: "Y",
          },
        },
        {
          sort: 1000100,
          id: "1127282136000102507",
          name: "OrganizeManage",
          path: "/system/OrganizeManage",
          parentId: "27245863256459422",
          component: "OrganizeManage",
          redirect: "",
          meta: {
            icon: "CodepenOutlined",
            title: "组织管理",
            hideChildInMenu: "N",
            hideInMenu: "N",
            allowCache: "Y",
          },
        },
        {
          sort: 1000200,
          id: "27245863256459445",
          name: "ResourceManage",
          path: "/system/ResourceManage",
          parentId: "27245863256459422",
          component: "ResourceManage",
          redirect: "",
          meta: {
            icon: "CodepenOutlined",
            title: "资源管理",
            hideChildInMenu: "N",
            hideInMenu: "N",
            allowCache: "Y",
          },
        },
        {
          sort: 1000300,
          id: "27245863256459495",
          name: "RoleManage",
          path: "/system/RoleManage",
          parentId: "27245863256459422",
          component: "RoleManage",
          redirect: "",
          meta: {
            icon: "CodepenOutlined",
            title: "角色管理",
            hideChildInMenu: "N",
            hideInMenu: "N",
            allowCache: "Y",
          },
        },
        {
          sort: 1000400,
          id: "1127282136000102579",
          name: "UserManage",
          path: "/system/UserManage",
          parentId: "27245863256459422",
          component: "UserManage",
          redirect: "",
          meta: {
            icon: "CodepenOutlined",
            title: "用户管理",
            hideChildInMenu: "N",
            hideInMenu: "N",
            allowCache: "Y",
          },
        },
      ],
    };

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);

字典接口

查询 Option 下拉框 /api/base/getOptionById
typescript
// 范例:
const result = [
  {
    label: "label", // 选项 label 文本
    value: "value", // 选项 value 值
  },
];
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "查询 Option 下拉框";
const url = resolver("/base/getOptionById");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    let resource: any = null;

    switch (body && body.id) {
      case "dept": {
        resource = {
          code: "0000",
          message: null,
          result: [
            {
              label: "公司部",
              parentId: "101.100.131",
              value: "1126534161135795126",
            },
            {
              label: "人事部",
              parentId: "101.100.131",
              value: "1126534161135795127",
            },
            {
              label: "财务部",
              parentId: "101.100.131",
              value: "1126534161135795128",
            },
            {
              label: "市场部",
              parentId: "101.100.131",
              value: "1126534161135795129",
            },
            {
              label: "运维部",
              parentId: "101.100.131",
              value: "1126534161135795130",
            },
            {
              label: "系统部",
              parentId: "101.100.131",
              value: "1126534161135795131",
            },
            {
              label: "软件部",
              parentId: "101.100.131",
              value: "1126534161135795132",
            },
            {
              label: "大数据中心",
              parentId: "101.100.131",
              value: "1126534161135795133",
            },
            {
              label: "技术中心",
              parentId: "101.100.131",
              value: "1126534161135795134",
            },
            {
              label: "研发中心",
              parentId: "101.100.131",
              value: "1126534161135795135",
            },
          ],
        };
        break;
      }
      default: {
        resource = {
          code: "0000",
          message: null,
          result: [],
        };
      }
    }

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);
查询 Tree 下拉框 /api/base/getTreeById
typescript
// 范例:
const result = [
  {
    label: "label", // 选项 label 文本
    value: "value", // 选项 value 值
    children: [
      {
        label: "label", // 子选项 label 文本
        value: "value", // 子选项 value 值
      },
    ],
  },
];
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "查询 Tree 下拉框";
const url = resolver("/base/getTreeById");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    let resource: any = null;

    switch (body && body.id) {
      case "orgTree": {
        resource = {
          code: "0000",
          message: null,
          result: [
            {
              label: "浙大远疆投资集团有限公司",
              shortName: "集团公司",
              value: "1",
              valueParent: "0",
              children: [
                {
                  label: "港运信息有限公司",
                  shortName: "港运公司",
                  value: "101.100",
                  valueParent: "1",
                  children: [
                    {
                      label: "一号集装箱码头有限公司",
                      shortName: "集运一号",
                      value: "101.100.101",
                      valueParent: "101.100",
                    },
                    {
                      label: "二号集装箱码头分公司",
                      shortName: "集运二号",
                      value: "101.100.105",
                      valueParent: "101.100",
                    },
                    {
                      label: "三号集装箱码头有限公司",
                      shortName: "集运三号",
                      value: "101.100.103",
                      valueParent: "101.100",
                    },
                    {
                      label: "梅山船运有限公司",
                      shortName: "梅山公司",
                      value: "101.100.104",
                      valueParent: "101.100",
                    },
                    {
                      label: "舟山客运有限公司",
                      shortName: "舟运公司",
                      value: "101.100.107",
                      valueParent: "101.100",
                    },
                    {
                      label: "苏州钢材有限公司",
                      shortName: "苏州钢材",
                      value: "101.100.106",
                      valueParent: "101.100",
                    },
                    {
                      label: "宁波永耀科技公司",
                      shortName: "永耀公司",
                      value: "101.100.108",
                      valueParent: "101.100",
                    },
                    {
                      label: "太仓微柯有限公司",
                      shortName: "太仓微柯",
                      value: "101.100.110",
                      valueParent: "101.100",
                    },
                    {
                      label: "东海食品加工有限公司",
                      shortName: "东海食品",
                      value: "101.100.111",
                      valueParent: "101.100",
                    },
                    {
                      label: "镇海希港公司",
                      shortName: "希港公司",
                      value: "101.100.112",
                      valueParent: "101.100",
                    },
                    {
                      label: "嘉兴港智科技有限公司",
                      shortName: "嘉兴港智",
                      value: "101.102",
                      valueParent: "101.100",
                    },
                    {
                      label: "北仑网安通信有限公司",
                      shortName: "北仑网安",
                      value: "101.100.113",
                      valueParent: "101.100",
                      children: [
                        {
                          label: "北仑海运有限责任公司",
                          shortName: "北仑海运",
                          value: "101.100.113.126",
                          valueParent: "101.100.113",
                        },
                      ],
                    },
                    {
                      label: "天芸集团有限公司",
                      shortName: "天芸集团",
                      value: "101.101",
                      valueParent: "101.100",
                      children: [
                        {
                          label: "温州信讯有限公司",
                          shortName: "温州信讯",
                          value: "101.101.105",
                          valueParent: "101.101",
                        },
                      ],
                    },
                    {
                      label: "太一集装箱码头有限公司",
                      shortName: "太一集司",
                      value: "101.100.106.100",
                      valueParent: "101.100",
                    },
                    {
                      label: "宁波铁运有限公司",
                      shortName: "宁波铁运",
                      value: "101.100.122",
                      valueParent: "101.100",
                    },
                    {
                      label: "万仓码头有限公司",
                      shortName: "万仓公司",
                      value: "101.100.114",
                      valueParent: "101.100",
                    },
                    {
                      label: "南京明夕有限公司",
                      shortName: "南京明夕",
                      value: "101.100.109",
                      valueParent: "101.100",
                    },
                    {
                      label: "浙江义乌微贸有限公司",
                      shortName: "义乌微贸",
                      value: "101.103",
                      valueParent: "101.100",
                    },
                    {
                      label: "宁波甬轮有限公司",
                      shortName: "宁波甬轮",
                      value: "101.100.128",
                      valueParent: "101.100",
                    },
                    {
                      label: "宁波云港运输有限公司",
                      shortName: "宁波云港",
                      value: "101.104",
                      valueParent: "101.100",
                    },
                    {
                      label: "宁波大航有限公司",
                      shortName: "宁波大航",
                      value: "101.106",
                      valueParent: "101.100",
                    },
                    {
                      label: "小港集装箱运输有限公司",
                      shortName: "小港集运公司",
                      value: "101.100.117",
                      valueParent: "101.100",
                    },
                    {
                      label: "麦羽港务有限公司",
                      shortName: "麦羽港务",
                      value: "101.122",
                      valueParent: "101.100",
                    },
                    {
                      label: "上海海马物流有限公司",
                      shortName: "海马物流",
                      value: "101.100.116",
                      valueParent: "101.100",
                    },
                    {
                      label: "舟山船代有限公司",
                      shortName: "船代公司",
                      value: "101.100.120",
                      valueParent: "101.100",
                    },
                    {
                      label: "宁波电商贸易有限公司",
                      shortName: "电商贸易",
                      value: "101.105",
                      valueParent: "101.100",
                    },
                    {
                      label: "宁波港业有限公司",
                      shortName: "宁波港业",
                      value: "101.100.121",
                      valueParent: "101.100",
                    },
                    {
                      label: "台州外轮理货有限公司",
                      shortName: "台州理货",
                      value: "101.100.123",
                      valueParent: "101.100",
                    },
                    {
                      label: "港通电子商务有限公司",
                      shortName: "港通电商",
                      value: "101.107",
                      valueParent: "101.100",
                    },
                    {
                      label: "北仑网安通信有限公司",
                      shortName: "北仑网安",
                      value: "101.100.131",
                      valueParent: "101.100",
                    },
                    {
                      label: "梅京众联有限公司",
                      shortName: "梅京众联",
                      value: "112.001",
                      valueParent: "101.100",
                    },
                    {
                      label: "浙江内港发展有限公司",
                      shortName: "浙江内港",
                      value: "101.119",
                      valueParent: "101.100",
                    },
                    {
                      label: "江阴集装箱码头有限公司",
                      shortName: "江阴集装箱公司",
                      value: "101.100.130",
                      valueParent: "101.100",
                    },
                    {
                      label: "舟山东极岛开发有限公司",
                      shortName: "东极岛公司",
                      value: "1.109",
                      valueParent: "101.100",
                    },
                    {
                      label: "船舶市场有限公司",
                      shortName: "船舶市场有限公司",
                      value: "101.100.113.100",
                      valueParent: "101.100",
                    },
                    {
                      label: "远洋投资开发有限公司",
                      shortName: "远洋投资",
                      value: "1.113",
                      valueParent: "101.100",
                    },
                    {
                      label: "商品交易中心有限公司",
                      shortName: "商品交易 ",
                      value: "1.114",
                      valueParent: "101.100",
                    },
                    {
                      label: "宁财港务有限公司",
                      shortName: "宁财港务",
                      value: "101.100.138",
                      valueParent: "101.100",
                    },
                    {
                      label: "宁波航运科技有限公司",
                      shortName: "宁波航运科技",
                      value: "1.721",
                      valueParent: "101.100",
                    },
                    {
                      label: "舟山微智集团财务有限公司",
                      shortName: "舟山微智",
                      value: "101.112",
                      valueParent: "101.100",
                    },
                    {
                      label: "游龙港务有限公司",
                      shortName: "游龙港务",
                      value: "101.119.100",
                      valueParent: "101.100",
                    },
                    {
                      label: "大榭招商国际投资有限公司",
                      shortName: "大榭招商",
                      value: "101.100.102",
                      valueParent: "101.100",
                    },
                    {
                      label: "航铁联合物流有限公司",
                      shortName: "航铁物流",
                      value: "101.100.127",
                      valueParent: "101.100",
                    },
                    {
                      label: "浙麦铁运管理有限公司",
                      shortName: "浙麦铁运",
                      value: "101.100.155",
                      valueParent: "101.100",
                    },
                    {
                      label: "舟山散货物流有限公司 ",
                      shortName: "舟山散货物流有限公司",
                      value: "101.121",
                      valueParent: "101.100",
                    },
                    {
                      label: "长兴港安有限公司",
                      shortName: "长兴港安",
                      value: "101.119.102",
                      valueParent: "101.100",
                    },
                    {
                      label: "浙芸资产管理有限公司 ",
                      shortName: "浙芸资管公司 ",
                      value: "101.110",
                      valueParent: "101.100",
                    },
                  ],
                },
              ],
            },
          ],
        };
        break;
      }
      default: {
        resource = {
          code: "0000",
          message: null,
          result: [],
        };
      }
    }

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);

组织接口

分页查询组织列表 /api/organize/getOrganizeInfoList
typescript
// 范例:
const result = {
  key: "1", // 组织 ID
  isOrg: "Y", // 是组织 (组织 'Y', 部门 'N')
  isLeaf: false, // 是否为叶子结点
  title: "浙大远疆投资集团有限公司", // 组织/部门 名称
  orgShortName: "集团公司", // 组织/部门 简称
  parentOrgId: "0", // 父组织 名称
  parentOrgName: "", // 父组织 ID
  activity: "Y", // 启用状态
};
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "分页查询组织列表";
const url = resolver("/organize/getOrganizeInfoList");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    let resource: any = null;

    switch (body && body.params && body.params.orgId) {
      case "1": {
        resource = {
          code: "0000",
          message: null,
          result: {
            data: [
              {
                key: "1",
                isOrg: "Y",
                isLeaf: false,
                title: "浙大远疆投资集团有限公司",
                orgShortName: "集团公司",
                parentOrgId: "0",
                parentOrgName: "",
                activity: "Y",
              },
              {
                key: "101.100",
                isOrg: "Y",
                isLeaf: false,
                title: "港运信息有限公司",
                orgShortName: "港运公司",
                parentOrgId: "1",
                parentOrgName: "浙大远疆投资集团有限公司",
                activity: "Y",
              },
            ],
            pageNo: 1,
            pageSize: 20,
            totalSize: 2,
            totalPage: 1,
          },
        };
        break;
      }
      case "101.100": {
        resource = {
          code: "0000",
          message: null,
          result: {
            data: [
              {
                key: "101.100",
                isOrg: "Y",
                isLeaf: false,
                title: "港运信息有限公司",
                orgShortName: "港运公司",
                parentOrgId: "1",
                parentOrgName: "浙大远疆投资集团有限公司",
                activity: "Y",
              },
              {
                key: "101.100.131",
                isOrg: "Y",
                isLeaf: false,
                title: "北仑网安通信有限公司",
                orgShortName: "北仑网安",
                parentOrgId: "101.100",
                parentOrgName: "港运信息有限公司",
                activity: "Y",
              },
              {
                key: "101.100.138",
                isOrg: "Y",
                isLeaf: false,
                title: "宁财港务有限公司",
                orgShortName: "宁财港务",
                parentOrgId: "101.100",
                parentOrgName: "港运信息有限公司",
                activity: "Y",
              },
            ],
            pageNo: 1,
            pageSize: 20,
            totalSize: 3,
            totalPage: 1,
          },
        };
        break;
      }
      case "101.100.131": {
        resource = {
          code: "0000",
          message: null,
          result: {
            data: [
              {
                key: "101.100.131",
                isOrg: "Y",
                isLeaf: false,
                title: "北仑网安通信有限公司",
                orgShortName: "北仑网安",
                parentOrgId: "101.100",
                parentOrgName: "港运信息有限公司",
                activity: "Y",
              },
              {
                key: "1126534161135795126",
                isOrg: "N",
                isLeaf: true,
                title: "公司部",
                orgShortName: "",
                activity: "Y",
              },
              {
                key: "1126534161135795127",
                isOrg: "N",
                isLeaf: true,
                title: "人事部",
                orgShortName: "",
                activity: "Y",
              },
              {
                key: "1126534161135795128",
                isOrg: "N",
                isLeaf: true,
                title: "财务部",
                orgShortName: "",
                activity: "Y",
              },
              {
                key: "1126534161135795129",
                isOrg: "N",
                isLeaf: true,
                title: "市场部",
                orgShortName: "",
                activity: "Y",
              },
              {
                key: "1126534161135795130",
                isOrg: "N",
                isLeaf: true,
                title: "运维部",
                orgShortName: "",
                activity: "Y",
              },
              {
                key: "1126534161135795131",
                isOrg: "N",
                isLeaf: true,
                title: "系统部",
                orgShortName: "",
                activity: "Y",
              },
              {
                key: "1126534161135795132",
                isOrg: "N",
                isLeaf: true,
                title: "开发部",
                orgShortName: "",
                activity: "Y",
              },
              {
                key: "1126534161135795133",
                isOrg: "N",
                isLeaf: true,
                title: "大数据中心",
                orgShortName: "",
                activity: "Y",
              },
              {
                key: "1126534161135795134",
                isOrg: "N",
                isLeaf: true,
                title: "技术中心",
                orgShortName: "",
                activity: "Y",
              },
              {
                key: "1126534161135795135",
                isOrg: "N",
                isLeaf: true,
                title: "研发中心",
                orgShortName: "",
                activity: "Y",
              },
              {
                key: "1126534161135795642",
                isOrg: "N",
                isLeaf: true,
                title: "后勤中心",
                orgShortName: "",
                activity: "Y",
              },
              {
                key: "1127020120488651741",
                isOrg: "N",
                isLeaf: true,
                title: "工程部",
                orgShortName: "",
                activity: "Y",
              },
            ],
            pageNo: 1,
            pageSize: 20,
            totalSize: 13,
            totalPage: 1,
          },
        };
        break;
      }
      case "101.100.138": {
        resource = {
          code: "0000",
          message: null,
          result: {
            data: [
              {
                key: "101.100.138",
                isOrg: "Y",
                isLeaf: false,
                title: "宁财港务有限公司",
                orgShortName: "宁财港务",
                parentOrgId: "101.100",
                parentOrgName: "港运信息有限公司",
                activity: "Y",
              },
            ],
            pageNo: 1,
            pageSize: 20,
            totalSize: 1,
            totalPage: 1,
          },
        };
        break;
      }
      default: {
        resource = {
          code: "0000",
          message: null,
          result: {
            data: [],
            pageNo: 1,
            pageSize: 20,
            totalSize: 0,
            totalPage: 0,
          },
        };
      }
    }

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);
获取组织 Tree 列表 /api/organize/getOrganizeInfoTree
typescript
// 范例:
const result = [
  {
    key: "1", // 组织 ID
    isOrg: "Y", // 是组织 (组织 'Y', 部门 'N')
    isLeaf: false, // 是否为叶子结点
    title: "浙大远疆投资集团有限公司", // 组织/部门 名称
    orgShortName: "集团公司", // 组织/部门 简称
  },
];
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "获取组织 Tree 列表";
const url = resolver("/organize/getOrganizeInfoTree");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    let resource: any = null;

    switch (body && body.params && body.params.orgId) {
      case "0": {
        resource = {
          code: "0000",
          message: null,
          result: [
            {
              key: "1",
              isOrg: "Y",
              isLeaf: false,
              title: "浙大远疆投资集团有限公司",
              orgShortName: "集团公司",
            },
          ],
        };
        break;
      }
      case "1": {
        resource = {
          code: "0000",
          message: null,
          result: [
            {
              key: "101.100",
              isOrg: "Y",
              isLeaf: false,
              title: "港运信息有限公司",
              orgShortName: "港运公司",
            },
          ],
        };
        break;
      }
      case "101.100": {
        resource = {
          code: "0000",
          message: null,
          result: [
            {
              key: "101.100.131",
              isOrg: "Y",
              isLeaf: true,
              title: "北仑网安通信有限公司",
              orgShortName: "北仑网安",
            },
            {
              key: "101.100.138",
              isOrg: "Y",
              isLeaf: true,
              title: "宁财港务有限公司",
              orgShortName: "宁财港务",
            },
          ],
        };
        break;
      }
      default: {
        resource = {
          code: "0000",
          message: null,
          result: [],
        };
      }
    }

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);

资源接口

根据角色查询按钮资源 /api/resource/getResourceButtonByRole
typescript
// 范例:
const result = {
  id: "1127282136000102507", // 菜单资源 id
  actionsOptions: [
    { label: "新增", value: "1127282136000102508" }, // 按钮权限: label -> 新增文本, value -> 新增按钮 id 值
    { label: "删除", value: "1127282136000102509" }, // 按钮权限: label -> 删除文本, value -> 删除按钮 id 值
    { label: "修改", value: "1127282136000102510" }, // 按钮权限: label -> 修改文本, value -> 修改按钮 id 值
    { label: "查询", value: "1127282136000102511" }, // 按钮权限: label -> 查询文本, value -> 查询按钮 id 值
  ],
  selected: [
    "1127282136000102508", // 已启用 新增 按钮资源
    "1127282136000102509", // 已启用 删除 按钮资源
    "1127282136000102510", // 已启用 修改 按钮资源
    "1127282136000102511", // 已启用 查询 按钮资源
  ],
};
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "根据角色查询按钮资源";
const url = resolver("/resource/getResourceButtonByRole");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    const resource = {
      code: "0000",
      message: null,
      result: [] as any,
    };

    for (const item of body.params) {
      // 角色: 系统管理
      // 菜单: 系统管理
      if (
        item.roleId === "27442970747734159" &&
        item.menuId === "27245863256459422"
      ) {
        resource.result.push({
          id: "27245863256459422",
          actionsOptions: [],
          selected: [],
        });
      }

      // 角色: 系统管理
      // 菜单: 组织管理
      if (
        item.roleId === "27442970747734159" &&
        item.menuId === "1127282136000102507"
      ) {
        resource.result.push({
          id: "1127282136000102507",
          actionsOptions: [
            { label: "新增", value: "1127282136000102508" },
            { label: "删除", value: "1127282136000102509" },
            { label: "修改", value: "1127282136000102510" },
            { label: "查询", value: "1127282136000102511" },
          ],
          selected: [
            "1127282136000102508",
            "1127282136000102509",
            "1127282136000102510",
            "1127282136000102511",
          ],
        });
      }

      // 角色: 系统管理
      // 菜单: 资源管理
      if (
        item.roleId === "27442970747734159" &&
        item.menuId === "27245863256459445"
      ) {
        resource.result.push({
          id: "27245863256459445",
          actionsOptions: [
            { label: "新增", value: "27245863256459447" },
            { label: "删除", value: "27245863256459449" },
          ],
          selected: ["27245863256459447", "27245863256459449"],
        });
      }

      // 角色: 系统管理
      // 菜单: 角色管理
      if (
        item.roleId === "27442970747734159" &&
        item.menuId === "27245863256459495"
      ) {
        resource.result.push({
          id: "27245863256459495",
          actionsOptions: [
            { label: "新增", value: "27245863256459496" },
            { label: "删除", value: "27245863256459497" },
            { label: "修改", value: "27245863256459498" },
            { label: "查询", value: "27245863256459499" },
          ],
          selected: [
            "27245863256459496",
            "27245863256459497",
            "27245863256459498",
            "27245863256459499",
          ],
        });
      }

      // 角色: 系统管理
      // 菜单: 用户管理
      if (
        item.roleId === "27442970747734159" &&
        item.menuId === "1127282136000102579"
      ) {
        resource.result.push({
          id: "1127282136000102579",
          actionsOptions: [
            { label: "新增", value: "1127282136000102580" },
            { label: "删除", value: "1127282136000102581" },
            { label: "修改", value: "1127282136000102582" },
            { label: "查询", value: "1127282136000102583" },
          ],
          selected: [
            "1127282136000102580",
            "1127282136000102581",
            "1127282136000102582",
            "1127282136000102583",
          ],
        });
      }
    }

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);
分页查询资源信息 /api/resource/getResourceListInfo
typescript
// 范例:
const result = {
  sort: 1000100, // 菜单资源 - 排序 (Layout.sider 菜单顺序)
  path: "/system/OrganizeManage", // 菜单路由 - path
  icon: "CodepenOutlined", // 菜单资源 - icon
  title: "组织管理", // 菜单资源 - title
  redirect: "", // 菜单路由 - 重定向
  parentId: "27245863256459422", // 菜单路由 - 父 id
  component: "OrganizeManage", // 菜单路由 - 组件
  resourceId: "1127282136000102507", // 菜单路由 - id
  resourceName: "OrganizeManage", // 菜单路由 - name
  resourceType: "m", // 菜单资源 - 类型, 'm' -> 菜单, 'b' -> '按钮'
  hideChildInMenu: "N", // 隐藏子菜单资源
  hideInMenu: "N", // 隐藏当前菜单资源
  allowCache: "Y", // 启用路由缓存
  activity: "Y", // 启用菜单资源
};
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "分页查询资源信息";
const url = resolver("/resource/getResourceListInfo");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    let resource: any = null;

    switch (body.params.parentId) {
      // 菜单 - 系统管理
      case "27245863256459422": {
        resource = {
          code: "0000",
          message: null,
          result: {
            data: [
              {
                sort: 1000100,
                path: "/system/OrganizeManage",
                icon: "CodepenOutlined",
                title: "组织管理",
                redirect: "",
                parentId: "27245863256459422",
                component: "OrganizeManage",
                resourceId: "1127282136000102507",
                resourceName: "OrganizeManage",
                resourceType: "m",
                hideChildInMenu: "N",
                hideInMenu: "N",
                allowCache: "Y",
                activity: "Y",
              },
              {
                sort: 1000200,
                path: "/system/ResourceManage",
                icon: "CodepenOutlined",
                title: "资源管理",
                redirect: "",
                parentId: "27245863256459422",
                component: "ResourceManage",
                resourceId: "27245863256459445",
                resourceName: "ResourceManage",
                resourceType: "m",
                hideChildInMenu: "N",
                hideInMenu: "N",
                allowCache: "Y",
                activity: "Y",
              },
              {
                sort: 1000300,
                path: "/system/RoleManage",
                icon: "CodepenOutlined",
                title: "角色管理",
                redirect: "",
                parentId: "27245863256459422",
                component: "RoleManage",
                resourceId: "27245863256459495",
                resourceName: "RoleManage",
                resourceType: "m",
                hideChildInMenu: "N",
                hideInMenu: "N",
                allowCache: "Y",
                activity: "Y",
              },
              {
                sort: 1000400,
                path: "/system/UserManage",
                icon: "CodepenOutlined",
                title: "用户管理",
                redirect: "",
                parentId: "27245863256459422",
                component: "UserManage",
                resourceId: "1127282136000102579",
                resourceName: "UserManage",
                resourceType: "m",
                hideChildInMenu: "N",
                hideInMenu: "N",
                allowCache: "Y",
                activity: "Y",
              },
            ],
            pageNo: 1,
            pageSize: 20,
            totalSize: 4,
            totalPage: 1,
          },
        };
        break;
      }

      // 菜单 - 组织管理
      case "1127282136000102507": {
        resource = {
          code: "0000",
          message: null,
          result: {
            data: [
              {
                sort: 1,
                title: "新增",
                parentId: "1127282136000102507",
                component: "OrganizeManage",
                resourceId: "1127282136000102508",
                resourceName: "add",
                resourceType: "b",
                activity: "Y",
              },
              {
                sort: 2,
                title: "删除",
                parentId: "1127282136000102507",
                component: "OrganizeManage",
                resourceId: "1127282136000102509",
                resourceName: "del",
                resourceType: "b",
                activity: "Y",
              },
              {
                sort: 3,
                title: "修改",
                parentId: "1127282136000102507",
                component: "OrganizeManage",
                resourceId: "1127282136000102510",
                resourceName: "edit",
                resourceType: "b",
                activity: "Y",
              },
              {
                sort: 4,
                title: "查询",
                parentId: "1127282136000102507",
                component: "OrganizeManage",
                resourceId: "1127282136000102511",
                resourceName: "query",
                resourceType: "b",
                activity: "Y",
              },
            ],
            pageNo: 1,
            pageSize: 20,
            totalSize: 4,
            totalPage: 1,
          },
        };
        break;
      }

      // 菜单 - 资源管理
      case "27245863256459445": {
        resource = {
          code: "0000",
          message: null,
          result: {
            data: [
              {
                sort: 1,
                title: "新增",
                parentId: "27245863256459445",
                component: "ResourceManage",
                resourceId: "27245863256459447",
                resourceName: "add",
                resourceType: "b",
                activity: "Y",
              },
              {
                sort: 2,
                title: "删除",
                parentId: "27245863256459445",
                component: "ResourceManage",
                resourceId: "27245863256459449",
                resourceName: "del",
                resourceType: "b",
                activity: "Y",
              },
            ],
            pageNo: 1,
            pageSize: 20,
            totalSize: 2,
            totalPage: 1,
          },
        };
        break;
      }

      // 菜单 - 角色管理
      case "27245863256459495": {
        resource = {
          code: "0000",
          message: null,
          result: {
            data: [
              {
                sort: 1,
                title: "新增",
                parentId: "27245863256459495",
                component: "RoleManage",
                resourceId: "27245863256459496",
                resourceName: "add",
                resourceType: "b",
                activity: "Y",
              },
              {
                sort: 2,
                title: "删除",
                parentId: "27245863256459495",
                component: "RoleManage",
                resourceId: "27245863256459497",
                resourceName: "del",
                resourceType: "b",
                activity: "Y",
              },
              {
                sort: 3,
                title: "修改",
                parentId: "27245863256459495",
                component: "RoleManage",
                resourceId: "27245863256459498",
                resourceName: "edit",
                resourceType: "b",
                activity: "Y",
              },
              {
                sort: 4,
                title: "查询",
                parentId: "27245863256459495",
                component: "RoleManage",
                resourceId: "27245863256459499",
                resourceName: "query",
                resourceType: "b",
                activity: "Y",
              },
            ],
            pageNo: 1,
            pageSize: 20,
            totalSize: 4,
            totalPage: 1,
          },
        };
        break;
      }

      // 菜单 - 用户管理
      case "1127282136000102579": {
        resource = {
          code: "0000",
          message: null,
          result: {
            data: [
              {
                sort: 1,
                title: "新增",
                parentId: "1127282136000102579",
                component: "UserManage",
                resourceId: "1127282136000102580",
                resourceName: "add",
                resourceType: "b",
                activity: "Y",
              },
              {
                sort: 2,
                title: "删除",
                parentId: "1127282136000102579",
                component: "UserManage",
                resourceId: "1127282136000102581",
                resourceName: "del",
                resourceType: "b",
                activity: "Y",
              },
              {
                sort: 3,
                title: "修改",
                parentId: "1127282136000102579",
                component: "UserManage",
                resourceId: "1127282136000102582",
                resourceName: "edit",
                resourceType: "b",
                activity: "Y",
              },
              {
                sort: 4,
                title: "查询",
                parentId: "1127282136000102579",
                component: "UserManage",
                resourceId: "1127282136000102583",
                resourceName: "query",
                resourceType: "b",
                activity: "Y",
              },
            ],
            pageNo: 1,
            pageSize: 20,
            totalSize: 4,
            totalPage: 1,
          },
        };
        break;
      }

      default: {
        resource = {
          code: "0000",
          message: null,
          result: {
            data: [],
            pageNo: 1,
            pageSize: 20,
            totalSize: 0,
            totalPage: 0,
          },
        };
      }
    }

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);
根据角色查询菜单资源 /api/resource/getResourceMenuByRole
typescript
// 范例:
const result = {
  treeNodes: [
    {
      label: "根目录", // 菜单资源 名称
      value: "0", // 菜单资源 id 值
      children: [
        {
          label: "系统管理", // 子菜单资源 名称
          value: "27245863256459422", // 子菜单资源 id 值
          children: [
            { label: "组织管理", value: "1127282136000102507" },
            { label: "资源管理", value: "27245863256459445" },
            { label: "角色管理", value: "27245863256459495" },
            { label: "用户管理", value: "1127282136000102579" },
          ],
        },
      ],
    },
  ],
  treeSelect: [
    "27245863256459422", // 菜单资源 - 组织管理 (已选择)
    "1127282136000102507", // 菜单资源 - 系统管理 (已选择)
    "27245863256459445", // 菜单资源 - 资源管理 (已选择)
    "27245863256459495", // 菜单资源 - 角色管理 (已选择)
    "1127282136000102579", // 菜单资源 - 用户管理 (已选择)
  ],
};
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "根据角色查询菜单资源";
const url = resolver("/resource/getResourceMenuByRole");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    const resource = {
      code: "0000",
      message: null,
      result: {
        treeNodes: [
          {
            label: "根目录",
            value: "0",
            children: [
              {
                label: "系统管理",
                value: "27245863256459422",
                children: [
                  {
                    children: [],
                    label: "组织管理",
                    value: "1127282136000102507",
                  },
                  {
                    children: [],
                    label: "资源管理",
                    value: "27245863256459445",
                  },
                  {
                    children: [],
                    label: "角色管理",
                    value: "27245863256459495",
                  },
                  {
                    children: [],
                    label: "用户管理",
                    value: "1127282136000102579",
                  },
                ],
              },
            ],
          },
        ],
        treeSelect: [
          "27245863256459422",
          "1127282136000102507",
          "27245863256459445",
          "27245863256459495",
          "1127282136000102579",
        ],
      },
    };

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);
查询所有菜单资源 /api/resource/getResourceTreeInfo
typescript
// 范例:
const result = {
  sort: 1000100, // 菜单资源 - 排序 (Layout.sider 菜单顺序)
  path: "/system/OrganizeManage", // 菜单路由 - path
  icon: "CodepenOutlined", // 菜单资源 - icon
  title: "组织管理", // 菜单资源 - title
  redirect: "", // 菜单路由 - 重定向
  parentId: "27245863256459422", // 菜单路由 - 父 id
  component: "OrganizeManage", // 菜单路由 - 组件
  resourceId: "1127282136000102507", // 菜单路由 - id
  resourceName: "OrganizeManage", // 菜单路由 - name
  resourceType: "m", // 菜单资源 - 类型, 'm' -> 菜单, 'b' -> '按钮'
  hideChildInMenu: "N", // 隐藏子菜单资源
  hideInMenu: "N", // 隐藏当前菜单资源
  allowCache: "Y", // 启用路由缓存
  activity: "Y", // 启用菜单资源
  children: [], // 子菜单资源
};
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "查询所有菜单资源";
const url = resolver("/resource/getResourceTreeInfo");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    const resource = {
      code: "0000",
      message: null,
      result: [
        {
          title: "根目录",
          resourceId: "0",
          children: [
            {
              sort: 1000000,
              path: "",
              icon: "CodepenOutlined",
              title: "系统管理",
              redirect: "",
              parentId: "0",
              component: "PageView",
              resourceId: "27245863256459422",
              resourceName: "system",
              resourceType: "m",
              hideChildInMenu: "N",
              hideInMenu: "N",
              allowCache: "Y",
              activity: "Y",
              children: [
                {
                  sort: 1000100,
                  path: "/system/OrganizeManage",
                  icon: "CodepenOutlined",
                  title: "组织管理",
                  redirect: "",
                  parentId: "27245863256459422",
                  component: "OrganizeManage",
                  resourceId: "1127282136000102507",
                  resourceName: "OrganizeManage",
                  resourceType: "m",
                  hideChildInMenu: "N",
                  hideInMenu: "N",
                  allowCache: "Y",
                  activity: "Y",
                },
                {
                  sort: 1000200,
                  path: "/system/ResourceManage",
                  icon: "CodepenOutlined",
                  title: "资源管理",
                  redirect: "",
                  parentId: "27245863256459422",
                  component: "ResourceManage",
                  resourceId: "27245863256459445",
                  resourceName: "ResourceManage",
                  resourceType: "m",
                  hideChildInMenu: "N",
                  hideInMenu: "N",
                  allowCache: "Y",
                  activity: "Y",
                },
                {
                  sort: 1000300,
                  path: "/system/RoleManage",
                  icon: "CodepenOutlined",
                  title: "角色管理",
                  redirect: "",
                  parentId: "27245863256459422",
                  component: "RoleManage",
                  resourceId: "27245863256459495",
                  resourceName: "RoleManage",
                  resourceType: "m",
                  hideChildInMenu: "N",
                  hideInMenu: "N",
                  allowCache: "Y",
                  activity: "Y",
                },
                {
                  sort: 1000400,
                  path: "/system/UserManage",
                  icon: "CodepenOutlined",
                  title: "用户管理",
                  redirect: "",
                  parentId: "27245863256459422",
                  component: "UserManage",
                  resourceId: "1127282136000102579",
                  resourceName: "UserManage",
                  resourceType: "m",
                  hideChildInMenu: "N",
                  hideInMenu: "N",
                  allowCache: "Y",
                  activity: "Y",
                },
              ],
            },
          ],
        },
      ],
    };

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);

角色接口

分页获取角色列表 /api/role/getRoleInfoByPages
typescript
// 范例:
const result = {
  orgId: "101.100.131", // 组织 id
  roleId: "27442970747734159", // 角色 id
  roleName: "系统管理", // 角色名称
  dataFlag: "2", // 角色数据范围 (0 -> 用户级, 1 -> 部门级, 2 -> 公司级)
  activity: "Y", // 角色状态 - 启用
};
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "分页获取角色列表";
const url = resolver("/role/getRoleInfoByPages");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    const resource = {
      code: "0000",
      message: null,
      result: {
        data: [
          {
            orgId: "101.100.131",
            roleId: "27442970747734159",
            roleName: "系统管理",
            dataFlag: "2",
            activity: "Y",
          },
        ],
        pageNo: 1,
        pageSize: 20,
        totalSize: 1,
        totalPage: 1,
      },
    };

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);
获取所有角色列表 /api/role/getRoleInfoList
typescript
// 范例:
const result = {
  orgId: "101.100.131", // 组织 id
  roleId: "27442970747734159", // 角色 id
  roleName: "系统管理", // 角色名称
  dataFlag: "2", // 角色数据范围 (0 -> 用户级, 1 -> 部门级, 2 -> 公司级)
  activity: "Y", // 角色状态 - 启用
};
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "获取所有角色列表";
const url = resolver("/role/getRoleInfoList");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    const resource = {
      code: "0000",
      message: null,
      result: [
        {
          orgId: "101.100.131",
          roleId: "27442970747734159",
          roleName: "系统管理",
          dataFlag: "2",
          activity: "Y",
        },
      ],
    };

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);

用户接口

分页查询用户列表 /api/user/getUserInfoList
typescript
// 范例:
const result = {
  userNo: "lin", // 用户账号
  userName: "林某", // 用户名称
  password: "12345678", // 用户密码
  mobilePhone: "182588xxx88", // 用户手机号
  idCard: "330204198603281111", // 用户身份证
  orgId: "101.100.131", // 用户所属组织 ID
  orgName: "北仑网安通信有限公司", // 用户所属组织 Name
  deptId: "1126534161135795132", // 用户所属部门 ID
  deptName: "软件部", // 用户所属部门 Name
  roleId: ["27442970747734159"], // 用户所拥有角色组
  postName: "系统管理", // 用户职位
  activity: "Y", // 用户账号状态
};
typescript
import { promiser, resolver, worker, rester } from "@/mock/setup";
import { http, HttpResponse } from "msw";

const tag = "分页查询用户列表";
const url = resolver("/user/getUserInfoList");

worker.use(
  http.post(url, async (req) => {
    const body = await rester.body(req);
    const query = await rester.query(req);
    const params = await rester.params(req);
    const printer = await rester.printer(tag);

    const resource = {
      code: "0000",
      message: null,
      result: {
        data: [
          {
            userNo: "admin",
            userName: "admin",
            password: "12345678",
            mobilePhone: "182588xxx88",
            idCard: "330206199901011111",
            orgId: "101.100.131",
            orgName: "北仑网安通信有限公司",
            deptName: "软件部",
            deptId: "1126534161135795132",
            roleId: ["27442970747734159"],
            postName: "系统管理",
            activity: "Y",
          },
          {
            userNo: "lin",
            userName: "林某",
            password: "12345678",
            mobilePhone: "182588xxx88",
            idCard: "330204198603281111",
            orgId: "101.100.131",
            orgName: "北仑网安通信有限公司",
            deptName: "软件部",
            deptId: "1126534161135795132",
            roleId: ["27442970747734159"],
            postName: "系统管理",
            activity: "Y",
          },
        ],
        pageNo: 1,
        pageSize: 20,
        totalSize: 2,
        totalPage: 1,
      },
    };

    // 打印日志 (浏览器端)
    printer((log) => {
      log("[body] - ", body);
      log("[query] - ", query);
      log("[params] - ", params);
      log("[resource] - ", resource);
    });

    // 延时 0s, 即返回响应
    return promiser(HttpResponse.json(resource), 0);
  })
);

基于 MIT 许可发布