api.js 9.12 KB
Newer Older
afc163's avatar
afc163 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
const titles = [
  'Alipay',
  'Angular',
  'Ant Design',
  'Ant Design Pro',
  'Bootstrap',
  'React',
  'Vue',
  'Webpack',
];
const avatars = [
  'https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png', // Alipay
  'https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png', // Angular
  'https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png', // Ant Design
  'https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png', // Ant Design Pro
  'https://gw.alipayobjects.com/zos/rmsportal/siCrBXXhmvTQGWPNLBow.png', // Bootstrap
  'https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png', // React
  'https://gw.alipayobjects.com/zos/rmsportal/ComBAopevLwENQdKWiIn.png', // Vue
  'https://gw.alipayobjects.com/zos/rmsportal/nxkuOJlFJuAUhzlMTCEe.png', // Webpack
];
afc163's avatar
afc163 committed
21 22

const avatars2 = [
afc163's avatar
afc163 committed
23 24 25 26 27 28 29 30 31 32
  'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
  'https://gw.alipayobjects.com/zos/rmsportal/cnrhVkzwxjPwAaCfPbdc.png',
  'https://gw.alipayobjects.com/zos/rmsportal/gaOngJwsRYRaVAuXXcmB.png',
  'https://gw.alipayobjects.com/zos/rmsportal/ubnKSIfAJTxIgXOKlciN.png',
  'https://gw.alipayobjects.com/zos/rmsportal/WhxKECPNujWoWEFNdnJE.png',
  'https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png',
  'https://gw.alipayobjects.com/zos/rmsportal/psOgztMplJMGpVEqfcgF.png',
  'https://gw.alipayobjects.com/zos/rmsportal/ZpBqSxLxVEXfcUNoPKrz.png',
  'https://gw.alipayobjects.com/zos/rmsportal/laiEnJdGHVOhJrUShBaJ.png',
  'https://gw.alipayobjects.com/zos/rmsportal/UrQsqscbKEpNuJcvBZBu.png',
afc163's avatar
afc163 committed
33 34
];

afc163's avatar
afc163 committed
35
const covers = [
afc163's avatar
afc163 committed
36 37
  'https://gw.alipayobjects.com/zos/rmsportal/uMfMFlvUuceEyPpotzlq.png',
  'https://gw.alipayobjects.com/zos/rmsportal/iZBVOIhGJiAnhplqjvZW.png',
ddcat1115's avatar
ddcat1115 committed
38
  'https://gw.alipayobjects.com/zos/rmsportal/iXjVmWVHbCJAyqvDxdtx.png',
afc163's avatar
afc163 committed
39 40 41 42 43 44 45 46 47
  'https://gw.alipayobjects.com/zos/rmsportal/gLaIAoVWTtLbBWZNYEMg.png',
];
const desc = [
  '那是一种内在的东西, 他们到达不了,也无法触及的',
  '希望是一个好东西,也许是最好的,好东西是不会消亡的',
  '生命就像一盒巧克力,结果往往出人意料',
  '城镇中有那么多的酒馆,她却偏偏走进了我的酒馆',
  '那时候我只会想自己想要什么,从不想自己拥有什么',
];
niko's avatar
niko committed
48

afc163's avatar
afc163 committed
49 50 51 52 53 54 55 56 57 58 59 60
const user = [
  '付小小',
  '曲丽丽',
  '林东东',
  '周星星',
  '吴加好',
  '朱偏右',
  '鱼酱',
  '乐哥',
  '谭小仪',
  '仲尼',
];
61

