.roadhogrc.mock.js 4.55 KB
Newer Older
1 2
import mockjs from 'mockjs';
import { getRule, postRule } from './mock/rule';
valleykid's avatar
valleykid committed
3
import { getActivities, getNotice, getFakeList, postFakeList } from './mock/api';
4
import { getFakeChartData } from './mock/chart';
ddcat1115's avatar
ddcat1115 committed
5 6
import { getProfileBasicData } from './mock/profile';
import { getProfileAdvancedData } from './mock/profile';
7 8
import { getNotices } from './mock/notices';
import { format, delay } from 'roadhog-api-doc';
陈帅's avatar
陈帅 committed
9
import { getProvince, getCity, getArea } from './mock/geographic/geographic';
10

nikogu's avatar
nikogu committed
11 12
// 是否禁用代理
const noProxy = process.env.NO_PROXY === 'true';
13

nikogu's avatar
nikogu committed
14
// 代码中会兼容本地 service mock 以及部署站点的静态数据
15 16 17
const proxy = {
  // 支持值为 Object 和 Array
  'GET /api/currentUser': {
陈帅's avatar
陈帅 committed
18
    $desc: '获取当前用户接口',
19 20 21 22 23 24 25
    $params: {
      pageSize: {
        desc: '分页',
        exp: 2,
      },
    },
    $body: {
afc163's avatar
afc163 committed
26
      name: 'Serati Ma',
陈帅's avatar
陈帅 committed
27 28
      avatar:
        'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
29
      userid: '00000001',
陈帅's avatar
陈帅 committed
30
      email: 'antdesign@alipay.com',
ddcat1115's avatar
ddcat1115 committed
31 32
      signature: '海纳百川,有容乃大',
      title: '交互专家',
ddcat1115's avatar
ddcat1115 committed
33
      group: '蚂蚁金服-某某某事业群-某某平台部-某某技术部-UED',
ddcat1115's avatar
ddcat1115 committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
      tags: [{
        key: '0',
        label: '很有想法的',
      }, {
        key: '1',
        label: '专注设计',
      }, {
        key: '2',
        label: '辣~',
      }, {
        key: '3',
        label: '大长腿',
      }, {
        key: '4',
        label: '川妹子',
      }, {
        key: '5',
        label: '海纳百川',
      }],
53
      notifyCount: 12,
陈帅's avatar
陈帅 committed
54 55 56 57 58 59 60 61 62 63 64 65 66
      country: 'China',
      geographic: {
        province: {
          label: '浙江省',
          key: '330000',
        },
        city: {
          label: '杭州市',
          key: '330100',
        },
      },
      address: '西湖区工专路 77 号',
      phone: '0752-268888888',
67 68 69
    },
  },
  // GET POST 可省略
陈帅's avatar
陈帅 committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
  'GET /api/users': [
    {
      key: '1',
      name: 'John Brown',
      age: 32,
      address: 'New York No. 1 Lake Park',
    },
    {
      key: '2',
      name: 'Jim Green',
      age: 42,
      address: 'London No. 1 Lake Park',
    },
    {
      key: '3',
      name: 'Joe Black',
      age: 32,
      address: 'Sidney No. 1 Lake Park',
    },
  ],
90 91 92 93 94 95 96 97 98 99 100 101 102
  'GET /api/project/notice': getNotice,
  'GET /api/activities': getActivities,
  'GET /api/rule': getRule,
  'POST /api/rule': {
    $params: {
      pageSize: {
        desc: '分页',
        exp: 2,
      },
    },
    $body: postRule,
  },
  'POST /api/forms': (req, res) => {
afc163's avatar
afc163 committed
103
    res.send({ message: 'Ok' });
104 105
  },
  'GET /api/tags': mockjs.mock({
陈帅's avatar
陈帅 committed
106
    'list|100': [{ name: '@city', 'value|1-100': 150, 'type|0-2': 1 }],
107 108
  }),
  'GET /api/fake_list': getFakeList,
valleykid's avatar
valleykid committed
109
  'POST /api/fake_list': postFakeList,
110
  'GET /api/fake_chart_data': getFakeChartData,
ddcat1115's avatar
ddcat1115 committed
111 112
  'GET /api/profile/basic': getProfileBasicData,
  'GET /api/profile/advanced': getProfileAdvancedData,
113
  'POST /api/login/account': (req, res) => {
afc163's avatar
afc163 committed
114
    const { password, userName, type } = req.body;
陈帅's avatar
陈帅 committed
115
    if (password === '888888' && userName === 'admin') {
ddcat1115's avatar
ddcat1115 committed
116 117 118
      res.send({
        status: 'ok',
        type,
陈帅's avatar
陈帅 committed
119
        currentAuthority: 'admin',
ddcat1115's avatar
ddcat1115 committed
120
      });
陈帅's avatar
陈帅 committed
121
      return;
ddcat1115's avatar
ddcat1115 committed
122
    }
陈帅's avatar
陈帅 committed
123
    if (password === '123456' && userName === 'user') {
ddcat1115's avatar
ddcat1115 committed
124 125 126
      res.send({
        status: 'ok',
        type,
陈帅's avatar
陈帅 committed
127
        currentAuthority: 'user',
ddcat1115's avatar
ddcat1115 committed
128
      });
陈帅's avatar
陈帅 committed
129
      return;
ddcat1115's avatar
ddcat1115 committed
130
    }
afc163's avatar
afc163 committed
131
    res.send({
ddcat1115's avatar
ddcat1115 committed
132
      status: 'error',
afc163's avatar
afc163 committed
133
      type,
陈帅's avatar
陈帅 committed
134
      currentAuthority: 'guest',
afc163's avatar
afc163 committed
135
    });
136 137
  },
  'POST /api/register': (req, res) => {
ddcat1115's avatar
ddcat1115 committed
138
    res.send({ status: 'ok', currentAuthority: 'user' });
139 140
  },
  'GET /api/notices': getNotices,
陈帅's avatar
陈帅 committed
141 142
  'GET /api/500': (req, res) => {
    res.status(500).send({
陈帅's avatar
陈帅 committed
143 144 145 146 147
      timestamp: 1513932555104,
      status: 500,
      error: 'error',
      message: 'error',
      path: '/base/category/list',
陈帅's avatar
陈帅 committed
148 149 150 151
    });
  },
  'GET /api/404': (req, res) => {
    res.status(404).send({
陈帅's avatar
陈帅 committed
152 153 154 155 156
      timestamp: 1513932643431,
      status: 404,
      error: 'Not Found',
      message: 'No message available',
      path: '/base/category/list/2121212',
陈帅's avatar
陈帅 committed
157 158 159 160
    });
  },
  'GET /api/403': (req, res) => {
    res.status(403).send({
陈帅's avatar
陈帅 committed
161 162 163 164 165
      timestamp: 1513932555104,
      status: 403,
      error: 'Unauthorized',
      message: 'Unauthorized',
      path: '/base/category/list',
陈帅's avatar
陈帅 committed
166 167
    });
  },
168 169
  'GET /api/401': (req, res) => {
    res.status(401).send({
陈帅's avatar
陈帅 committed
170 171 172 173 174
      timestamp: 1513932555104,
      status: 401,
      error: 'Unauthorized',
      message: 'Unauthorized',
      path: '/base/category/list',
175 176
    });
  },
陈帅's avatar
陈帅 committed
177 178
  'GET /api/geographic/province': getProvince,
  'GET /api/geographic/city/:province': getCity,
179 180
};

陈帅's avatar
陈帅 committed
181
export default (noProxy ? {} : delay(proxy, 1000));