.roadhogrc.mock.js 4.63 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 5
import { getFakeChartData } from './mock/chart';
import { imgMap } from './mock/utils';
ddcat1115's avatar
ddcat1115 committed
6 7
import { getProfileBasicData } from './mock/profile';
import { getProfileAdvancedData } from './mock/profile';
8 9
import { getNotices } from './mock/notices';
import { format, delay } from 'roadhog-api-doc';
陈帅's avatar
陈帅 committed
10
import { getProvince, getCity, getArea } from './mock/geographic/geographic';
11

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

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

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