Commit 3b202a8a authored by 愚道's avatar 愚道

remove .umirc.mock.js

parent e89dadee
import mockjs from 'mockjs';
const titles = [ const titles = [
'Alipay', 'Alipay',
'Angular', 'Angular',
...@@ -59,7 +61,7 @@ const user = [ ...@@ -59,7 +61,7 @@ const user = [
'仲尼', '仲尼',
]; ];
export function fakeList(count) { function fakeList(count) {
const list = []; const list = [];
for (let i = 0; i < count; i += 1) { for (let i = 0; i < count; i += 1) {
list.push({ list.push({
...@@ -109,7 +111,7 @@ export function fakeList(count) { ...@@ -109,7 +111,7 @@ export function fakeList(count) {
let sourceData; let sourceData;
export function getFakeList(req, res) { function getFakeList(req, res) {
const params = req.query; const params = req.query;
const count = params.count * 1 || 20; const count = params.count * 1 || 20;
...@@ -124,7 +126,7 @@ export function getFakeList(req, res) { ...@@ -124,7 +126,7 @@ export function getFakeList(req, res) {
} }
} }
export function postFakeList(req, res) { function postFakeList(req, res) {
const { /* url = '', */ body } = req; const { /* url = '', */ body } = req;
// const params = getUrlParams(url); // const params = getUrlParams(url);
const { method, id } = body; const { method, id } = body;
...@@ -160,7 +162,7 @@ export function postFakeList(req, res) { ...@@ -160,7 +162,7 @@ export function postFakeList(req, res) {
} }
} }
export const getNotice = [ const getNotice = [
{ {
id: 'xxx1', id: 'xxx1',
title: titles[0], title: titles[0],
...@@ -223,7 +225,7 @@ export const getNotice = [ ...@@ -223,7 +225,7 @@ export const getNotice = [
}, },
]; ];
export const getActivities = [ const getActivities = [
{ {
id: 'trend-1', id: 'trend-1',
updatedAt: new Date(), updatedAt: new Date(),
...@@ -324,7 +326,7 @@ export const getActivities = [ ...@@ -324,7 +326,7 @@ export const getActivities = [
}, },
]; ];
export function getFakeCaptcha(req, res) { function getFakeCaptcha(req, res) {
if (res && res.json) { if (res && res.json) {
res.json('captcha-xxx'); res.json('captcha-xxx');
} else { } else {
...@@ -333,9 +335,15 @@ export function getFakeCaptcha(req, res) { ...@@ -333,9 +335,15 @@ export function getFakeCaptcha(req, res) {
} }
export default { export default {
getNotice, 'GET /api/project/notice': getNotice,
getActivities, 'GET /api/activities': getActivities,
getFakeList, 'POST /api/forms': (req, res) => {
postFakeList, res.send({ message: 'Ok' });
getFakeCaptcha, },
'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,
}; };
...@@ -179,7 +179,7 @@ radarOriginData.forEach(item => { ...@@ -179,7 +179,7 @@ radarOriginData.forEach(item => {
}); });
}); });
export const getFakeChartData = { const getFakeChartData = {
visitData, visitData,
visitData2, visitData2,
salesData, salesData,
...@@ -193,5 +193,5 @@ export const getFakeChartData = { ...@@ -193,5 +193,5 @@ export const getFakeChartData = {
}; };
export default { export default {
getFakeChartData, 'GET /api/fake_chart_data': getFakeChartData,
}; };
import city from './geographic/city.json'; import city from './geographic/city.json';
import province from './geographic/province.json'; import province from './geographic/province.json';
export function getProvince(req, res) { function getProvince(req, res) {
res.json(province); res.json(province);
} }
export function getCity(req, res) { function getCity(req, res) {
res.json(city[req.params.province]); res.json(city[req.params.province]);
} }
export default { export default {
getProvince, 'GET /api/geographic/province': getProvince,
getCity, 'GET /api/geographic/city/:province': getCity,
}; };
export const getNotices = (req, res) => { const getNotices = (req, res) => {
res.json([ res.json([
{ {
id: '000000001', id: '000000001',
...@@ -94,6 +94,7 @@ export const getNotices = (req, res) => { ...@@ -94,6 +94,7 @@ export const getNotices = (req, res) => {
}, },
]); ]);
}; };
export default { export default {
getNotices, 'GET /api/notices': getNotices,
}; };
...@@ -141,18 +141,18 @@ const advancedOperation3 = [ ...@@ -141,18 +141,18 @@ const advancedOperation3 = [
}, },
]; ];
export const getProfileBasicData = { const getProfileBasicData = {
basicGoods, basicGoods,
basicProgress, basicProgress,
}; };
export const getProfileAdvancedData = { const getProfileAdvancedData = {
advancedOperation1, advancedOperation1,
advancedOperation2, advancedOperation2,
advancedOperation3, advancedOperation3,
}; };
export default { export default {
getProfileBasicData, 'GET /api/profile/advanced': getProfileAdvancedData,
getProfileAdvancedData, 'GET /api/profile/basic': getProfileBasicData,
}; };
...@@ -23,7 +23,7 @@ for (let i = 0; i < 46; i += 1) { ...@@ -23,7 +23,7 @@ for (let i = 0; i < 46; i += 1) {
}); });
} }
export function getRule(req, res, u) { function getRule(req, res, u) {
let url = u; let url = u;
if (!url || Object.prototype.toString.call(url) !== '[object String]') { if (!url || Object.prototype.toString.call(url) !== '[object String]') {
url = req.url; // eslint-disable-line url = req.url; // eslint-disable-line
...@@ -79,7 +79,7 @@ export function getRule(req, res, u) { ...@@ -79,7 +79,7 @@ export function getRule(req, res, u) {
} }
} }
export function postRule(req, res, u, b) { function postRule(req, res, u, b) {
let url = u; let url = u;
if (!url || Object.prototype.toString.call(url) !== '[object String]') { if (!url || Object.prototype.toString.call(url) !== '[object String]') {
url = req.url; // eslint-disable-line url = req.url; // eslint-disable-line
...@@ -141,6 +141,6 @@ export function postRule(req, res, u, b) { ...@@ -141,6 +141,6 @@ export function postRule(req, res, u, b) {
} }
export default { export default {
getRule, 'GET /api/rule': getRule,
postRule, 'POST /api/rule': postRule,
}; };
import mockjs from 'mockjs';
import { getRule, postRule } from './mock/rule';
import { getActivities, getNotice, getFakeList, postFakeList, getFakeCaptcha } from './mock/api';
import { getFakeChartData } from './mock/chart';
import { getProfileBasicData } from './mock/profile';
import { getProfileAdvancedData } from './mock/profile';
import { getNotices } from './mock/notices';
import { getProvince, getCity } from './mock/geographic';
// 是否禁用代理
const noProxy = process.env.NO_PROXY === 'true';
// 代码中会兼容本地 service mock 以及部署站点的静态数据 // 代码中会兼容本地 service mock 以及部署站点的静态数据
const proxy = { export default {
// 支持值为 Object 和 Array // 支持值为 Object 和 Array
'GET /api/currentUser': { 'GET /api/currentUser': {
name: 'Serati Ma', name: 'Serati Ma',
...@@ -83,21 +71,6 @@ const proxy = { ...@@ -83,21 +71,6 @@ const proxy = {
address: 'Sidney No. 1 Lake Park', address: 'Sidney No. 1 Lake Park',
}, },
], ],
'GET /api/project/notice': getNotice,
'GET /api/activities': getActivities,
'GET /api/rule': getRule,
'POST /api/rule': 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,
'POST /api/fake_list': postFakeList,
'GET /api/fake_chart_data': getFakeChartData,
'GET /api/profile/basic': getProfileBasicData,
'GET /api/profile/advanced': getProfileAdvancedData,
'POST /api/login/account': (req, res) => { 'POST /api/login/account': (req, res) => {
const { password, userName, type } = req.body; const { password, userName, type } = req.body;
if (password === '888888' && userName === 'admin') { if (password === '888888' && userName === 'admin') {
...@@ -125,7 +98,6 @@ const proxy = { ...@@ -125,7 +98,6 @@ const proxy = {
'POST /api/register': (req, res) => { 'POST /api/register': (req, res) => {
res.send({ status: 'ok', currentAuthority: 'user' }); res.send({ status: 'ok', currentAuthority: 'user' });
}, },
'GET /api/notices': getNotices,
'GET /api/500': (req, res) => { 'GET /api/500': (req, res) => {
res.status(500).send({ res.status(500).send({
timestamp: 1513932555104, timestamp: 1513932555104,
...@@ -162,9 +134,4 @@ const proxy = { ...@@ -162,9 +134,4 @@ const proxy = {
path: '/base/category/list', path: '/base/category/list',
}); });
}, },
'GET /api/geographic/province': getProvince,
'GET /api/geographic/city/:province': getCity,
'GET /api/captcha': getFakeCaptcha,
}; };
export default (noProxy ? {} : proxy);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment