2
0

_api.ts 8.6 KB

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