diff --git a/.roadhogrc.mock.js b/.roadhogrc.mock.js index 076ee0c687b3686e7b3fb2e7f38e311c208482af..284f3161141f07a4dd26c74efd7305c753738529 100644 --- a/.roadhogrc.mock.js +++ b/.roadhogrc.mock.js @@ -2,7 +2,6 @@ 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'; diff --git a/mock/api.js b/mock/api.js index 35b649460d9fcabc2455d239af132a1bffc5927a..969c15182cbfb7ddb2eae5e53f8917d3f119c23a 100644 --- a/mock/api.js +++ b/mock/api.js @@ -1,4 +1,4 @@ -import { getUrlParams } from './utils'; +import { parse } from 'url'; const titles = [ 'Alipay', @@ -110,7 +110,7 @@ export function getFakeList(req, res, u) { url = req.url; // eslint-disable-line } - const params = getUrlParams(url); + const params = parse(url, true).query; const count = (params.count * 1) || 20; diff --git a/mock/rule.js b/mock/rule.js index 2090ce8e18a0687987045ab6119471aa21508d86..78fb95d1531af6ba3fc046128957ee58e4089049 100644 --- a/mock/rule.js +++ b/mock/rule.js @@ -1,4 +1,4 @@ -import { getUrlParams } from './utils'; +import { parse } from 'url'; // mock tableListDataSource let tableListDataSource = []; @@ -26,7 +26,7 @@ export function getRule(req, res, u) { url = req.url; // eslint-disable-line } - const params = getUrlParams(url); + const params = parse(url, true).query; let dataSource = [...tableListDataSource]; diff --git a/mock/utils.js b/mock/utils.js deleted file mode 100644 index 8438a2658df6a3dd105de7961080c1c58ffaedc0..0000000000000000000000000000000000000000 --- a/mock/utils.js +++ /dev/null @@ -1,45 +0,0 @@ -export const imgMap = { - user: 'https://gw.alipayobjects.com/zos/rmsportal/UjusLxePxWGkttaqqmUI.png', - a: 'https://gw.alipayobjects.com/zos/rmsportal/ZrkcSjizAKNWwJTwcadT.png', - b: 'https://gw.alipayobjects.com/zos/rmsportal/KYlwHMeomKQbhJDRUVvt.png', - c: 'https://gw.alipayobjects.com/zos/rmsportal/gabvleTstEvzkbQRfjxu.png', - d: 'https://gw.alipayobjects.com/zos/rmsportal/jvpNzacxUYLlNsHTtrAD.png', -}; - -// refers: https://www.sitepoint.com/get-url-parameters-with-javascript/ -export function getUrlParams(url) { - const d = decodeURIComponent; - let queryString = url ? url.split('?')[1] : window.location.search.slice(1); - const obj = {}; - if (queryString) { - queryString = queryString.split('#')[0]; // eslint-disable-line - const arr = queryString.split('&'); - for (let i = 0; i < arr.length; i += 1) { - const a = arr[i].split('='); - let paramNum; - const paramName = a[0].replace(/\[\d*\]/, (v) => { - paramNum = v.slice(1, -1); - return ''; - }); - const paramValue = typeof (a[1]) === 'undefined' ? true : a[1]; - if (obj[paramName]) { - if (typeof obj[paramName] === 'string') { - obj[paramName] = d([obj[paramName]]); - } - if (typeof paramNum === 'undefined') { - obj[paramName].push(d(paramValue)); - } else { - obj[paramName][paramNum] = d(paramValue); - } - } else { - obj[paramName] = d(paramValue); - } - } - } - return obj; -} - -export default { - getUrlParams, - imgMap, -};