api.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. import mockjs from 'mockjs';
  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. 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. '在中台产品的研发过程中,会出现不同的设计规范和实现方式,但其中往往存在很多类似的页面和组件,这些类似的组件会被抽离成一套标准规范。',
  77. activeUser: Math.ceil(Math.random() * 100000) + 100000,
  78. newUser: Math.ceil(Math.random() * 1000) + 1000,
  79. star: Math.ceil(Math.random() * 100) + 100,
  80. like: Math.ceil(Math.random() * 100) + 100,
  81. message: Math.ceil(Math.random() * 10) + 10,
  82. content:
  83. '段落示意:蚂蚁金服设计平台 ant.design,用最小的工作量,无缝接入蚂蚁金服生态,提供跨越设计与开发的体验解决方案。蚂蚁金服设计平台 ant.design,用最小的工作量,无缝接入蚂蚁金服生态,提供跨越设计与开发的体验解决方案。',
  84. members: [
  85. {
  86. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ZiESqWwCXBRQoaPONSJe.png',
  87. name: '曲丽丽',
  88. id: 'member1',
  89. },
  90. {
  91. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/tBOxZPlITHqwlGjsJWaF.png',
  92. name: '王昭君',
  93. id: 'member2',
  94. },
  95. {
  96. avatar: 'https://gw.alipayobjects.com/zos/rmsportal/sBxjgqiuHMGRkIjqlQCd.png',
  97. name: '董娜娜',
  98. id: 'member3',
  99. },
  100. ],
  101. });
  102. }
  103. return list;
  104. }
  105. let sourceData;
  106. function getFakeList(req, res) {
  107. const params = req.query;
  108. const count = params.count * 1 || 20;
  109. const result = fakeList(count);
  110. sourceData = result;
  111. if (res && res.json) {
  112. res.json(result);
  113. } else {
  114. return result;
  115. }
  116. }
  117. function postFakeList(req, res) {
  118. const { /* url = '', */ body } = req;
  119. // const params = getUrlParams(url);
  120. const { method, id } = body;
  121. // const count = (params.count * 1) || 20;
  122. let result = sourceData;
  123. switch (method) {
  124. case 'delete':
  125. result = result.filter(item => item.id !== id);
  126. break;
  127. case 'update':
  128. result.forEach((item, i) => {
  129. if (item.id === id) {
  130. result[i] = Object.assign(item, body);
  131. }
  132. });
  133. break;
  134. case 'post':
  135. result.unshift({
  136. body,
  137. id: `fake-list-${result.length}`,
  138. createdAt: new Date().getTime(),
  139. });
  140. break;
  141. default:
  142. break;
  143. }
  144. if (res && res.json) {
  145. res.json(result);
  146. } else {
  147. return result;
  148. }
  149. }
  150. const getNotice = [
  151. {
  152. id: 'xxx1',
  153. title: titles[0],
  154. logo: avatars[0],
  155. description: '那是一种内在的东西,他们到达不了,也无法触及的',
  156. updatedAt: new Date(),
  157. member: '科学搬砖组',
  158. href: '',
  159. memberLink: '',
  160. },
  161. {
  162. id: 'xxx2',
  163. title: titles[1],
  164. logo: avatars[1],
  165. description: '希望是一个好东西,也许是最好的,好东西是不会消亡的',
  166. updatedAt: new Date('2017-07-24'),
  167. member: '全组都是吴彦祖',
  168. href: '',
  169. memberLink: '',
  170. },
  171. {
  172. id: 'xxx3',
  173. title: titles[2],
  174. logo: avatars[2],
  175. description: '城镇中有那么多的酒馆,她却偏偏走进了我的酒馆',
  176. updatedAt: new Date(),
  177. member: '中二少女团',
  178. href: '',
  179. memberLink: '',
  180. },
  181. {
  182. id: 'xxx4',
  183. title: titles[3],
  184. logo: avatars[3],
  185. description: '那时候我只会想自己想要什么,从不想自己拥有什么',
  186. updatedAt: new Date('2017-07-23'),
  187. member: '程序员日常',
  188. href: '',
  189. memberLink: '',
  190. },
  191. {
  192. id: 'xxx5',
  193. title: titles[4],
  194. logo: avatars[4],
  195. description: '凛冬将至',
  196. updatedAt: new Date('2017-07-23'),
  197. member: '高逼格设计天团',
  198. href: '',
  199. memberLink: '',
  200. },
  201. {
  202. id: 'xxx6',
  203. title: titles[5],
  204. logo: avatars[5],
  205. description: '生命就像一盒巧克力,结果往往出人意料',
  206. updatedAt: new Date('2017-07-23'),
  207. member: '骗你来学计算机',
  208. href: '',
  209. memberLink: '',
  210. },
  211. ];
  212. const getActivities = [
  213. {
  214. id: 'trend-1',
  215. updatedAt: new Date(),
  216. user: {
  217. name: '曲丽丽',
  218. avatar: avatars2[0],
  219. },
  220. group: {
  221. name: '高逼格设计天团',
  222. link: 'http://github.com/',
  223. },
  224. project: {
  225. name: '六月迭代',
  226. link: 'http://github.com/',
  227. },
  228. template: '在 @{group} 新建项目 @{project}',
  229. },
  230. {
  231. id: 'trend-2',
  232. updatedAt: new Date(),
  233. user: {
  234. name: '付小小',
  235. avatar: avatars2[1],
  236. },
  237. group: {
  238. name: '高逼格设计天团',
  239. link: 'http://github.com/',
  240. },
  241. project: {
  242. name: '六月迭代',
  243. link: 'http://github.com/',
  244. },
  245. template: '在 @{group} 新建项目 @{project}',
  246. },
  247. {
  248. id: 'trend-3',
  249. updatedAt: new Date(),
  250. user: {
  251. name: '林东东',
  252. avatar: avatars2[2],
  253. },
  254. group: {
  255. name: '中二少女团',
  256. link: 'http://github.com/',
  257. },
  258. project: {
  259. name: '六月迭代',
  260. link: 'http://github.com/',
  261. },
  262. template: '在 @{group} 新建项目 @{project}',
  263. },
  264. {
  265. id: 'trend-4',
  266. updatedAt: new Date(),
  267. user: {
  268. name: '周星星',
  269. avatar: avatars2[4],
  270. },
  271. project: {
  272. name: '5 月日常迭代',
  273. link: 'http://github.com/',
  274. },
  275. template: '将 @{project} 更新至已发布状态',
  276. },
  277. {
  278. id: 'trend-5',
  279. updatedAt: new Date(),
  280. user: {
  281. name: '朱偏右',
  282. avatar: avatars2[3],
  283. },
  284. project: {
  285. name: '工程效能',
  286. link: 'http://github.com/',
  287. },
  288. comment: {
  289. name: '留言',
  290. link: 'http://github.com/',
  291. },
  292. template: '在 @{project} 发布了 @{comment}',
  293. },
  294. {
  295. id: 'trend-6',
  296. updatedAt: new Date(),
  297. user: {
  298. name: '乐哥',
  299. avatar: avatars2[5],
  300. },
  301. group: {
  302. name: '程序员日常',
  303. link: 'http://github.com/',
  304. },
  305. project: {
  306. name: '品牌迭代',
  307. link: 'http://github.com/',
  308. },
  309. template: '在 @{group} 新建项目 @{project}',
  310. },
  311. ];
  312. function getFakeCaptcha(req, res) {
  313. if (res && res.json) {
  314. res.json('captcha-xxx');
  315. } else {
  316. return 'captcha-xxx';
  317. }
  318. }
  319. export default {
  320. 'GET /api/project/notice': getNotice,
  321. 'GET /api/activities': getActivities,
  322. 'POST /api/forms': (req, res) => {
  323. res.send({ message: 'Ok' });
  324. },
  325. 'GET /api/tags': mockjs.mock({
  326. 'list|100': [{ name: '@city', 'value|1-100': 150, 'type|0-2': 1 }],
  327. }),
  328. 'GET /api/fake_list': getFakeList,
  329. 'POST /api/fake_list': postFakeList,
  330. 'GET /api/captcha': getFakeCaptcha,
  331. };