_api.ts 8.0 KB

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