api.js 9.1 KB

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