提交 bd9d6d19 编写于 作者: KK's avatar KK

修复后台报错前端无任何提示bug & 代码格式化

上级 731ea5e4
import axios, { AxiosResponse } from 'axios';
import qs from 'qs';
import { HttpResponse } from './http-response';
import { Notice } from '@/utils/notice/notice';
import { Loading } from '../loading/loading';
/**
* Http net 对象
......@@ -24,6 +25,15 @@ export class Http {
return this.Http;
}
/**
* 提示工具类
*
* @protected
* @type {Notice}
* @memberof UIActionBase
*/
private notice: Notice = Notice.getInstance();
/**
* 单例变量声明
*
......@@ -106,36 +116,36 @@ export class Http {
* @returns {Promise<any>}
* @memberof Http
*/
public get(url: string,params: any = {}, isloading?: boolean, serialnumber?: number): Promise<any> {
public get(url: string, params: any = {}, isloading?: boolean, serialnumber?: number): Promise<any> {
params = this.handleRequestData(params);
if(params.srfparentdata){
Object.assign(params,params.srfparentdata);
if (params.srfparentdata) {
Object.assign(params, params.srfparentdata);
delete params.srfparentdata;
}
if((Object.keys(params)).length>0){
let tempParam:any = {};
let sort:any = null;
Object.keys(params).forEach((item:any) =>{
if( params[item] || Object.is(params[item],0) ){
if (Object.is(item,'sort')){
sort = params[item];
}else{
tempParam[item] = params[item];
if ((Object.keys(params)).length > 0) {
let tempParam: any = {};
let sort: any = null;
Object.keys(params).forEach((item: any) => {
if (params[item] || Object.is(params[item], 0)) {
if (Object.is(item, 'sort')) {
sort = params[item];
} else {
tempParam[item] = params[item];
}
}
})
url += `?${qs.stringify(tempParam)}`;
if(sort){
url += '&sort='+sort;
if (sort) {
url += '&sort=' + sort;
}
}
}
if (isloading) {
this.beginLoading();
}
return new Promise((resolve: any, reject: any) => {
axios.get(url).then((response: AxiosResponse) => {
resolve(this.doResponseRresult(response, resolve, isloading, serialnumber));
}).catch((response: AxiosResponse) => {
reject(this.doResponseRresult(response, reject, isloading, serialnumber));
});
......@@ -151,19 +161,19 @@ export class Http {
* @returns {Promise<any>}
* @memberof Http
*/
public delete(url: string, isloading?: boolean,data?:any, serialnumber?: number): Promise<any> {
public delete(url: string, isloading?: boolean, data?: any, serialnumber?: number): Promise<any> {
if (isloading) {
this.beginLoading();
}
return new Promise((resolve: any, reject: any) => {
if(!data){
if (!data) {
axios.delete(url).then((response: any) => {
resolve(this.doResponseRresult(response, resolve, isloading, serialnumber));
}).catch((response: any) => {
reject(this.doResponseRresult(response, reject, isloading, serialnumber));
});
}else{
axios.delete(url,{data:data}).then((response: any) => {
} else {
axios.delete(url, { data: data }).then((response: any) => {
resolve(this.doResponseRresult(response, resolve, isloading, serialnumber));
}).catch((response: any) => {
reject(this.doResponseRresult(response, reject, isloading, serialnumber));
......@@ -217,8 +227,10 @@ export class Http {
if (response.status === 200) {
return new HttpResponse(200, response.data, undefined, response.headers);
}
this.notice.error(response.data.message ? response.data.message : HttpResponse.getStatusMessage(response.status));
return new HttpResponse(response.status, response.data, { code: 101, message: HttpResponse.getStatusMessage(response.status) }, response.headers)
}
this.notice.error(HttpResponse.getStatusMessage(response.status));
return new HttpResponse(500, null, { code: 100, message: '请求发生异常,无返回结果!' }, response.headers);
}
......@@ -245,8 +257,8 @@ export class Http {
}
setTimeout(() => {
if (this.loadingCount === 0) {
// todo 停止加载
Loading.hidden();
// todo 停止加载
Loading.hidden();
}
}, 500);
}
......@@ -258,11 +270,11 @@ export class Http {
* @param data
* @memberof Http
*/
private handleRequestData(data:any){
if(data.srfsessionkey){
private handleRequestData(data: any) {
if (data.srfsessionkey) {
delete data.srfsessionkey;
}
if(data.srfsessionid){
if (data.srfsessionid) {
delete data.srfsessionid;
}
return data;
......
......@@ -3,7 +3,6 @@ import axios from 'axios';
import Router from 'vue-router';
import i18n from '@/locale';
import ignoreProxyMap from './ignore-proxy';
import { Loading } from '@/ibiz-core/utils';
/**
* 拦截器
*
......@@ -30,7 +29,7 @@ export class Interceptors {
*/
private store: Store<any> | any;
/**
* 单列对象
......@@ -87,8 +86,8 @@ export class Interceptors {
const token = window.localStorage.getItem('token');
config.headers.Authorization = `Bearer ${token}`;
}
config.headers['Accept-Language'] = i18n.locale;
config.headers['Accept-Language'] = i18n.locale;
// 混合 app 代理处理
if (Object.is(process.env.VUE_APP_CURRENTMODE, 'hybridapp') && !config.url.startsWith('https://') && !config.url.startsWith('http://')) {
if (!ignoreProxyMap.has(config.url)) {
......@@ -104,22 +103,17 @@ export class Interceptors {
return response;
}, (error: any) => {
error = error ? error : { response: {} };
// tslint:disable-next-line:prefer-const
let { response: res } = error;
let { data: _data } = res;
if (res.status === 401) {
// Loading.hidden();
this.doNoLogin(_data.data);
}
if (res.status === 404) {
// Loading.hidden();
this.router.push({ path: '/404' });
} else if (res.status === 500) {
// Loading.hidden();
this.router.push({ path: '/500' });
}
return Promise.reject(res);
});
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册