api.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. import { parse } from 'url';
  2. const titles = [
  3. 'Alipay',
  4. 'Angular',
  5. 'Ant Design',
  6. 'Ant Design Pro',
  7. 'Bootstrap',
  8. 'React',
  9. 'Vue',
  10. 'Webpack',
  11. ];
  12. const avatars = [
  13. 'https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png', // Alipay
  14. 'https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png', // Angular
  15. 'https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png', // Ant Design
  16. 'https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png', // Ant Design Pro
  17. 'https://gw.alipayobjects.com/zos/rmsportal/siCrBXXhmvTQGWPNLBow.png', // Bootstrap
  18. 'https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png', // React
  19. 'https://gw.alipayobjects.com/zos/rmsportal/ComBAopevLwENQdKWiIn.png', // Vue
  20. 'https://gw.alipayobjects.com/zos/rmsportal/nxkuOJlFJuAUhzlMTCEe.png', // Webpack
  21. ];
  22. const avatars2 = [
  23. 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
  24. 'https://gw.alipayobjects.com/zos/rmsportal/cnrhVkzwxjPwAaCfPbdc.png',
  25. 'https://gw.alipayobjects.com/zos/rmsportal/gaOngJwsRYRaVAuXXcmB.png',
  26. 'https://gw.alipayobjects.com/zos/rmsportal/ubnKSIfAJTxIgXOKlciN.png',
  27. 'https://gw.alipayobjects.com/zos/rmsportal/WhxKECPNujWoWEFNdnJE.png',
  28. 'https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png',
  29. 'https://gw.alipayobjects.com/zos/rmsportal/psOgztMplJMGpVEqfcgF.png',
  30. 'https://gw.alipayobjects.com/zos/rmsportal/ZpBqSxLxVEXfcUNoPKrz.png',
  31. 'https://gw.alipayobjects.com/zos/rmsportal/laiEnJdGHVOhJrUShBaJ.png',
  32. 'https://gw.alipayobjects.com/zos/rmsportal/UrQsqscbKEpNuJcvBZBu.png',
  33. ];
  34. const covers = [
  35. 'https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png',
  36. 'https://gw.alipayobjects.com/zos/rmsportal/iZBVOIhGJiAnhplqjvZW.png',
  37. 'https://gw.alipayobjects.com/zos/rmsportal/iXjVmWVHbCJAyqvDxdtx.png',
  38. 'https://gw.alipayobjects.com/zos/rmsportal/gLaIAoVWTtLbBWZNYEMg.png',
  39. ];
  40. const desc = [
  41. '那是一种内在的东西, 他们到达不了,也无法触及的',
  42. '希望是一个好东西,也许是最好的,好东西是不会消亡的',
  43. '生命就像一盒巧克力,结果往往出人意料',
  44. '城镇中有那么多的酒馆,她却偏偏走进了我的酒馆',
  45. '那时候我只会想自己想要什么,从不想自己拥有什么',
  46. ];
  47. const user = [
  48. '付小小',
  49. '曲丽丽',
  50. '林东东',
  51. '周星星',
  52. '吴加好',
  53. '朱偏右',
  54. '鱼酱',
  55. '乐哥',
  56. '谭小仪',
  57. '仲尼',
  58. ];
  59. export function fakeList(count) {
  60. const list = [];
  61. for (let i = 0; i < count; i += 1) {
  62. list.push({
  63. id: `fake-list-${i}`,
  64. owner: user[i % 10],
  65. title: titles[i % 8],
  66. avatar: avatars[i % 8],
  67. cover: parseInt(i / 4, 10) % 2 === 0 ? covers[i % 4] : covers[3 - (i % 4)],
  68. status: ['active', 'exception', 'normal'][i % 3],
  69. percent: Math.ceil(Math.random() * 50) + 50,
  70. logo: avatars[i % 8],
  71. href: 'https://ant.design',
  72. updatedAt: new Date(new Date().getTime() - (1000 * 60 * 60 * 2 * i)),
  73. createdAt: new Date(new Date().getTime() - (1000 * 60 * 60 * 2 * i)),
  74. subDescription: desc[i % 5],
  75. description: '在中台产品的研发过程中,会出现不同的设计规范和实现方式,但其中往往存在很多类似的页面和组件,这些类似的组件会被抽离成一套标准规范。',
  76. activeUser: Math.ceil(Math.random() * 100000) + 100000,
  77. newUser: Math.ceil(Math.random() * 1000) + 1000,
  78. star: Math.ceil(Math.random() * 100) + 100,
  79. like: Math.ceil(Math.random() * 100) + 100,
  80. message: Math.ceil(Math.random() * 10) + 10,
  81. content: '段落示意:蚂蚁金服设计平台 ant.design,用最小的工作量,无缝接入蚂蚁金服生态,提供跨越设计与开发的体验解决方案。蚂蚁金服设计平台 ant.design,用最小的工作量,无缝接入蚂蚁金服生态,提供跨越设计与开发的体验解决方案。',
  82. members: [
  83. {
  84. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ZiESqWwCXBRQoaPONSJe.png',
  85. name: '曲丽丽',
  86. id: 'member1',
  87. },
  88. {
  89. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/tBOxZPlITHqwlGjsJWaF.png',
  90. name: '王昭君',
  91. id: 'member2',
  92. },
  93. {
  94. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/sBxjgqiuHMGRkIjqlQCd.png',
  95. name: '董娜娜',
  96. id: 'member3',
  97. },
  98. ],
  99. });
  100. }
  101. return list;
  102. }
  103. let sourceData;
  104. export function getFakeList(req, res, u) {
  105. let url = u;
  106. if (!url || Object.prototype.toString.call(url) !== '[object String]') {
  107. url = req.url; // eslint-disable-line
  108. }
  109. const params = parse(url, true).query;
  110. const count = (params.count * 1) || 20;
  111. const result = fakeList(count);
  112. sourceData = result;
  113. if (res && res.json) {
  114. res.json(result);
  115. } else {
  116. return result;
  117. }
  118. }
  119. export function postFakeList(req, res) {
  120. const { /* url = '', */ body } = req;
  121. // const params = getUrlParams(url);
  122. const { method, id, ...restParams } = body;
  123. // const count = (params.count * 1) || 20;
  124. let result = sourceData;
  125. switch (method) {
  126. case 'delete':
  127. result = result.filter(item => item.id !== id);
  128. break;
  129. case 'update':
  130. result.forEach((item, i) => {
  131. if (item.id === id) {
  132. result[i] = Object.assign(item, restParams);
  133. }
  134. });
  135. break;
  136. case 'post':
  137. result.unshift({
  138. ...restParams,
  139. id: `fake-list-${result.length}`,
  140. createdAt: new Date().getTime(),
  141. });
  142. break;
  143. default:
  144. break;
  145. }
  146. if (res && res.json) {
  147. res.json(result);
  148. } else {
  149. return result;
  150. }
  151. }
  152. export const getNotice = [
  153. {
  154. id: 'xxx1',
  155. title: titles[0],
  156. logo: avatars[0],
  157. description: '那是一种内在的东西,他们到达不了,也无法触及的',
  158. updatedAt: new Date(),
  159. member: '科学搬砖组',
  160. href: '',
  161. memberLink: '',
  162. },
  163. {
  164. id: 'xxx2',
  165. title: titles[1],
  166. logo: avatars[1],
  167. description: '希望是一个好东西,也许是最好的,好东西是不会消亡的',
  168. updatedAt: new Date('2017-07-24'),
  169. member: '全组都是吴彦祖',
  170. href: '',
  171. memberLink: '',
  172. },
  173. {
  174. id: 'xxx3',
  175. title: titles[2],
  176. logo: avatars[2],
  177. description: '城镇中有那么多的酒馆,她却偏偏走进了我的酒馆',
  178. updatedAt: new Date(),
  179. member: '中二少女团',
  180. href: '',
  181. memberLink: '',
  182. },
  183. {
  184. id: 'xxx4',
  185. title: titles[3],
  186. logo: avatars[3],
  187. description: '那时候我只会想自己想要什么,从不想自己拥有什么',
  188. updatedAt: new Date('2017-07-23'),
  189. member: '程序员日常',
  190. href: '',
  191. memberLink: '',
  192. },
  193. {
  194. id: 'xxx5',
  195. title: titles[4],
  196. logo: avatars[4],
  197. description: '凛冬将至',
  198. updatedAt: new Date('2017-07-23'),
  199. member: '高逼格设计天团',
  200. href: '',
  201. memberLink: '',
  202. },
  203. {
  204. id: 'xxx6',
  205. title: titles[5],
  206. logo: avatars[5],
  207. description: '生命就像一盒巧克力,结果往往出人意料',
  208. updatedAt: new Date('2017-07-23'),
  209. member: '骗你来学计算机',
  210. href: '',
  211. memberLink: '',
  212. },
  213. ];
  214. export const getActivities = [
  215. {
  216. id: 'trend-1',
  217. updatedAt: new Date(),
  218. user: {
  219. name: '曲丽丽',
  220. avatar: avatars2[0],
  221. },
  222. group: {
  223. name: '高逼格设计天团',
  224. link: 'http://github.com/',
  225. },
  226. project: {
  227. name: '六月迭代',
  228. link: 'http://github.com/',
  229. },
  230. template: '在 @{group} 新建项目 @{project}',
  231. },
  232. {
  233. id: 'trend-2',
  234. updatedAt: new Date(),
  235. user: {
  236. name: '付小小',
  237. avatar: avatars2[1],
  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. id: 'trend-3',
  251. updatedAt: new Date(),
  252. user: {
  253. name: '林东东',
  254. avatar: avatars2[2],
  255. },
  256. group: {
  257. name: '中二少女团',
  258. link: 'http://github.com/',
  259. },
  260. project: {
  261. name: '六月迭代',
  262. link: 'http://github.com/',
  263. },
  264. template: '在 @{group} 新建项目 @{project}',
  265. },
  266. {
  267. id: 'trend-4',
  268. updatedAt: new Date(),
  269. user: {
  270. name: '周星星',
  271. avatar: avatars2[4],
  272. },
  273. project: {
  274. name: '5 月日常迭代',
  275. link: 'http://github.com/',
  276. },
  277. template: '将 @{project} 更新至已发布状态',
  278. },
  279. {
  280. id: 'trend-5',
  281. updatedAt: new Date(),
  282. user: {
  283. name: '朱偏右',
  284. avatar: avatars2[3],
  285. },
  286. project: {
  287. name: '工程效能',
  288. link: 'http://github.com/',
  289. },
  290. comment: {
  291. name: '留言',
  292. link: 'http://github.com/',
  293. },
  294. template: '在 @{project} 发布了 @{comment}',
  295. },
  296. {
  297. id: 'trend-6',
  298. updatedAt: new Date(),
  299. user: {
  300. name: '乐哥',
  301. avatar: avatars2[5],
  302. },
  303. group: {
  304. name: '程序员日常',
  305. link: 'http://github.com/',
  306. },
  307. project: {
  308. name: '品牌迭代',
  309. link: 'http://github.com/',
  310. },
  311. template: '在 @{group} 新建项目 @{project}',
  312. },
  313. ];
  314. export default {
  315. getNotice,
  316. getActivities,
  317. getFakeList,
  318. postFakeList,
  319. };