Commit db402b7c authored by 郭志伟's avatar 郭志伟

feat: 问题修复

parent e0770a60
This diff is collapsed.
{
"name": "@qg/ui-request",
"version": "0.0.3",
"version": "0.0.8",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
{
"name": "@qg/ui-request",
"version": "0.0.5",
"version": "0.0.8",
"description": "axios策略请求封装",
"main": "dist/index.js",
"scripts": {
......
......@@ -10,10 +10,10 @@ function getURLSearchParams(json) {
return dataArray.filter(item => item !== undefined && item !== null).join('&');
}
function getVccChannel() {
function getVccChannel(channelKey = 'vccChannel') {
return isWechat
? localStorage.get('vccChannel') || ''
: (isAndroid ? '159905' : isIOS ? '159904' : localStorage.get('vccChannel')) || '';
? localStorage.get(channelKey) || ''
: (isAndroid ? '159905' : isIOS ? '159904' : localStorage.get(channelKey)) || '';
}
export default function strategyModes(toastFn = () => {}) {
return {
......@@ -56,6 +56,7 @@ export default function strategyModes(toastFn = () => {}) {
}
if (!hideVccChannel) {
cfg.headers['vccChannel'] = getVccChannel();
cfg.headers['sonVccChannel'] = getVccChannel('sonVccChannel');
}
if (method === 'post' && cfg.emulateJSON) {
cfg.headers['Content-Type'] = 'application/x-www-form-urlencoded';
......
......@@ -29,12 +29,14 @@ const defaultStratege = {
};
const defaultConfig = {
timeout: 15000
timeout: 15000,
strategy: 'service'
};
class HttpRequest {
constructor(strategy = {}, config = {}, toastFn = () => {}, loadingFn = () => {}) {
this.CancelToken = axios.CancelToken;
this.instance = axios.create({ ...defaultConfig, ...config });
this.axiosConfig = { ...defaultConfig, ...config };
this.instance = axios.create(this.axiosConfig);
this.pending = {};
this.reqNum = 0;
this.timeId = null;
......@@ -44,6 +46,8 @@ class HttpRequest {
this.strategyModes.default = defaultStratege;
this.initRequestInterceptors();
this.initResponseInterceptors();
}
getInstance() {
return this.instance;
}
beforeRequest() {
......@@ -83,9 +87,7 @@ class HttpRequest {
}
config.cancelToken = new self.CancelToken(c => (self.pending[config.url] = c));
// 使用默认响应处理策略
if (!config.strategy) {
config.strategy = 'service';
}
config.strategy = config.strategy || self.axiosConfig.strategy;
if (self.strategyModes[config.strategy].request) {
config = self.strategyModes[config.strategy].request(config);
}
......@@ -104,7 +106,6 @@ class HttpRequest {
!response.config.hideLoading && self.afterRequest();
delete self.pending[response.config.url || ''];
}
return self.strategyModes[response.config.strategy].response(response);
},
err => {
......
......@@ -2694,7 +2694,7 @@ var drawChart = (function () {
</script>
<script>
/*<!--*/
const data = {"version":1,"tree":{"name":"index.js","children":[{"name":"utils.js","uid":"6f55-1"},{"name":"localStorage.js","uid":"6f55-2"},{"name":"config.js","uid":"6f55-3"},{"name":"index.js","uid":"6f55-4"},{"name":"\u0000rollupPluginBabelHelpers.js","uid":"6f55-0"}],"renderedLength":5116,"isRoot":true},"nodes":{"6f55-0":{"renderedLength":1969,"id":"\u0000rollupPluginBabelHelpers.js"},"6f55-1":{"renderedLength":230,"id":"utils.js"},"6f55-2":{"renderedLength":634,"id":"localStorage.js"},"6f55-3":{"renderedLength":2182,"id":"config.js"},"6f55-4":{"renderedLength":4935,"isEntry":true,"id":"index.js"},"6f55-5":{"renderedLength":0,"isExternal":true,"id":"axios"}},"links":[{"source":"6f55-4","target":"6f55-0"},{"source":"6f55-4","target":"6f55-5"},{"source":"6f55-4","target":"6f55-3"},{"source":"6f55-3","target":"6f55-1"},{"source":"6f55-3","target":"6f55-2"}],"env":{"rollup":"2.44.0","rollup-plugin-visualizer":"4.2.2"},"options":{"gzip":false,"brotli":false}};
const data = {"version":1,"tree":{"name":"index.js","children":[{"name":"utils.js","uid":"31e0-1"},{"name":"localStorage.js","uid":"31e0-2"},{"name":"config.js","uid":"31e0-3"},{"name":"index.js","uid":"31e0-4"},{"name":"\u0000rollupPluginBabelHelpers.js","uid":"31e0-0"}],"renderedLength":5313,"isRoot":true},"nodes":{"31e0-0":{"renderedLength":1969,"id":"\u0000rollupPluginBabelHelpers.js"},"31e0-1":{"renderedLength":230,"id":"utils.js"},"31e0-2":{"renderedLength":634,"id":"localStorage.js"},"31e0-3":{"renderedLength":2352,"id":"config.js"},"31e0-4":{"renderedLength":5065,"isEntry":true,"id":"index.js"},"31e0-5":{"renderedLength":0,"isExternal":true,"id":"axios"}},"links":[{"source":"31e0-4","target":"31e0-0"},{"source":"31e0-4","target":"31e0-5"},{"source":"31e0-4","target":"31e0-3"},{"source":"31e0-3","target":"31e0-1"},{"source":"31e0-3","target":"31e0-2"}],"env":{"rollup":"2.44.0","rollup-plugin-visualizer":"4.2.2"},"options":{"gzip":false,"brotli":false}};
const run = () => {
const width = window.innerWidth;
......
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