system.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. import { MockMethod } from 'vite-plugin-mock';
  2. import { resultError, resultPageSuccess, resultSuccess, baseUrl } 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 userList = (() => {
  20. const result: any[] = [];
  21. for (let index = 0; index < 20; index++) {
  22. result.push({
  23. id: `${index}`,
  24. username: '@first',
  25. email: '@email',
  26. realname: '@cname()',
  27. createTime: '@datetime',
  28. remark: '@cword(10,20)',
  29. avatar: 'https://q1.qlogo.cn/g?b=qq&nk=190848757&s=640',
  30. });
  31. }
  32. return result;
  33. })();
  34. const roleList = (() => {
  35. const result: any[] = [];
  36. for (let index = 0; index < 4; index++) {
  37. result.push({
  38. id: index + 1,
  39. orderNo: `${index + 1}`,
  40. roleName: ['超级管理员', '管理员', '文章管理员', '普通用户'][index],
  41. roleValue: '@first',
  42. createTime: '@datetime',
  43. remark: '@cword(10,20)',
  44. menu: [['0', '1', '2'], ['0', '1'], ['0', '2'], ['2']][index],
  45. 'status|1': ['0', '1'],
  46. });
  47. }
  48. return result;
  49. })();
  50. const newRoleList = (() => {
  51. const result: any[] = [];
  52. for (let index = 0; index < 4; index++) {
  53. result.push({
  54. id: index + 1,
  55. orderNo: `${index + 1}`,
  56. roleName: ['超级管理员', '管理员', '文章管理员', '普通用户'][index],
  57. roleCode: '@first',
  58. createTime: '@datetime',
  59. remark: '@cword(10,20)',
  60. });
  61. }
  62. return result;
  63. })();
  64. const testList = (() => {
  65. const result: any[] = [];
  66. for (let index = 0; index < 4; index++) {
  67. result.push({
  68. id: index + 1,
  69. orderNo: `${index + 1}`,
  70. testName: ['数据1', '数据2', '数据3', '数据4'][index],
  71. testValue: '@first',
  72. createTime: '@datetime',
  73. });
  74. }
  75. return result;
  76. })();
  77. const tableDemoList = (() => {
  78. const result: any[] = [];
  79. for (let index = 0; index < 4; index++) {
  80. result.push({
  81. id: index + 1,
  82. orderCode: '2008200' + `${index + 1}`,
  83. orderMoney: '@natural(1000,3000)',
  84. ctype: '@natural(1,2)',
  85. content: '@cword(10,20)',
  86. orderDate: '@datetime',
  87. });
  88. }
  89. return result;
  90. })();
  91. const deptList = (() => {
  92. const result: any[] = [];
  93. for (let index = 0; index < 3; index++) {
  94. result.push({
  95. id: `${index}`,
  96. deptName: ['华东分部', '华南分部', '西北分部'][index],
  97. orderNo: index + 1,
  98. createTime: '@datetime',
  99. remark: '@cword(10,20)',
  100. 'status|1': ['0', '0', '1'],
  101. children: (() => {
  102. const children: any[] = [];
  103. for (let j = 0; j < 4; j++) {
  104. children.push({
  105. id: `${index}-${j}`,
  106. deptName: ['研发部', '市场部', '商务部', '财务部'][j],
  107. orderNo: j + 1,
  108. createTime: '@datetime',
  109. remark: '@cword(10,20)',
  110. 'status|1': ['0', '1'],
  111. parentDept: `${index}`,
  112. children: undefined,
  113. });
  114. }
  115. return children;
  116. })(),
  117. });
  118. }
  119. return result;
  120. })();
  121. const menuList = (() => {
  122. const result: any[] = [];
  123. for (let index = 0; index < 3; index++) {
  124. result.push({
  125. id: `${index}`,
  126. icon: ['ion:layers-outline', 'ion:git-compare-outline', 'ion:tv-outline'][index],
  127. component: 'LAYOUT',
  128. type: '0',
  129. menuName: ['Dashboard', '权限管理', '功能'][index],
  130. permission: '',
  131. orderNo: index + 1,
  132. createTime: '@datetime',
  133. 'status|1': ['0', '0', '1'],
  134. children: (() => {
  135. const children: any[] = [];
  136. for (let j = 0; j < 4; j++) {
  137. children.push({
  138. id: `${index}-${j}`,
  139. type: '1',
  140. menuName: ['菜单1', '菜单2', '菜单3', '菜单4'][j],
  141. icon: 'ion:document',
  142. permission: ['menu1:view', 'menu2:add', 'menu3:update', 'menu4:del'][index],
  143. component: ['/dashboard/welcome/index', '/dashboard/Analysis/index', '/dashboard/workbench/index', '/dashboard/test/index'][j],
  144. orderNo: j + 1,
  145. createTime: '@datetime',
  146. 'status|1': ['0', '1'],
  147. parentMenu: `${index}`,
  148. children: (() => {
  149. const children: any[] = [];
  150. for (let k = 0; k < 4; k++) {
  151. children.push({
  152. id: `${index}-${j}-${k}`,
  153. type: '2',
  154. menuName: '按钮' + (j + 1) + '-' + (k + 1),
  155. icon: '',
  156. permission: ['menu1:view', 'menu2:add', 'menu3:update', 'menu4:del'][index] + ':btn' + (k + 1),
  157. component: ['/dashboard/welcome/index', '/dashboard/Analysis/index', '/dashboard/workbench/index', '/dashboard/test/index'][j],
  158. orderNo: j + 1,
  159. createTime: '@datetime',
  160. 'status|1': ['0', '1'],
  161. parentMenu: `${index}-${j}`,
  162. children: undefined,
  163. });
  164. }
  165. return children;
  166. })(),
  167. });
  168. }
  169. return children;
  170. })(),
  171. });
  172. }
  173. return result;
  174. })();
  175. export default [
  176. {
  177. url: `${baseUrl}/system/getAccountList`,
  178. timeout: 100,
  179. method: 'get',
  180. response: ({ query }) => {
  181. const { page = 1, pageSize = 20 } = query;
  182. return resultPageSuccess(page, pageSize, accountList);
  183. },
  184. },
  185. {
  186. url: `${baseUrl}/sys/user/list`,
  187. timeout: 100,
  188. method: 'get',
  189. response: ({ query }) => {
  190. const { page = 1, pageSize = 20 } = query;
  191. return resultPageSuccess(page, pageSize, userList);
  192. },
  193. },
  194. {
  195. url: `${baseUrl}/system/getRoleListByPage`,
  196. timeout: 100,
  197. method: 'get',
  198. response: ({ query }) => {
  199. const { page = 1, pageSize = 20 } = query;
  200. return resultPageSuccess(page, pageSize, roleList);
  201. },
  202. },
  203. {
  204. url: `${baseUrl}/sys/role/list`,
  205. timeout: 100,
  206. method: 'get',
  207. response: ({ query }) => {
  208. const { page = 1, pageSize = 20 } = query;
  209. return resultPageSuccess(page, pageSize, newRoleList);
  210. },
  211. },
  212. {
  213. url: `${baseUrl}/system/getTestListByPage`,
  214. timeout: 100,
  215. method: 'get',
  216. response: ({ query }) => {
  217. const { page = 1, pageSize = 20 } = query;
  218. return resultPageSuccess(page, pageSize, testList);
  219. },
  220. },
  221. {
  222. url: `${baseUrl}/system/getDemoTableListByPage`,
  223. timeout: 100,
  224. method: 'get',
  225. response: ({ query }) => {
  226. const { page = 1, pageSize = 20 } = query;
  227. return resultPageSuccess(page, pageSize, tableDemoList);
  228. },
  229. },
  230. {
  231. url: `${baseUrl}/system/setRoleStatus`,
  232. timeout: 500,
  233. method: 'post',
  234. response: ({ query }) => {
  235. const { id, status } = query;
  236. return resultSuccess({ id, status });
  237. },
  238. },
  239. {
  240. url: `${baseUrl}/system/getAllRoleList`,
  241. timeout: 100,
  242. method: 'get',
  243. response: () => {
  244. return resultSuccess(roleList);
  245. },
  246. },
  247. {
  248. url: `${baseUrl}/system/getDeptList`,
  249. timeout: 100,
  250. method: 'get',
  251. response: () => {
  252. return resultSuccess(deptList);
  253. },
  254. },
  255. {
  256. url: `${baseUrl}/system/getMenuList`,
  257. timeout: 100,
  258. method: 'get',
  259. response: () => {
  260. return resultSuccess(menuList);
  261. },
  262. },
  263. {
  264. url: `${baseUrl}/system/accountExist`,
  265. timeout: 500,
  266. method: 'post',
  267. response: ({ body }) => {
  268. const { account } = body || {};
  269. if (account && account.indexOf('admin') !== -1) {
  270. return resultError('该字段不能包含admin');
  271. } else {
  272. return resultSuccess(`${account} can use`);
  273. }
  274. },
  275. },
  276. ] as MockMethod[];