_api.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import { MockRequest, MockStatusError } from '@delon/mock';
  2. // region: mock data
  3. const titles = ['Alipay', 'Angular', 'Ant Design', 'Ant Design Pro', 'Bootstrap', 'React', 'Vue', 'Webpack'];
  4. const avatars = [
  5. 'https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png', // Alipay
  6. 'https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png', // Angular
  7. 'https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png', // Ant Design
  8. 'https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png', // Ant Design Pro
  9. 'https://gw.alipayobjects.com/zos/rmsportal/siCrBXXhmvTQGWPNLBow.png', // Bootstrap
  10. 'https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png', // React
  11. 'https://gw.alipayobjects.com/zos/rmsportal/ComBAopevLwENQdKWiIn.png', // Vue
  12. 'https://gw.alipayobjects.com/zos/rmsportal/nxkuOJlFJuAUhzlMTCEe.png', // Webpack
  13. ];
  14. const covers = [
  15. 'https://gw.alipayobjects.com/zos/rmsportal/HrxcVbrKnCJOZvtzSqjN.png',
  16. 'https://gw.alipayobjects.com/zos/rmsportal/alaPpKWajEbIYEUvvVNf.png',
  17. 'https://gw.alipayobjects.com/zos/rmsportal/RLwlKSYGSXGHuWSojyvp.png',
  18. 'https://gw.alipayobjects.com/zos/rmsportal/gLaIAoVWTtLbBWZNYEMg.png',
  19. ];
  20. const desc = [
  21. '那是一种内在的东西, 他们到达不了,也无法触及的',
  22. '希望是一个好东西,也许是最好的,好东西是不会消亡的',
  23. '生命就像一盒巧克力,结果往往出人意料',
  24. '城镇中有那么多的酒馆,她却偏偏走进了我的酒馆',
  25. '那时候我只会想自己想要什么,从不想自己拥有什么',
  26. ];
  27. const user = ['卡色', 'cipchk', '付小小', '曲丽丽', '林东东', '周星星', '吴加好', '朱偏右', '鱼酱', '乐哥', '谭小仪', '仲尼'];
  28. // endregion
  29. function getFakeList(count: number = 20): any[] {
  30. const list: any[] = [];
  31. for (let i = 0; i < count; i += 1) {
  32. list.push({
  33. id: `fake-list-${i}`,
  34. owner: user[i % 10],
  35. title: titles[i % 8],
  36. avatar: avatars[i % 8],
  37. cover: parseInt((i / 4).toString(), 10) % 2 === 0 ? covers[i % 4] : covers[3 - (i % 4)],
  38. status: ['active', 'exception', 'normal'][i % 3],
  39. percent: Math.ceil(Math.random() * 50) + 50,
  40. logo: avatars[i % 8],
  41. href: 'https://ant.design',
  42. updatedAt: new Date(new Date().getTime() - 1000 * 60 * 60 * 2 * i),
  43. createdAt: new Date(new Date().getTime() - 1000 * 60 * 60 * 2 * i),
  44. subDescription: desc[i % 5],
  45. description:
  46. '在中台产品的研发过程中,会出现不同的设计规范和实现方式,但其中往往存在很多类似的页面和组件,这些类似的组件会被抽离成一套标准规范。',
  47. activeUser: Math.ceil(Math.random() * 100000) + 100000,
  48. newUser: Math.ceil(Math.random() * 1000) + 1000,
  49. star: Math.ceil(Math.random() * 100) + 100,
  50. like: Math.ceil(Math.random() * 100) + 100,
  51. message: Math.ceil(Math.random() * 10) + 10,
  52. content:
  53. '段落示意:蚂蚁金服设计平台 ant.design,用最小的工作量,无缝接入蚂蚁金服生态,提供跨越设计与开发的体验解决方案。蚂蚁金服设计平台 ant.design,用最小的工作量,无缝接入蚂蚁金服生态,提供跨越设计与开发的体验解决方案。',
  54. members: [
  55. {
  56. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ZiESqWwCXBRQoaPONSJe.png',
  57. name: '曲丽丽',
  58. },
  59. {
  60. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/tBOxZPlITHqwlGjsJWaF.png',
  61. name: '王昭君',
  62. },
  63. {
  64. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/sBxjgqiuHMGRkIjqlQCd.png',
  65. name: '董娜娜',
  66. },
  67. ],
  68. });
  69. }
  70. return list;
  71. }
  72. function getNotice(): any[] {
  73. return [
  74. {
  75. id: 'xxx1',
  76. title: titles[0],
  77. logo: avatars[0],
  78. description: '那是一种内在的东西, 他们到达不了,也无法触及的',
  79. updatedAt: new Date(),
  80. member: '科学搬砖组',
  81. href: '',
  82. memberLink: '',
  83. },
  84. {
  85. id: 'xxx2',
  86. title: titles[1],
  87. logo: avatars[1],
  88. description: '希望是一个好东西,也许是最好的,好东西是不会消亡的',
  89. updatedAt: new Date('2017-07-24'),
  90. member: '全组都是吴彦祖',
  91. href: '',
  92. memberLink: '',
  93. },
  94. {
  95. id: 'xxx3',
  96. title: titles[2],
  97. logo: avatars[2],
  98. description: '城镇中有那么多的酒馆,她却偏偏走进了我的酒馆',
  99. updatedAt: new Date(),
  100. member: '中二少女团',
  101. href: '',
  102. memberLink: '',
  103. },
  104. {
  105. id: 'xxx4',
  106. title: titles[3],
  107. logo: avatars[3],
  108. description: '那时候我只会想自己想要什么,从不想自己拥有什么',
  109. updatedAt: new Date('2017-07-23'),
  110. member: '程序员日常',
  111. href: '',
  112. memberLink: '',
  113. },
  114. {
  115. id: 'xxx5',
  116. title: titles[4],
  117. logo: avatars[4],
  118. description: '凛冬将至',
  119. updatedAt: new Date('2017-07-23'),
  120. member: '高逼格设计天团',
  121. href: '',
  122. memberLink: '',
  123. },
  124. {
  125. id: 'xxx6',
  126. title: titles[5],
  127. logo: avatars[5],
  128. description: '生命就像一盒巧克力,结果往往出人意料',
  129. updatedAt: new Date('2017-07-23'),
  130. member: '骗你来学计算机',
  131. href: '',
  132. memberLink: '',
  133. },
  134. ];
  135. }
  136. function getActivities(): any[] {
  137. return [
  138. {
  139. id: 'trend-1',
  140. updatedAt: new Date(),
  141. user: {
  142. name: '林东东',
  143. avatar: avatars[0],
  144. },
  145. group: {
  146. name: '高逼格设计天团',
  147. link: 'http://github.com/',
  148. },
  149. project: {
  150. name: '六月迭代',
  151. link: 'http://github.com/',
  152. },
  153. template: '在 @{group} 新建项目 @{project}',
  154. },
  155. {
  156. id: 'trend-2',
  157. updatedAt: new Date(),
  158. user: {
  159. name: '付小小',
  160. avatar: avatars[1],
  161. },
  162. group: {
  163. name: '高逼格设计天团',
  164. link: 'http://github.com/',
  165. },
  166. project: {
  167. name: '六月迭代',
  168. link: 'http://github.com/',
  169. },
  170. template: '在 @{group} 新建项目 @{project}',
  171. },
  172. {
  173. id: 'trend-3',
  174. updatedAt: new Date(),
  175. user: {
  176. name: '曲丽丽',
  177. avatar: avatars[2],
  178. },
  179. group: {
  180. name: '中二少女团',
  181. link: 'http://github.com/',
  182. },
  183. project: {
  184. name: '六月迭代',
  185. link: 'http://github.com/',
  186. },
  187. template: '在 @{group} 新建项目 @{project}',
  188. },
  189. {
  190. id: 'trend-4',
  191. updatedAt: new Date(),
  192. user: {
  193. name: '周星星',
  194. avatar: avatars[3],
  195. },
  196. project: {
  197. name: '5 月日常迭代',
  198. link: 'http://github.com/',
  199. },
  200. template: '将 @{project} 更新至已发布状态',
  201. },
  202. {
  203. id: 'trend-5',
  204. updatedAt: new Date(),
  205. user: {
  206. name: '朱偏右',
  207. avatar: avatars[4],
  208. },
  209. project: {
  210. name: '工程效能',
  211. link: 'http://github.com/',
  212. },
  213. comment: {
  214. name: '留言',
  215. link: 'http://github.com/',
  216. },
  217. template: '在 @{project} 发布了 @{comment}',
  218. },
  219. {
  220. id: 'trend-6',
  221. updatedAt: new Date(),
  222. user: {
  223. name: '乐哥',
  224. avatar: avatars[5],
  225. },
  226. group: {
  227. name: '程序员日常',
  228. link: 'http://github.com/',
  229. },
  230. project: {
  231. name: '品牌迭代',
  232. link: 'http://github.com/',
  233. },
  234. template: '在 @{group} 新建项目 @{project}',
  235. },
  236. ];
  237. }
  238. export const APIS = {
  239. '/api/list': (req: MockRequest) => getFakeList(req.queryString.count),
  240. '/api/notice': () => getNotice(),
  241. '/api/activities': () => getActivities(),
  242. 'POST /api/auth/refresh': { msg: 'ok', token: 'new-token-by-refresh' },
  243. '/api/401': () => {
  244. throw new MockStatusError(401);
  245. },
  246. '/api/403': () => {
  247. throw new MockStatusError(403);
  248. },
  249. '/api/404': () => {
  250. throw new MockStatusError(404);
  251. },
  252. '/api/500': () => {
  253. throw new MockStatusError(500);
  254. },
  255. };