api.js 9.21 KB
Newer Older
愚道's avatar
愚道 committed
1 2
import mockjs from 'mockjs';

afc163's avatar
afc163 committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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
23 24

const avatars2 = [
afc163's avatar
afc163 committed
25 26 27 28 29 30 31 32 33 34
  '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
35 36
];

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

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

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

  return list;
}

valleykid's avatar
valleykid committed
112 113
let sourceData;

愚道's avatar
愚道 committed
114
function getFakeList(req, res) {
陈帅's avatar
陈帅 committed
115
  const params = req.query;
116

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

  const result = fakeList(count);
valleykid's avatar
valleykid committed
120
  sourceData = result;
121
  res.json(result);
valleykid's avatar
valleykid committed
122 123
}

愚道's avatar
愚道 committed
124
function postFakeList(req, res) {
valleykid's avatar
valleykid committed
125 126
  const { /* url = '', */ body } = req;
  // const params = getUrlParams(url);
陈帅's avatar
陈帅 committed
127
  const { method, id } = body;
valleykid's avatar
valleykid committed
128 129 130 131 132 133 134 135 136 137
  // 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
138
          result[i] = Object.assign(item, body);
valleykid's avatar
valleykid committed
139 140 141 142 143
        }
      });
      break;
    case 'post':
      result.unshift({
陈帅's avatar
陈帅 committed
144
        body,
valleykid's avatar
valleykid committed
145 146 147 148 149 150 151
        id: `fake-list-${result.length}`,
        createdAt: new Date().getTime(),
      });
      break;
    default:
      break;
  }
152

153
  res.json(result);
154 155
}

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

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

愚道's avatar
愚道 committed
320
function getFakeCaptcha(req, res) {
321
  res.json('captcha-xxx');
322 323
}

324
export default {
愚道's avatar
愚道 committed
325 326 327 328 329 330 331 332 333 334 335
  'GET /api/project/notice': getNotice,
  'GET /api/activities': getActivities,
  'POST /api/forms': (req, res) => {
    res.send({ message: 'Ok' });
  },
  'GET /api/tags': mockjs.mock({
    'list|100': [{ name: '@city', 'value|1-100': 150, 'type|0-2': 1 }],
  }),
  'GET /api/fake_list': getFakeList,
  'POST /api/fake_list': postFakeList,
  'GET /api/captcha': getFakeCaptcha,
336
};