role.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-08-02 18:11:13
  4. * @LastEditTime: 2021-08-13 10:20:57
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: /CostAccountManaSys/mock/role.js
  8. */
  9. // eslint-disable-next-line import/no-extraneous-dependencies
  10. import moment from 'moment';
  11. import { parse } from 'url'; // mock tableListDataSource
  12. const genList = (current, pageSize) => {
  13. const tableListDataSource = [];
  14. for (let i = 0; i < pageSize; i += 1) {
  15. const index = (current - 1) * 10 + i;
  16. tableListDataSource.push({
  17. key: index,
  18. roleId: index,
  19. roleName: `角色${i}`,
  20. hospName: `院区${i}`,
  21. modifyUserName: `变更人 ${index}`,
  22. users: [
  23. {
  24. id: 93,
  25. name: '用户93',
  26. },
  27. {
  28. id: 92,
  29. name: '用户92',
  30. },
  31. ],
  32. menus: [],
  33. modifyTime: moment().format('YYYY-MM-DD'),
  34. });
  35. }
  36. // console.log({tableListDataSource});
  37. tableListDataSource.reverse();
  38. return tableListDataSource;
  39. };
  40. let tableListDataSource = genList(1, 100);
  41. function getList(req, res, u) {
  42. let realUrl = u;
  43. if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') {
  44. realUrl = req.url;
  45. }
  46. const { current = 1, pageSize = 10 } = req.query;
  47. let dataSource = [...tableListDataSource].slice((current - 1) * pageSize, current * pageSize);
  48. const result = {
  49. data: {
  50. list: dataSource,
  51. totalCount: tableListDataSource.length,
  52. pageSize: pageSize,
  53. },
  54. status: 200,
  55. success: true,
  56. };
  57. return res.json(result);
  58. }
  59. function postList(req, res, u, b) {
  60. let realUrl = u;
  61. if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') {
  62. realUrl = req.url;
  63. }
  64. const { method, body } = req;
  65. tableListDataSource.push({ ...body });
  66. const result = {
  67. status: 200,
  68. msg: '',
  69. };
  70. res.json(result);
  71. }
  72. function delList(req, res, u, b) {
  73. const { method, body } = req;
  74. tableListDataSource = tableListDataSource.filter((item) => !body.includes(item.roleId));
  75. const result = {
  76. status: 200,
  77. msg: '',
  78. };
  79. res.json(result);
  80. }
  81. function getHasBindUserList(req, res, u, b){
  82. const data = [
  83. {
  84. id:98,name:'用户98'
  85. },
  86. {
  87. id:92,name:'用户92'
  88. }
  89. ]
  90. const result = {
  91. status: 200,
  92. msg: '',
  93. data:data
  94. };
  95. res.json(result);
  96. }
  97. function getHasBindMenuList(req, res, u, b){
  98. const data = [
  99. {
  100. id:98,name:'菜单98'
  101. },
  102. {
  103. id:92,name:'菜单92'
  104. }
  105. ]
  106. const result = {
  107. status: 200,
  108. msg: '',
  109. data:data
  110. };
  111. res.json(result);
  112. }
  113. function bindList(req, res, u, b) {
  114. const { method, body } = req;
  115. const { roleId, userIds } = body;
  116. const result = {
  117. status: 200,
  118. msg: '',
  119. };
  120. res.json(result);
  121. }
  122. export default {
  123. 'GET /api/costAccount/role/list': getList,
  124. 'GET /api/costAccount/role/roleUsers': getHasBindUserList,
  125. 'GET /api/costAccount/role/roleMenus': getHasBindMenuList,
  126. 'POST /api/costAccount/role/save': postList,
  127. 'POST /api/costAccount/role/delete': delList,
  128. 'POST /api/costAccount/role/editUserRole': bindList,
  129. };