From 3b202a8a2206a6e41b027ddb5d4e27358c05aa1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=84=9A=E9=81=93?= Date: Wed, 11 Jul 2018 15:52:45 +0800 Subject: [PATCH] remove .umirc.mock.js --- mock/.gitkeep | 0 mock/api.js | 30 ++++++++++++++++++----------- mock/chart.js | 4 ++-- mock/geographic.js | 8 ++++---- mock/notices.js | 5 +++-- mock/profile.js | 8 ++++---- mock/rule.js | 8 ++++---- .umirc.mock.js => mock/user.js | 35 +--------------------------------- 8 files changed, 37 insertions(+), 61 deletions(-) delete mode 100644 mock/.gitkeep rename .umirc.mock.js => mock/user.js (70%) diff --git a/mock/.gitkeep b/mock/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/mock/api.js b/mock/api.js index a2017094..2bcdd8bb 100644 --- a/mock/api.js +++ b/mock/api.js @@ -1,3 +1,5 @@ +import mockjs from 'mockjs'; + const titles = [ 'Alipay', 'Angular', @@ -59,7 +61,7 @@ const user = [ '仲尼', ]; -export function fakeList(count) { +function fakeList(count) { const list = []; for (let i = 0; i < count; i += 1) { list.push({ @@ -109,7 +111,7 @@ export function fakeList(count) { let sourceData; -export function getFakeList(req, res) { +function getFakeList(req, res) { const params = req.query; const count = params.count * 1 || 20; @@ -124,7 +126,7 @@ export function getFakeList(req, res) { } } -export function postFakeList(req, res) { +function postFakeList(req, res) { const { /* url = '', */ body } = req; // const params = getUrlParams(url); const { method, id } = body; @@ -160,7 +162,7 @@ export function postFakeList(req, res) { } } -export const getNotice = [ +const getNotice = [ { id: 'xxx1', title: titles[0], @@ -223,7 +225,7 @@ export const getNotice = [ }, ]; -export const getActivities = [ +const getActivities = [ { id: 'trend-1', updatedAt: new Date(), @@ -324,7 +326,7 @@ export const getActivities = [ }, ]; -export function getFakeCaptcha(req, res) { +function getFakeCaptcha(req, res) { if (res && res.json) { res.json('captcha-xxx'); } else { @@ -333,9 +335,15 @@ export function getFakeCaptcha(req, res) { } export default { - getNotice, - getActivities, - getFakeList, - postFakeList, - getFakeCaptcha, + '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, }; diff --git a/mock/chart.js b/mock/chart.js index 55c8a412..8eca3829 100644 --- a/mock/chart.js +++ b/mock/chart.js @@ -179,7 +179,7 @@ radarOriginData.forEach(item => { }); }); -export const getFakeChartData = { +const getFakeChartData = { visitData, visitData2, salesData, @@ -193,5 +193,5 @@ export const getFakeChartData = { }; export default { - getFakeChartData, + 'GET /api/fake_chart_data': getFakeChartData, }; diff --git a/mock/geographic.js b/mock/geographic.js index b6892117..64e430ce 100644 --- a/mock/geographic.js +++ b/mock/geographic.js @@ -1,15 +1,15 @@ import city from './geographic/city.json'; import province from './geographic/province.json'; -export function getProvince(req, res) { +function getProvince(req, res) { res.json(province); } -export function getCity(req, res) { +function getCity(req, res) { res.json(city[req.params.province]); } export default { - getProvince, - getCity, + 'GET /api/geographic/province': getProvince, + 'GET /api/geographic/city/:province': getCity, }; diff --git a/mock/notices.js b/mock/notices.js index 7e1b3ce4..bc069380 100644 --- a/mock/notices.js +++ b/mock/notices.js @@ -1,4 +1,4 @@ -export const getNotices = (req, res) => { +const getNotices = (req, res) => { res.json([ { id: '000000001', @@ -94,6 +94,7 @@ export const getNotices = (req, res) => { }, ]); }; + export default { - getNotices, + 'GET /api/notices': getNotices, }; diff --git a/mock/profile.js b/mock/profile.js index 7c24be1b..03aecc56 100644 --- a/mock/profile.js +++ b/mock/profile.js @@ -141,18 +141,18 @@ const advancedOperation3 = [ }, ]; -export const getProfileBasicData = { +const getProfileBasicData = { basicGoods, basicProgress, }; -export const getProfileAdvancedData = { +const getProfileAdvancedData = { advancedOperation1, advancedOperation2, advancedOperation3, }; export default { - getProfileBasicData, - getProfileAdvancedData, + 'GET /api/profile/advanced': getProfileAdvancedData, + 'GET /api/profile/basic': getProfileBasicData, }; diff --git a/mock/rule.js b/mock/rule.js index 6245b82c..ea1b0fac 100644 --- a/mock/rule.js +++ b/mock/rule.js @@ -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; if (!url || Object.prototype.toString.call(url) !== '[object String]') { url = req.url; // eslint-disable-line @@ -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; if (!url || Object.prototype.toString.call(url) !== '[object String]') { url = req.url; // eslint-disable-line @@ -141,6 +141,6 @@ export function postRule(req, res, u, b) { } export default { - getRule, - postRule, + 'GET /api/rule': getRule, + 'POST /api/rule': postRule, }; diff --git a/.umirc.mock.js b/mock/user.js similarity index 70% rename from .umirc.mock.js rename to mock/user.js index 667b1ae9..f9294459 100644 --- a/.umirc.mock.js +++ b/mock/user.js @@ -1,17 +1,5 @@ -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 以及部署站点的静态数据 -const proxy = { +export default { // 支持值为 Object 和 Array 'GET /api/currentUser': { name: 'Serati Ma', @@ -83,21 +71,6 @@ const proxy = { 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) => { const { password, userName, type } = req.body; if (password === '888888' && userName === 'admin') { @@ -125,7 +98,6 @@ const proxy = { 'POST /api/register': (req, res) => { res.send({ status: 'ok', currentAuthority: 'user' }); }, - 'GET /api/notices': getNotices, 'GET /api/500': (req, res) => { res.status(500).send({ timestamp: 1513932555104, @@ -162,9 +134,4 @@ const proxy = { path: '/base/category/list', }); }, - 'GET /api/geographic/province': getProvince, - 'GET /api/geographic/city/:province': getCity, - 'GET /api/captcha': getFakeCaptcha, }; - -export default (noProxy ? {} : proxy); -- GitLab