_user.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { MockRequest } from '@delon/mock';
  2. const list: any[] = [];
  3. const total = 50;
  4. for (let i = 0; i < total; i += 1) {
  5. list.push({
  6. id: i + 1,
  7. disabled: i % 6 === 0,
  8. href: 'https://ant.design',
  9. avatar: [
  10. 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
  11. 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
  12. ][i % 2],
  13. no: `TradeCode ${i}`,
  14. title: `一个任务名称 ${i}`,
  15. owner: '曲丽丽',
  16. description: '这是一段描述',
  17. callNo: Math.floor(Math.random() * 1000),
  18. status: Math.floor(Math.random() * 10) % 4,
  19. updatedAt: new Date(`2017-07-${Math.floor(i / 2) + 1}`),
  20. createdAt: new Date(`2017-07-${Math.floor(i / 2) + 1}`),
  21. progress: Math.ceil(Math.random() * 100),
  22. });
  23. }
  24. function genData(params: any) {
  25. let ret = [...list];
  26. const pi = +params.pi,
  27. ps = +params.ps,
  28. start = (pi - 1) * ps;
  29. if (params.no) {
  30. ret = ret.filter(data => data.no.indexOf(params.no) > -1);
  31. }
  32. return { total: ret.length, list: ret.slice(start, ps * pi) };
  33. }
  34. function saveData(id: number, value: any) {
  35. const item = list.find(w => w.id === id);
  36. if (!item) return { msg: '无效用户信息' };
  37. Object.assign(item, value);
  38. return { msg: 'ok' };
  39. }
  40. export const USERS = {
  41. '/user': (req: MockRequest) => genData(req.queryString),
  42. '/user/:id': (req: MockRequest) => list.find(w => w.id === +req.params.id),
  43. 'POST /user/:id': (req: MockRequest) => saveData(+req.params.id, req.body),
  44. '/user/current': {
  45. name: 'Cipchk',
  46. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
  47. userid: '00000001',
  48. email: 'cipchk@qq.com',
  49. signature: '海纳百川,有容乃大',
  50. title: '交互专家',
  51. group: '蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED',
  52. tags: [
  53. {
  54. key: '0',
  55. label: '很有想法的',
  56. },
  57. {
  58. key: '1',
  59. label: '专注撩妹',
  60. },
  61. {
  62. key: '2',
  63. label: '帅~',
  64. },
  65. {
  66. key: '3',
  67. label: '通吃',
  68. },
  69. {
  70. key: '4',
  71. label: '专职后端',
  72. },
  73. {
  74. key: '5',
  75. label: '海纳百川',
  76. },
  77. ],
  78. notifyCount: 12,
  79. country: 'China',
  80. geographic: {
  81. province: {
  82. label: '上海',
  83. key: '330000',
  84. },
  85. city: {
  86. label: '市辖区',
  87. key: '330100',
  88. },
  89. },
  90. address: 'XX区XXX路 XX 号',
  91. phone: '你猜-你猜你猜猜猜',
  92. },
  93. 'POST /user/avatar': 'ok',
  94. 'POST /login/account': (req: MockRequest) => {
  95. const data = req.body;
  96. console.log(data);
  97. // if (
  98. // !(data.userName === 'admin' || data.userName === 'user') ||
  99. // data.password !== '123456'
  100. // ) {
  101. // return { msg: `Invalid username or password(admin/123456)` };
  102. // }
  103. // return {
  104. // msg: 'ok',
  105. // user: {
  106. // token: '123456789',
  107. // name: data.userName,
  108. // email: `${data.userName}@qq.com`,
  109. // id: 10000,
  110. // time: +new Date(),
  111. // },
  112. // };
  113. },
  114. 'POST /register': {
  115. msg: 'ok',
  116. },
  117. };