afc163's avatar
afc163 committed
62
export function fakeList(count) {
63 64 65 66
  const list = [];
  for (let i = 0; i < count; i += 1) {
    list.push({
      id: `fake-list-${i}`,
niko's avatar
niko committed
67
      owner: user[i % 10],
68
      title: titles[i % 8],
afc163's avatar
afc163 committed
69
      avatar: avatars[i % 8],
陈帅's avatar
陈帅 committed
70
      cover: parseInt(i / 4, 10) % 2 === 0 ? covers[i % 4] : covers[3 - (i % 4)],
71 72
      status: ['active', 'exception', 'normal'][i % 3],
      percent: Math.ceil(Math.random() * 50) + 50,
afc163's avatar
afc163 committed
73
      logo: avatars[i % 8],
74
      href: 'https://ant.design',
jim's avatar
jim committed
75 76
      updatedAt: new Date(new Date().getTime() - 1000 * 60 * 60 * 2 * i),
      createdAt: new Date(new Date().getTime() - 1000 * 60 * 60 * 2 * i),
niko's avatar
niko committed
77
      subDescription: desc[i % 5],
jim's avatar
jim committed
78 79
      description:
        '在中台产品的研发过程中,会出现不同的设计规范和实现方式,但其中往往存在很多类似的页面和组件,这些类似的组件会被抽离成一套标准规范。',
80 81 82 83 84
      activeUser: Math.ceil(Math.random() * 100000) + 100000,
      newUser: Math.ceil(Math.random() * 1000) + 1000,
      star: Math.ceil(Math.random() * 100) + 100,
      like: Math.ceil(Math.random() * 100) + 100,
      message: Math.ceil(Math.random() * 10) + 10,
jim's avatar
jim committed
85 86
      content:
        '段落示意:蚂蚁金服设计平台 ant.design,用最小的工作量,无缝接入蚂蚁金服生态,提供跨越设计与开发的体验解决方案。蚂蚁金服设计平台 ant.design,用最小的工作量,无缝接入蚂蚁金服生态,提供跨越设计与开发的体验解决方案。',
87 88
      members: [
        {
nikogu's avatar
nikogu committed
89 90
          avatar: 'https://gw.alipayobjects.com/zos/rmsportal/ZiESqWwCXBRQoaPONSJe.png',
          name: '曲丽丽',
ddcat1115's avatar
ddcat1115 committed
91
          id: 'member1',
92 93
        },
        {
nikogu's avatar
nikogu committed
94
          avatar: 'https://gw.alipayobjects.com/zos/rmsportal/tBOxZPlITHqwlGjsJWaF.png',
95
          name: '王昭君',
ddcat1115's avatar
ddcat1115 committed
96
          id: 'member2',
97 98
        },
        {
nikogu's avatar
nikogu committed
99 100
          avatar: 'https://gw.alipayobjects.com/zos/rmsportal/sBxjgqiuHMGRkIjqlQCd.png',
          name: '董娜娜',
ddcat1115's avatar
ddcat1115 committed
101
          id: 'member3',
102 103 104 105 106 107 108 109
        },
      ],
    });
  }

  return list;
}

valleykid's avatar
valleykid committed
110 111
let sourceData;

陈帅's avatar
陈帅 committed
112 113
export function getFakeList(req, res) {
  const params = req.query;
114

jim's avatar
jim committed
115
  const count = params.count * 1 || 20;
116 117

  const result = fakeList(count);
valleykid's avatar
valleykid committed
118 119 120 121 122 123 124 125 126 127 128 129
  sourceData = result;

  if (res && res.json) {
    res.json(result);
  } else {
    return result;
  }
}

export function postFakeList(req, res) {
  const { /* url = '', */ body } = req;
  // const params = getUrlParams(url);
陈帅's avatar
陈帅 committed
130
  const { method, id } = body;
valleykid's avatar
valleykid committed
131 132 133 134 135 136 137 138 139 140
  // const count = (params.count * 1) || 20;
  let result = sourceData;

  switch (method) {
    case 'delete':
      result = result.filter(item => item.id !== id);
      break;
    case 'update':
      result.forEach((item, i) => {
        if (item.id === id) {
陈帅's avatar
陈帅 committed
141
          result[i] = Object.assign(item, body);
valleykid's avatar
valleykid committed
142 143 144 145 146
        }
      });
      break;
    case 'post':
      result.unshift({
陈帅's avatar
陈帅 committed
147
        body,
valleykid's avatar
valleykid committed
148 149 150 151 152 153 154
        id: `fake-list-${result.length}`,
        createdAt: new Date().getTime(),
      });
      break;
    default:
      break;
  }
155 156 157 158 159 160 161 162 163 164 165

  if (res && res.json) {
    res.json(result);
  } else {
    return result;
  }
}

export const getNotice = [
  {
    id: 'xxx1',
afc163's avatar
afc163 committed
166 167
    title: titles[0],
    logo: avatars[0],
afc163's avatar
afc163 committed
168
    description: '那是一种内在的东西,他们到达不了,也无法触及的',
169
    updatedAt: new Date(),
niko's avatar
niko committed
170
    member: '科学搬砖组',
ddcat1115's avatar
ddcat1115 committed
171 172
    href: '',
    memberLink: '',
173 174 175
  },
  {
    id: 'xxx2',
afc163's avatar
afc163 committed
176 177
    title: titles[1],
    logo: avatars[1],
niko's avatar
niko committed
178
    description: '希望是一个好东西,也许是最好的,好东西是不会消亡的',
afc163's avatar
afc163 committed
179
    updatedAt: new Date('2017-07-24'),
niko's avatar
niko committed
180
    member: '全组都是吴彦祖',
ddcat1115's avatar
ddcat1115 committed
181 182
    href: '',
    memberLink: '',
183 184 185
  },
  {
    id: 'xxx3',
afc163's avatar
afc163 committed
186 187
    title: titles[2],
    logo: avatars[2],
niko's avatar
niko committed
188
    description: '城镇中有那么多的酒馆,她却偏偏走进了我的酒馆',
189
    updatedAt: new Date(),
niko's avatar
niko committed
190
    member: '中二少女团',
ddcat1115's avatar
ddcat1115 committed
191 192
    href: '',
    memberLink: '',
193 194 195
  },
  {
    id: 'xxx4',
afc163's avatar
afc163 committed
196 197
    title: titles[3],
    logo: avatars[3],
niko's avatar
niko committed
198
    description: '那时候我只会想自己想要什么,从不想自己拥有什么',
afc163's avatar
afc163 committed
199
    updatedAt: new Date('2017-07-23'),
niko's avatar
niko committed
200
    member: '程序员日常',
ddcat1115's avatar
ddcat1115 committed
201 202
    href: '',
    memberLink: '',
203 204 205
  },
  {
    id: 'xxx5',
afc163's avatar
afc163 committed
206 207
    title: titles[4],
    logo: avatars[4],
niko's avatar
niko committed
208
    description: '凛冬将至',
afc163's avatar
afc163 committed
209
    updatedAt: new Date('2017-07-23'),
niko's avatar
niko committed
210
    member: '高逼格设计天团',
ddcat1115's avatar
ddcat1115 committed
211 212
    href: '',
    memberLink: '',
213 214 215
  },
  {
    id: 'xxx6',
afc163's avatar
afc163 committed
216 217
    title: titles[5],
    logo: avatars[5],
niko's avatar
niko committed
218
    description: '生命就像一盒巧克力,结果往往出人意料',
afc163's avatar
afc163 committed
219
    updatedAt: new Date('2017-07-23'),
niko's avatar
niko committed
220
    member: '骗你来学计算机',
ddcat1115's avatar
ddcat1115 committed
221 222
    href: '',
    memberLink: '',
223 224 225 226 227 228 229 230
  },
];

