-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,82 @@ | ||
import axios, {AxiosRequestConfig} from "axios"; | ||
import axios, { AxiosRequestConfig } from "axios"; | ||
import SafeUtil from "./SafeUtil"; | ||
|
||
|
||
//http请求全部收口在这个工具类中,可以快速切换http框架。 | ||
export default class HttpUtil { | ||
|
||
|
||
static httpGet(url: any, params = {}, successCallback?: any, errorCallback?: any, finallyCallback?: any, opts?: any) { | ||
|
||
static httpGet( | ||
url: any, | ||
params = {}, | ||
successCallback?: any, | ||
errorCallback?: any, | ||
finallyCallback?: any, | ||
opts?: any | ||
) { | ||
axios | ||
.get(url, { | ||
params: params | ||
params: params, | ||
}) | ||
.then(function (response) { | ||
SafeUtil.safeCallback(successCallback)(response) | ||
|
||
SafeUtil.safeCallback(successCallback)(response); | ||
}) | ||
.catch(function (error) { | ||
|
||
SafeUtil.safeCallback(errorCallback)(error) | ||
|
||
SafeUtil.safeCallback(errorCallback)(error); | ||
}) | ||
.finally(function () { | ||
|
||
SafeUtil.safeCallback(finallyCallback)() | ||
|
||
SafeUtil.safeCallback(finallyCallback)(); | ||
}); | ||
} | ||
|
||
|
||
static httpPost(url: any, params = {}, successCallback?: any, errorCallback?: any, finallyCallback?: any, opts?: any) { | ||
|
||
static httpPost( | ||
url: any, | ||
params = {}, | ||
successCallback?: any, | ||
errorCallback?: any, | ||
finallyCallback?: any, | ||
opts?: any | ||
) { | ||
return axios | ||
.post(url, params, opts) | ||
.then(function (response) { | ||
|
||
SafeUtil.safeCallback(successCallback)(response) | ||
|
||
SafeUtil.safeCallback(successCallback)(response); | ||
}) | ||
.catch(function (error) { | ||
|
||
SafeUtil.safeCallback(errorCallback)(error) | ||
|
||
SafeUtil.safeCallback(errorCallback)(error); | ||
}) | ||
.finally(function () { | ||
|
||
SafeUtil.safeCallback(finallyCallback)() | ||
|
||
SafeUtil.safeCallback(finallyCallback)(); | ||
}); | ||
} | ||
|
||
/** | ||
* 上传文件的请求 | ||
*/ | ||
static httpPostFile(url: string, | ||
formData: FormData, | ||
successCallback?: any, | ||
errorCallback?: any, | ||
finallyCallback?: any, | ||
processCallback?: (progressEvent: any) => void, | ||
opts?: any) { | ||
|
||
static httpPostFile( | ||
url: string, | ||
formData: FormData, | ||
successCallback?: any, | ||
errorCallback?: any, | ||
finallyCallback?: any, | ||
processCallback?: (progressEvent: any) => void, | ||
opts?: any | ||
) { | ||
const config: AxiosRequestConfig = { | ||
headers: { | ||
'Content-Type': 'multipart/form-data' | ||
"Content-Type": "multipart/form-data", | ||
}, | ||
onUploadProgress: processCallback | ||
} | ||
cancelToken: opts ? opts.cancelToken : "", | ||
onUploadProgress: processCallback, | ||
}; | ||
|
||
axios | ||
.post(url, formData, config) | ||
.then(function (response) { | ||
|
||
SafeUtil.safeCallback(successCallback)(response) | ||
|
||
SafeUtil.safeCallback(successCallback)(response); | ||
}) | ||
.catch(function (error) { | ||
|
||
SafeUtil.safeCallback(errorCallback)(error) | ||
|
||
SafeUtil.safeCallback(errorCallback)(error); | ||
}) | ||
.finally(function () { | ||
|
||
SafeUtil.safeCallback(finallyCallback)() | ||
|
||
SafeUtil.safeCallback(finallyCallback)(); | ||
}); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters