diff --git a/mock/.gitkeep b/mock/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/mock/api.js b/mock/api.js index a20170943cde9e9aa617fd4eb695f619278689d8..2bcdd8bb3a904e3f892eaccfaa08904f09fe4ea2 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 55c8a412dbb080897ca50f8285307b48b18e70c7..8eca382979e837257888b72f02f51191d3036988 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 b68921176220c632e77c041bab4749b5191adb4f..64e430cebbe01516b7f037227756a7a17b7aa0c3 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 7e1b3ce43d2f1155eb08da70bfd37827893e8ca1..bc06938096d8548b907fd8914553c067394703bc 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 7c24be1bdae0f4cc1bbd3556cbf401e62effce22..03aecc56c01c33f8bd76a7131831e5754b4905b3 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 6245b82c9fac4f658f6abc43477efaa4379ab542..ea1b0fac375ec2aeaee272a29f287d0538361b37 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 667b1ae99f15901aaefaa7bb03966e0a795fba07..f92944599e68a26ea55a7b9d53df4ab168e17b63 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);