user.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import Mock from 'mockjs';
  2. import { resultSuccess, doCustomTimes } from '../_util';
  3. const Random = Mock.Random;
  4. const token = Random.string('upper', 32, 32);
  5. //超级管理员
  6. const adminPermissions = [
  7. {
  8. label: '主控台',
  9. value: 'dashboard_console',
  10. },
  11. {
  12. label: '监控页',
  13. value: 'dashboard_monitor',
  14. },
  15. {
  16. label: '工作台',
  17. value: 'dashboard_workplace',
  18. },
  19. {
  20. label: '基础列表',
  21. value: 'basic_list',
  22. },
  23. ];
  24. //普通管理员
  25. const ordinaryPermissions = [
  26. {
  27. label: '主控台',
  28. value: 'dashboard_console',
  29. },
  30. {
  31. label: '监控页',
  32. value: 'dashboard_monitor',
  33. },
  34. {
  35. label: '工作台',
  36. value: 'dashboard_workplace',
  37. },
  38. ];
  39. const adminInfo = {
  40. userId: '1',
  41. username: 'admin',
  42. realName: 'Admin',
  43. avatar: Random.image(),
  44. desc: 'manager',
  45. password: Random.string('upper', 4, 16),
  46. token,
  47. role_type: 1, // 1 超级管理员 2 普通管理员
  48. permissions: [], // 权限集合
  49. };
  50. const userList = (pageSize) => {
  51. const result: any[] = [];
  52. doCustomTimes(pageSize, () => {
  53. result.push({
  54. id: '@integer(10,9999)',
  55. username: '@cname()',
  56. avatar: Random.image('400x400', Random.color(), Random.color(), Random.first()),
  57. account: 'M086611',
  58. mobile: `188@integer(1000,9999)9999`,
  59. email: '735@integer(1000,9999)02@qq.com',
  60. 'gender|1': [1, 2],
  61. 'status|1': ['normal', 'disable'],
  62. 'role|1': ['普通用户', '推广管理员', '发货管理员', '财务管理员'],
  63. create_date: `@date('yyyy-MM-dd hh:mm:ss')`,
  64. });
  65. });
  66. return result;
  67. };
  68. export default [
  69. {
  70. url: '/api/login',
  71. timeout: 1000,
  72. method: 'post',
  73. response: () => {
  74. return resultSuccess({ token });
  75. },
  76. },
  77. {
  78. url: '/api/admin_info',
  79. timeout: 1000,
  80. method: 'get',
  81. response: () => {
  82. // const token = getRequestToken(request);
  83. // if (!token) return resultError('Invalid token');
  84. //此处随机了,为了模拟不同角色权限
  85. //const randomNum = Math.floor(Math.random() * 2 + 1);
  86. const randomNum = 1;
  87. adminInfo.permissions = (randomNum === 1 ? adminPermissions : ordinaryPermissions) as never[];
  88. adminInfo.role_type = randomNum;
  89. return resultSuccess(adminInfo);
  90. },
  91. },
  92. {
  93. url: '/api/user_list',
  94. timeout: 1000,
  95. method: 'get',
  96. response: ({ query }) => {
  97. const { page = 1, pageSize = 10 } = query;
  98. const list = userList(Number(pageSize));
  99. return resultSuccess({
  100. page: Number(page),
  101. pageSize: Number(pageSize),
  102. pageCount: 60,
  103. itemCount: 60 * Number(pageSize),
  104. list,
  105. });
  106. },
  107. },
  108. ];