.roadhogrc.mock.js 7.99 KB
import mockjs from 'mockjs';
import { getRule, postRule } from './mock/rule';
import { getActivities, getNotice, getFakeList } from './mock/api';
import { getFakeChartData } from './mock/chart';
import { imgMap } from './mock/utils';
import { getProfileBasicData } from './mock/profile';
import { getProfileAdvancedData } from './mock/profile';
import { getNotices } from './mock/notices';
import { format, delay } from 'roadhog-api-doc';

import { getSchoolLists } from './mock/schoollist'
import {linkmanglist,linkmangroups,single_user} from './mock/linkman'
import {arealist} from './mock/areas'


// 是否禁用代理
const noProxy = process.env.NO_PROXY === 'true';

// 代码中会兼容本地 service mock 以及部署站点的静态数据
const proxy = {
  // 支持值为 Object 和 Array
  'GET /api/currentUser': {
    $desc: "获取当前用户接口",
    $params: {
      pageSize: {
        desc: '分页',
        exp: 2,
      },
    },
    $body: {
      name: 'Serati Ma',
      avatar: 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png',
      userid: '00000001',
      notifyCount: 12,
      //code:'10007',
    },
  },
  // GET POST 可省略
  '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',
  }],
  '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) => {
    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,
  'GET /api/fake_chart_data': getFakeChartData,
  'GET /api/profile/basic': getProfileBasicData,
  'GET /api/profile/advanced': getProfileAdvancedData,
  'POST /api/token/get': (req, res) => {
    const { secret, account, type } = req.body;
    if(secret === '888888' && account === 'admin'){
      res.send({
        token:{value:'xxxxxxx---xxxxx----xxxx'},
        ext:{
          status: 'ok',
          type,
          currentAuthority: 'admin'
        }
      });
      return ;
    }
  },
  'POST /api/login/account': (req, res) => {
    const { secret, account, type } = req.body;
    if(secret === '888888' && account === 'admin'){
      res.send({
        token:{value:'xxxxxxx---xxxxx----xxxx'},
        ext:{
          status: 'ok',
          type,
          currentAuthority: 'admin'
        }
      });
      return ;
    }
    if(secret === '123456' && account === 'user'){
      res.send({
        token:{value:'xxxxxxx---xxxxx----xxxx'},
        ext:{
          status: 'ok',
          type,
          currentAuthority: 'user'
        }
      });
      return ;
    }
    res.send({
      token:{value:'xxxxxxx---xxxxx----xxxx'},
      ext:{
        status: 'error',
        type,
        currentAuthority: 'guest'
      }
    });
  },
  'POST /api/register': (req, res) => {
    res.send({ status: 'ok', currentAuthority: 'user' });
  },
  'GET /api/notices': getNotices,
  'GET /api/ywpt/bd/schoolist': getSchoolLists,
  'GET /api/ywpt/wx/linkman/groups': linkmangroups,
  'GET /api/ywpt/wx/linkman/list': linkmanglist,
  'GET /api/ywpt/bd/area': arealist,
  'GET /api/ywpt/wx/linkman/user' : single_user,
  'GET /api/ywpt/wx/linkman/operation_cmd' : (req,res)=>{
    res.send({
      status: 'ok',
      code: 0,
      message:'功能触发成功...'
    });
  },
  'GET /api/ywpt/wx/schinfo':(req,res)=>{
    res.send({
      code:0,
      corpid:"wx720bfe80a251d709",
      followed:68,
      members:427,
      status:"ok",
      sysName:"明星宝贝惠州仲恺高新区潼侨光明学校",
      unfollowed:359,
      wxqrcodeUrl: "http://shp.qpic.cn/bizmp/YdxBCvkOIrBxN45FNiauQSTyg0S8bEiayX9JcTZ2eUTZTcGlNEG7ia8Gw/",
    });
  },
  'GET /api/500': (req, res) => {
    res.status(500).send({
      "timestamp": 1513932555104,
      "status": 500,
      "error": "error",
      "message": "error",
      "path": "/base/category/list"
    });
  },
  'GET /api/404': (req, res) => {
    res.status(404).send({
      "timestamp": 1513932643431,
      "status": 404,
      "error": "Not Found",
      "message": "No message available",
      "path": "/base/category/list/2121212"
    });
  },
  'GET /api/403': (req, res) => {
    res.status(403).send({
      "timestamp": 1513932555104,
      "status": 403,
      "error": "Unauthorized",
      "message": "Unauthorized",
      "path": "/base/category/list"
    });
  },
  'GET /api/401': (req, res) => {
    res.status(401).send({
      "timestamp": 1513932555104,
      "status": 401,
      "error": "Unauthorized",
      "message": "Unauthorized",
      "path": "/base/category/list"
    });
  },
  'GET /api/ywpt/wx/appinfo' :(req,res) =>{
     res.send({
      "list":[
        {
            "agentid":"80",
            "allow_partys":[
                "1"
            ],
            "name":"学校-微课",
            "square_logo_url":"http://wx.qlogo.cn/mmhead/Q3auHgzwzM6NAhlmVKZSdpJOVQGXMtJuWPdtsxibXrcdy6CwyFcZmpQ/0"
        },
        {
            "agentid":"36",
            "allow_partys":[
                "1"
            ],
            "name":"成绩查询",
            "square_logo_url":"http://wx.qlogo.cn/mmhead/Q3auHgzwzM6BBhS1C7bzs3sRRL5aOyWtBOFiaSjygZGj7GQY5TPHT7w/0"
        }
      ]
     });
  },
  'GET /api/ywpt/wx/mdf_admin':(req,res) =>{
    res.send({
      status: 'ok',
      code: 0,
      message:'功能触发成功...'
    });
  },
  'GET /sea/2017':[
    {
      "_id": "5a1bc1f7bf3ad50d1953818a", 
      "caption": "Campeonato Brasileiro da S\u00e9rie A", 
      "currentMatchday": 37, 
      "id": 444, 
      "lastUpdated": "2017-11-27T04:20:04Z", 
      "league": "BSA", 
      "numberOfGames": 380, 
      "numberOfMatchdays": 38, 
      "numberOfTeams": 20, 
      "year": "2017"
    }, 
    {
      "_id": "5a1bc1f7bf3ad50d1953818b", 
      "caption": "Premier League 2017/18", 
      "currentMatchday": 13, 
      "id": 445, 
      "lastUpdated": "2017-11-26T18:10:07Z", 
      "league": "PL", 
      "numberOfGames": 380, 
      "numberOfMatchdays": 38, 
      "numberOfTeams": 20, 
      "year": "2017"
    }, 
    {
      "_id": "5a1bc1f7bf3ad50d1953818c", 
      "caption": "Championship 2017/18", 
      "currentMatchday": 19, 
      "id": 446, 
      "lastUpdated": "2017-11-26T15:10:12Z", 
      "league": "ELC", 
      "numberOfGames": 552, 
      "numberOfMatchdays": 46, 
      "numberOfTeams": 24, 
      "year": "2017"
    }],
    'GET /teams/444':
    { 
      "pagination":{
        "total":1,
        "pageSize":4,
        "current":1
      },
      "list":[
        {
        "_id": "5a1e87aebf3ad5246014a67b", 
        "key":1,
        "league": "PL", 
        "league_id": 445, 
        "sc_name": "Arsenal", 
        "team_id": 57, 
        "team_name": "Arsenal FC"
        }, 
        {
          "_id": "5a1e87aebf3ad5246014a67c", 
          "key":2,
          "league": "PL", 
          "league_id": 445, 
          "sc_name": "Foxes", 
          "team_id": 338, 
          "team_name": "Leicester City FC"
        }, 
        {
          "_id": "5a1e87aebf3ad5246014a67d", 
          "key":3,
          "league": "PL", 
          "league_id": 445, 
          "sc_name": "Watford", 
          "team_id": 346, 
          "team_name": "Watford FC"
        }, 
        {
          "_id": "5a1e87aebf3ad5246014a67e", 
          "key":4,
          "league": "PL", 
          "league_id": 445, 
          "sc_name": "Liverpool", 
          "team_id": 64, 
          "team_name": "Liverpool FC"
        }
      ],
    },
};

//export default noProxy ? { "GET /*": "http://www.weixiao100.cn/","POST /*": "http://www.weixiao100.cn/" } : delay(proxy, 1000);
export default noProxy ? { "GET /*": "http://120.79.153.141:5000/","POST /*": "http://120.79.153.141:5000/" } : delay(proxy, 1000);