export const getActivities = [
  {
    id: 'trend-1',
    updatedAt: new Date(),
    user: {
afc163's avatar
afc163 committed
231
      name: '曲丽丽',
afc163's avatar
afc163 committed
232
      avatar: avatars2[0],
233
    },
afc163's avatar
afc163 committed
234 235 236 237 238 239 240 241 242
    group: {
      name: '高逼格设计天团',
      link: 'http://github.com/',
    },
    project: {
      name: '六月迭代',
      link: 'http://github.com/',
    },
    template: '在 @{group} 新建项目 @{project}',
243 244 245 246 247
  },
  {
    id: 'trend-2',
    updatedAt: new Date(),
    user: {
niko's avatar
niko committed
248
      name: '付小小',
afc163's avatar
afc163 committed
249
      avatar: avatars2[1],
250
    },
afc163's avatar
afc163 committed
251 252 253 254 255 256 257 258 259
    group: {
      name: '高逼格设计天团',
      link: 'http://github.com/',
    },
    project: {
      name: '六月迭代',
      link: 'http://github.com/',
    },
    template: '在 @{group} 新建项目 @{project}',
260 261 262 263 264
  },
  {
    id: 'trend-3',
    updatedAt: new Date(),
    user: {
afc163's avatar
afc163 committed
265
      name: '林东东',
afc163's avatar
afc163 committed
266
      avatar: avatars2[2],
267
    },
afc163's avatar
afc163 committed
268 269 270 271 272 273 274 275 276
    group: {
      name: '中二少女团',
      link: 'http://github.com/',
    },
    project: {
      name: '六月迭代',
      link: 'http://github.com/',
    },
    template: '在 @{group} 新建项目 @{project}',
277 278 279 280 281
  },
  {
    id: 'trend-4',
    updatedAt: new Date(),
    user: {
niko's avatar
niko committed
282
      name: '周星星',
afc163's avatar
afc163 committed
283
      avatar: avatars2[4],
284
    },
afc163's avatar
afc163 committed
285 286 287 288 289
    project: {
      name: '5 月日常迭代',
      link: 'http://github.com/',
    },
    template: '将 @{project} 更新至已发布状态',
290 291 292 293 294
  },
  {
    id: 'trend-5',
    updatedAt: new Date(),
    user: {
niko's avatar
niko committed
295
      name: '朱偏右',
afc163's avatar
afc163 committed
296
      avatar: avatars2[3],
297
    },
afc163's avatar
afc163 committed
298 299 300 301 302 303 304 305 306
    project: {
      name: '工程效能',
      link: 'http://github.com/',
    },
    comment: {
      name: '留言',
      link: 'http://github.com/',
    },
    template: '在 @{project} 发布了 @{comment}',
307 308 309 310 311
  },
  {
    id: 'trend-6',
    updatedAt: new Date(),
    user: {
niko's avatar
niko committed
312
      name: '乐哥',
afc163's avatar
afc163 committed
313
      avatar: avatars2[5],
314
    },
afc163's avatar
afc163 committed
315 316 317 318 319 320 321 322 323
    group: {
      name: '程序员日常',
      link: 'http://github.com/',
    },
    project: {
      name: '品牌迭代',
      link: 'http://github.com/',
    },
    template: '在 @{group} 新建项目 @{project}',
324 325 326
  },
];

327 328 329 330 331 332 333 334
export function getFakeCaptcha(req, res) {
  if (res && res.json) {
    res.json('captcha-xxx');
  } else {
    return 'captcha-xxx';
  }
}

335 336 337 338
export default {
  getNotice,
  getActivities,
  getFakeList,
valleykid's avatar
valleykid committed
339
  postFakeList,
340
  getFakeCaptcha,
341
};