/* * @Author: your name * @Date: 2021-08-02 18:11:13 * @LastEditTime: 2021-08-13 10:20:57 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: /CostAccountManaSys/mock/role.js */ // eslint-disable-next-line import/no-extraneous-dependencies import moment from 'moment'; import { parse } from 'url'; // mock tableListDataSource const genList = (current, pageSize) => { const tableListDataSource = []; for (let i = 0; i < pageSize; i += 1) { const index = (current - 1) * 10 + i; tableListDataSource.push({ key: index, roleId: index, roleName: `角色${i}`, hospName: `院区${i}`, modifyUserName: `变更人 ${index}`, users: [ { id: 93, name: '用户93', }, { id: 92, name: '用户92', }, ], menus: [], modifyTime: moment().format('YYYY-MM-DD'), }); } // console.log({tableListDataSource}); tableListDataSource.reverse(); return tableListDataSource; }; let tableListDataSource = genList(1, 100); function getList(req, res, u) { let realUrl = u; if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') { realUrl = req.url; } const { current = 1, pageSize = 10 } = req.query; let dataSource = [...tableListDataSource].slice((current - 1) * pageSize, current * pageSize); const result = { data: { list: dataSource, totalCount: tableListDataSource.length, pageSize: pageSize, }, status: 200, success: true, }; return res.json(result); } function postList(req, res, u, b) { let realUrl = u; if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') { realUrl = req.url; } const { method, body } = req; tableListDataSource.push({ ...body }); const result = { status: 200, msg: '', }; res.json(result); } function delList(req, res, u, b) { const { method, body } = req; tableListDataSource = tableListDataSource.filter((item) => !body.includes(item.roleId)); const result = { status: 200, msg: '', }; res.json(result); } function getHasBindUserList(req, res, u, b){ const data = [ { id:98,name:'用户98' }, { id:92,name:'用户92' } ] const result = { status: 200, msg: '', data:data }; res.json(result); } function getHasBindMenuList(req, res, u, b){ const data = [ { id:98,name:'菜单98' }, { id:92,name:'菜单92' } ] const result = { status: 200, msg: '', data:data }; res.json(result); } function bindList(req, res, u, b) { const { method, body } = req; const { roleId, userIds } = body; const result = { status: 200, msg: '', }; res.json(result); } export default { 'GET /api/costAccount/role/list': getList, 'GET /api/costAccount/role/roleUsers': getHasBindUserList, 'GET /api/costAccount/role/roleMenus': getHasBindMenuList, 'POST /api/costAccount/role/save': postList, 'POST /api/costAccount/role/delete': delList, 'POST /api/costAccount/role/editUserRole': bindList, };