chore:1.0.17
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tiesheng/npm-tool",
|
"name": "@tiesheng/npm-tool",
|
||||||
"version": "1.0.16",
|
"version": "1.0.17",
|
||||||
"description": "npm tool package",
|
"description": "npm tool package",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -77,13 +77,15 @@ const dealParamsBody = (options) => {
|
|||||||
* @returns {Promise<<any>>}
|
* @returns {Promise<<any>>}
|
||||||
*/
|
*/
|
||||||
async function req(url, options) {
|
async function req(url, options) {
|
||||||
let {prefix} = GlobalConfig.getConfig();
|
let {prefix, urlDeal} = GlobalConfig.getConfig();
|
||||||
if (typeof prefix === "function") {
|
if (typeof prefix === "function") {
|
||||||
prefix = prefix(url);
|
prefix = prefix(url);
|
||||||
}
|
}
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
url = prefix + url;
|
url = prefix + url;
|
||||||
}
|
}
|
||||||
|
url = urlDeal(url)
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
request(url, {
|
request(url, {
|
||||||
...dealParamsBody(options),
|
...dealParamsBody(options),
|
||||||
|
|||||||
@@ -3,17 +3,20 @@
|
|||||||
* @type {{onHttpError: defaultConfig.onHttpError, prefix: string, base64Key: string}}
|
* @type {{onHttpError: defaultConfig.onHttpError, prefix: string, base64Key: string}}
|
||||||
*/
|
*/
|
||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
base64Key: "WmdUzPJXbngVNiaSsQrihg==",
|
base64Key: "WmdUzPJXbngVNiaSsQrihg==",
|
||||||
prefix: "",
|
prefix: "",
|
||||||
onHttpError: (res) => {
|
urlDeal: (url) => {
|
||||||
}
|
return url;
|
||||||
|
},
|
||||||
|
onHttpError: (res) => {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取网络请求配置
|
* 获取网络请求配置
|
||||||
*/
|
*/
|
||||||
const getConfig = () => {
|
const getConfig = () => {
|
||||||
return window.httpConfig || defaultConfig;
|
return window.httpConfig || defaultConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,9 +24,9 @@ const getConfig = () => {
|
|||||||
* @param obj
|
* @param obj
|
||||||
*/
|
*/
|
||||||
function setConfig(obj = defaultConfig) {
|
function setConfig(obj = defaultConfig) {
|
||||||
window.httpConfig = {...getConfig(), ...obj};
|
window.httpConfig = {...getConfig(), ...obj};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
setConfig, getConfig
|
setConfig, getConfig
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user