system.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import { MockMethod } from 'vite-plugin-mock';
  2. import { resultError, resultPageSuccess, resultSuccess } from '../_util';
  3. const accountList = (() => {
  4. const result: any[] = [];
  5. for (let index = 0; index < 20; index++) {
  6. result.push({
  7. id: `${index}`,
  8. account: '@first',
  9. email: '@email',
  10. nickname: '@cname()',
  11. role: '@first',
  12. createTime: '@datetime',
  13. remark: '@cword(10,20)',
  14. 'dept|0-2': 1,
  15. 'status|1': ['0', '1'],
  16. });
  17. }
  18. return result;
  19. })();
  20. const roleList = (() => {
  21. const result: any[] = [];
  22. for (let index = 0; index < 4; index++) {
  23. result.push({
  24. id: index + 1,
  25. orderNo: `${index + 1}`,
  26. roleName: ['超级管理员', '管理员', '文章管理员', '普通用户'][index],
  27. roleValue: '@first',
  28. createTime: '@datetime',
  29. remark: '@cword(10,20)',
  30. menu: [['0', '1', '2'], ['0', '1'], ['0', '2'], ['2']][index],
  31. 'status|1': ['0', '1'],
  32. });
  33. }
  34. return result;
  35. })();
  36. const deptList = (() => {
  37. const result: any[] = [];
  38. for (let index = 0; index < 3; index++) {
  39. result.push({
  40. id: `${index}`,
  41. deptName: ['华东分部', '华南分部', '西北分部'][index],
  42. orderNo: index + 1,
  43. createTime: '@datetime',
  44. remark: '@cword(10,20)',
  45. 'status|1': ['0', '0', '1'],
  46. children: (() => {
  47. const children: any[] = [];
  48. for (let j = 0; j < 4; j++) {
  49. children.push({
  50. id: `${index}-${j}`,
  51. deptName: ['研发部', '市场部', '商务部', '财务部'][j],
  52. orderNo: j + 1,
  53. createTime: '@datetime',
  54. remark: '@cword(10,20)',
  55. 'status|1': ['0', '1'],
  56. parentDept: `${index}`,
  57. children: undefined,
  58. });
  59. }
  60. return children;
  61. })(),
  62. });
  63. }
  64. return result;
  65. })();
  66. const menuList = (() => {
  67. const result: any[] = [];
  68. for (let index = 0; index < 3; index++) {
  69. result.push({
  70. id: `${index}`,
  71. icon: ['ion:layers-outline', 'ion:git-compare-outline', 'ion:tv-outline'][index],
  72. component: 'LAYOUT',
  73. type: '0',
  74. menuName: ['Dashboard', '权限管理', '功能'][index],
  75. permission: '',
  76. orderNo: index + 1,
  77. createTime: '@datetime',
  78. 'status|1': ['0', '0', '1'],
  79. children: (() => {
  80. const children: any[] = [];
  81. for (let j = 0; j < 4; j++) {
  82. children.push({
  83. id: `${index}-${j}`,
  84. type: '1',
  85. menuName: ['菜单1', '菜单2', '菜单3', '菜单4'][j],
  86. icon: 'ion:document',
  87. permission: ['menu1:view', 'menu2:add', 'menu3:update', 'menu4:del'][index],
  88. component: [
  89. '/dashboard/welcome/index',
  90. '/dashboard/analysis/index',
  91. '/dashboard/workbench/index',
  92. '/dashboard/test/index',
  93. ][j],
  94. orderNo: j + 1,
  95. createTime: '@datetime',
  96. 'status|1': ['0', '1'],
  97. parentMenu: `${index}`,
  98. children: (() => {
  99. const children: any[] = [];
  100. for (let k = 0; k < 4; k++) {
  101. children.push({
  102. id: `${index}-${j}-${k}`,
  103. type: '2',
  104. menuName: '按钮' + (j + 1) + '-' + (k + 1),
  105. icon: '',
  106. permission:
  107. ['menu1:view', 'menu2:add', 'menu3:update', 'menu4:del'][index] +
  108. ':btn' +
  109. (k + 1),
  110. component: [
  111. '/dashboard/welcome/index',
  112. '/dashboard/analysis/index',
  113. '/dashboard/workbench/index',
  114. '/dashboard/test/index',
  115. ][j],
  116. orderNo: j + 1,
  117. createTime: '@datetime',
  118. 'status|1': ['0', '1'],
  119. parentMenu: `${index}-${j}`,
  120. children: undefined,
  121. });
  122. }
  123. return children;
  124. })(),
  125. });
  126. }
  127. return children;
  128. })(),
  129. });
  130. }
  131. return result;
  132. })();
  133. export default [
  134. {
  135. url: '/basic-api/system/getAccountList',
  136. timeout: 100,
  137. method: 'get',
  138. response: ({ query }) => {
  139. const { page = 1, pageSize = 20 } = query;
  140. return resultPageSuccess(page, pageSize, accountList);
  141. },
  142. },
  143. {
  144. url: '/basic-api/system/getRoleListByPage',
  145. timeout: 100,
  146. method: 'get',
  147. response: ({ query }) => {
  148. const { page = 1, pageSize = 20 } = query;
  149. return resultPageSuccess(page, pageSize, roleList);
  150. },
  151. },
  152. {
  153. url: '/basic-api/system/setRoleStatus',
  154. timeout: 500,
  155. method: 'post',
  156. response: ({ query }) => {
  157. const { id, status } = query;
  158. return resultSuccess({ id, status });
  159. },
  160. },
  161. {
  162. url: '/basic-api/system/getAllRoleList',
  163. timeout: 100,
  164. method: 'get',
  165. response: () => {
  166. return resultSuccess(roleList);
  167. },
  168. },
  169. {
  170. url: '/basic-api/system/getDeptList',
  171. timeout: 100,
  172. method: 'get',
  173. response: () => {
  174. return resultSuccess(deptList);
  175. },
  176. },
  177. {
  178. url: '/basic-api/system/getMenuList',
  179. timeout: 100,
  180. method: 'get',
  181. response: () => {
  182. return resultSuccess(menuList);
  183. },
  184. },
  185. {
  186. url: '/basic-api/system/accountExist',
  187. timeout: 500,
  188. method: 'post',
  189. response: ({ body }) => {
  190. const { account } = body || {};
  191. if (account && account.indexOf('admin') !== -1) {
  192. return resultError('该字段不能包含admin');
  193. } else {
  194. return resultSuccess(`${account} can use`);
  195. }
  196. },
  197. },
  198. ] as MockMethod[];