system.ts 5.5 KB

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