2
0

_user.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { MockRequest } from '@delon/mock';
  17. const list: any[] = [];
  18. const total = 50;
  19. for (let i = 0; i < total; i += 1) {
  20. list.push({
  21. id: i + 1,
  22. disabled: i % 6 === 0,
  23. href: 'https://ant.design',
  24. avatar: [
  25. 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
  26. 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
  27. ][i % 2],
  28. no: `TradeCode ${i}`,
  29. title: `一个任务名称 ${i}`,
  30. owner: '曲丽丽',
  31. description: '这是一段描述',
  32. callNo: Math.floor(Math.random() * 1000),
  33. status: Math.floor(Math.random() * 10) % 4,
  34. updatedAt: new Date(`2017-07-${Math.floor(i / 2) + 1}`),
  35. createdAt: new Date(`2017-07-${Math.floor(i / 2) + 1}`),
  36. progress: Math.ceil(Math.random() * 100),
  37. });
  38. }
  39. function genData(params: any): { total: number; list: any[] } {
  40. let ret = [...list];
  41. const pi = +params.pi;
  42. const ps = +params.ps;
  43. const start = (pi - 1) * ps;
  44. if (params.no) {
  45. ret = ret.filter((data) => data.no.indexOf(params.no) > -1);
  46. }
  47. return { total: ret.length, list: ret.slice(start, ps * pi) };
  48. }
  49. function saveData(id: number, value: any): { msg: string } {
  50. const item = list.find((w) => w.id === id);
  51. if (!item) {
  52. return { msg: '无效用户信息' };
  53. }
  54. Object.assign(item, value);
  55. return { msg: 'ok' };
  56. }
  57. export const USERS = {
  58. '/user': (req: MockRequest) => genData(req.queryString),
  59. '/user/:id': (req: MockRequest) => list.find((w) => w.id === +req.params.id),
  60. 'POST /user/:id': (req: MockRequest) => saveData(+req.params.id, req.body),
  61. '/user/current': {
  62. name: 'Cipchk',
  63. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
  64. userid: '00000001',
  65. email: 'cipchk@qq.com',
  66. signature: '海纳百川,有容乃大',
  67. title: '交互专家',
  68. group: '蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED',
  69. tags: [
  70. {
  71. key: '0',
  72. label: '很有想法的',
  73. },
  74. {
  75. key: '1',
  76. label: '专注撩妹',
  77. },
  78. {
  79. key: '2',
  80. label: '帅~',
  81. },
  82. {
  83. key: '3',
  84. label: '通吃',
  85. },
  86. {
  87. key: '4',
  88. label: '专职后端',
  89. },
  90. {
  91. key: '5',
  92. label: '海纳百川',
  93. },
  94. ],
  95. notifyCount: 12,
  96. country: 'China',
  97. geographic: {
  98. province: {
  99. label: '上海',
  100. key: '330000',
  101. },
  102. city: {
  103. label: '市辖区',
  104. key: '330100',
  105. },
  106. },
  107. address: 'XX区XXX路 XX 号',
  108. phone: '你猜-你猜你猜猜猜',
  109. },
  110. 'POST /user/avatar': 'ok',
  111. 'POST /login/account': (req: MockRequest) => {
  112. const data = req.body;
  113. if (!(data.userName === 'admin' || data.userName === 'user') || data.password !== 'ng-alain.com') {
  114. return { msg: `Invalid username or password(admin/ng-alain.com)` };
  115. }
  116. return {
  117. msg: 'ok',
  118. user: {
  119. token: '123456789',
  120. name: data.userName,
  121. email: `${data.userName}@qq.com`,
  122. id: 10000,
  123. time: +new Date(),
  124. },
  125. };
  126. },
  127. 'POST /register': {
  128. msg: 'ok',
  129. },
  130. };