system.ts 5.6 KB

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