Commit 38f1302a authored by 王集鹄's avatar 王集鹄 Committed by 偏右

️ Change 'getUrlParams()' as standard library to 'url.parse()' (#926)

🔥 Clean up unused code
parent 3c18317c
......@@ -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';
......
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;
......
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];
......
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,
};
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