|
@@ -0,0 +1,58 @@
|
|
|
+class HTTP {
|
|
|
+ constructor() {
|
|
|
+ this.env = 'dev';
|
|
|
+ }
|
|
|
+ request({
|
|
|
+ url,
|
|
|
+ data = {},
|
|
|
+ method = "POST",
|
|
|
+ header = {
|
|
|
+ 'content-type': 'application/json'
|
|
|
+ },
|
|
|
+ showLoading = ''
|
|
|
+ }) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ this._request(url, resolve, reject, data, method, header, showLoading);
|
|
|
+ })
|
|
|
+ }
|
|
|
+ _request(url, resolve, reject, data, method, header, showLoading) {
|
|
|
+ if (showLoading) uni.showLoading({
|
|
|
+ title: showLoading,
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+ uni.request({
|
|
|
+ // #ifdef H5
|
|
|
+ url: (this.env == 'dev' ? "/apis1" : "/apis") + '/waserver/rest/index' + url,
|
|
|
+ // #endif
|
|
|
+ // #ifndef H5
|
|
|
+ url: (this.env == 'dev' ? "http://60.204.153.188" : "https://oms.idcgroup.com.cn:8079") + '/waserver/rest/index' + url,
|
|
|
+ // #endif
|
|
|
+ data: data,
|
|
|
+ method: method,
|
|
|
+ header: header,
|
|
|
+ timeout: 60000,
|
|
|
+ success: res => resolve(res.data),
|
|
|
+ fial: err => reject(err),
|
|
|
+ complete: (res) => {
|
|
|
+ if (showLoading) uni.hideLoading()
|
|
|
+ if (res.errMsg != 'request:ok') {
|
|
|
+ uni.showToast({
|
|
|
+ title: '网络异常,请重新进入',
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ } else if (res.data.msg == '登陆状态已过期,请重新登陆!') {
|
|
|
+ uni.redirectTo({
|
|
|
+ url: '/pages/login/login',
|
|
|
+ });
|
|
|
+ uni.showToast({
|
|
|
+ title: res.msg,
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+export {
|
|
|
+ HTTP
|
|
|
+}
|