66 * @Company :
77 * @Date : 2019-08-16 16:57:42
88 * @LastEditors : 水痕
9- * @LastEditTime : 2019-08-16 17:30:10
9+ * @LastEditTime : 2019-08-21 10:21:16
1010 */
1111
1212import axios from 'axios' ;
@@ -59,9 +59,7 @@ export const axiosConfig = (): void => {
5959
6060 /********************************请求响应的 start********************************/
6161 function response ( res : any ) {
62- return isPlainRequest ( res . config . url ) || useOrigin ( response )
63- ? res
64- : res . data ;
62+ return isPlainRequest ( res . config . url ) || useOrigin ( res ) ? res : res . data ;
6563 }
6664 function responseError ( error : any ) {
6765 return Promise . reject ( error ) ;
@@ -73,3 +71,62 @@ export const axiosConfig = (): void => {
7371 // 拦截响应
7472 axios . interceptors . response . use ( response , responseError ) ;
7573} ;
74+
75+ // class AxiosRequest {
76+ // private baseUrl: string;
77+ // private timeout: number;
78+ // constructor(baseUrl: string = prefix, timeout: number = 60 * 1000) {
79+ // this.baseUrl = baseUrl;
80+ // this.timeout = timeout;
81+ // }
82+
83+ // public request(config: { [propsName: string]: any }) {
84+ // const instance = axios.create({
85+ // baseURL: this.baseUrl,
86+ // timeout: this.timeout,
87+ // });
88+ // /********************************设置请求拦截 start********************************/
89+ // instance.interceptors.request.use(this.requestSuccess, this.requestError);
90+ // /********************************设置请求拦截 end********************************/
91+ // /********************************设置响应拦截 start********************************/
92+ // instance.interceptors.response.use(
93+ // this.responseSuccess,
94+ // this.responseError,
95+ // );
96+ // /********************************设置响应拦截 end********************************/
97+ // return instance(config);
98+ // }
99+
100+ // private requestSuccess(config: { [propsName: string]: any }) {
101+ // config.headers['X-Origin'] = 'admin-web';
102+ // config.headers[authToken] = storage.getItem(authToken);
103+ // config.headers[authMobile] = storage.getItem(authMobile);
104+ // return config;
105+ // }
106+
107+ // private requestError(rejection: { data: any }) {
108+ // return this.useOrigin(rejection)
109+ // ? Promise.reject(rejection)
110+ // : Promise.reject(rejection.data);
111+ // }
112+
113+ // private responseSuccess(res: any): any {
114+ // return this.isPlainRequest(res.config.url) || this.useOrigin(res)
115+ // ? res
116+ // : res.data;
117+ // }
118+
119+ // private responseError(error: any) {
120+ // return Promise.reject(error);
121+ // }
122+
123+ // private useOrigin(res: any) {
124+ // return res.config.useOrigin;
125+ // }
126+
127+ // private isPlainRequest(input: string) {
128+ // return /\.(html?|xml|txt)$/.test(input);
129+ // }
130+ // }
131+
132+ // export const axiosConfig = new AxiosRequest();
0 commit comments