system.ts 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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: [
  144. '/dashboard/welcome/index',
  145. '/dashboard/Analysis/index',
  146. '/dashboard/workbench/index',
  147. '/dashboard/test/index',
  148. ][j],
  149. orderNo: j + 1,
  150. createTime: '@datetime',
  151. 'status|1': ['0', '1'],
  152. parentMenu: `${index}`,
  153. children: (() => {
  154. const children: any[] = [];
  155. for (let k = 0; k < 4; k++) {
  156. children.push({
  157. id: `${index}-${j}-${k}`,
  158. type: '2',
  159. menuName: '按钮' + (j + 1) + '-' + (k + 1),
  160. icon: '',
  161. permission:
  162. ['menu1:view', 'menu2:add', 'menu3:update', 'menu4:del'][index] +
  163. ':btn' +
  164. (k + 1),
  165. component: [
  166. '/dashboard/welcome/index',
  167. '/dashboard/Analysis/index',
  168. '/dashboard/workbench/index',
  169. '/dashboard/test/index',
  170. ][j],
  171. orderNo: j + 1,
  172. createTime: '@datetime',
  173. 'status|1': ['0', '1'],
  174. parentMenu: `${index}-${j}`,
  175. children: undefined,
  176. });
  177. }
  178. return children;
  179. })(),
  180. });
  181. }
  182. return children;
  183. })(),
  184. });
  185. }
  186. return result;
  187. })();
  188. export default [
  189. {
  190. url: `${baseUrl}/system/getAccountList`,
  191. timeout: 100,
  192. method: 'get',
  193. response: ({ query }) => {
  194. const { page = 1, pageSize = 20 } = query;
  195. return resultPageSuccess(page, pageSize, accountList);
  196. },
  197. },
  198. {
  199. url: `${baseUrl}/sys/user/list`,
  200. timeout: 100,
  201. method: 'get',
  202. response: ({ query }) => {
  203. const { page = 1, pageSize = 20 } = query;
  204. return resultPageSuccess(page, pageSize, userList);
  205. },
  206. },
  207. {
  208. url: `${baseUrl}/system/getRoleListByPage`,
  209. timeout: 100,
  210. method: 'get',
  211. response: ({ query }) => {
  212. const { page = 1, pageSize = 20 } = query;
  213. return resultPageSuccess(page, pageSize, roleList);
  214. },
  215. },
  216. {
  217. url: `${baseUrl}/sys/role/list`,
  218. timeout: 100,
  219. method: 'get',
  220. response: ({ query }) => {
  221. const { page = 1, pageSize = 20 } = query;
  222. return resultPageSuccess(page, pageSize, newRoleList);
  223. },
  224. },
  225. {
  226. url: `${baseUrl}/system/getTestListByPage`,
  227. timeout: 100,
  228. method: 'get',
  229. response: ({ query }) => {
  230. const { page = 1, pageSize = 20 } = query;
  231. return resultPageSuccess(page, pageSize, testList);
  232. },
  233. },
  234. {
  235. url: `${baseUrl}/system/getDemoTableListByPage`,
  236. timeout: 100,
  237. method: 'get',
  238. response: ({ query }) => {
  239. const { page = 1, pageSize = 20 } = query;
  240. return resultPageSuccess(page, pageSize, tableDemoList);
  241. },
  242. },
  243. {
  244. url: `${baseUrl}/system/setRoleStatus`,
  245. timeout: 500,
  246. method: 'post',
  247. response: ({ query }) => {
  248. const { id, status } = query;
  249. return resultSuccess({ id, status });
  250. },
  251. },
  252. {
  253. url: `${baseUrl}/system/getAllRoleList`,
  254. timeout: 100,
  255. method: 'get',
  256. response: () => {
  257. return resultSuccess(roleList);
  258. },
  259. },
  260. {
  261. url: `${baseUrl}/system/getDeptList`,
  262. timeout: 100,
  263. method: 'get',
  264. response: () => {
  265. return resultSuccess(deptList);
  266. },
  267. },
  268. {
  269. url: `${baseUrl}/system/getMenuList`,
  270. timeout: 100,
  271. method: 'get',
  272. response: () => {
  273. return resultSuccess(menuList);
  274. },
  275. },
  276. {
  277. url: `${baseUrl}/system/accountExist`,
  278. timeout: 500,
  279. method: 'post',
  280. response: ({ body }) => {
  281. const { account } = body || {};
  282. if (account && account.indexOf('admin') !== -1) {
  283. return resultError('该字段不能包含admin');
  284. } else {
  285. return resultSuccess(`${account} can use`);
  286. }
  287. },
  288. },
  289. ] as MockMethod[];