Explorar o código

环境判断接口地址

xiaohaizhao %!s(int64=2) %!d(string=hai) anos
pai
achega
07a904da11
Modificáronse 1 ficheiros con 59 adicións e 53 borrados
  1. 59 53
      utils/Http.js

+ 59 - 53
utils/Http.js

@@ -1,59 +1,65 @@
 let count = null;
 class HTTP {
-  constructor() {
-    this.baseUrl = "http://61.164.207.46:8000";
-    // this.baseUrl = "https://oms.idcgroup.com.cn:8079";
-  }
-  request({
-    url,
-    data = {},
-    method = "POST",
-    header = {
-      'content-type': 'application/json'
-    },
-    loading = true
-  }) {
-    return new Promise((resolve, reject) => {
-      this._request(url, resolve, reject, data, method, header, loading);
-    })
-  }
-  _request(url, resolve, reject, data, method, header, loading) {
-    /* if (loading) wx.showLoading({
-        title: '加载中...',
-        mask: true
-    }) */
-    wx.request({
-      url: this.baseUrl + '/yos/rest/index' + url,
-      data: data,
-      method: method,
-      header: header,
-      timeout: 60000,
-      success: res => resolve(res.data),
-      fial: err => reject(err),
-      complete: (res) => {
-        // if (loading) wx.hideLoading()
-        if (res.errMsg != 'request:ok') {
-          wx.showToast({
-            title: '网络异常,请重新进入',
-            icon: "none"
-          })
-        } else if (res.data.msg == '登陆状态已过期,请重新登陆!') {
-          wx.showToast({
-            title: '登陆状态已过期,请重新登陆!',
-            icon: "none",
-            mask: true
-          })
-          getApp().globalData.LaunchOptions = wx.getLaunchOptionsSync();
-          count = setTimeout(() => {
-            wx.reLaunch({
-              url: '/pages/login/phone',
-            });
-          }, 1000)
+    constructor() {
+        let ENV = wx.getAccountInfoSync().miniProgram.envVersion;
+        // ENV = 'release';
+        if (ENV === 'release') { // 正式版
+            this.baseUrl = "https://oms.idcgroup.com.cn:8079";
+        } else {
+            this.baseUrl = "http://61.164.207.46:8000";
         }
-      }
-    })
-  }
+        console.log("接口地址:", this.baseUrl)
+    }
+    request({
+        url,
+        data = {},
+        method = "POST",
+        header = {
+            'content-type': 'application/json'
+        },
+        loading = true
+    }) {
+        return new Promise((resolve, reject) => {
+            this._request(url, resolve, reject, data, method, header, loading);
+        })
+    }
+    _request(url, resolve, reject, data, method, header, loading) {
+        /* if (loading) wx.showLoading({
+            title: '加载中...',
+            mask: true
+        }) */
+        wx.request({
+            url: this.baseUrl + '/yos/rest/index' + url,
+            data: data,
+            method: method,
+            header: header,
+            timeout: 60000,
+            success: res => resolve(res.data),
+            fial: err => reject(err),
+            complete: (res) => {
+                // if (loading) wx.hideLoading()
+                if (res.errMsg != 'request:ok') {
+                    wx.showToast({
+                        title: '网络异常,请重新进入',
+                        icon: "none"
+                    })
+                } else if (res.data.msg == '登陆状态已过期,请重新登陆!') {
+                    wx.showToast({
+                        title: '登陆状态已过期,请重新登陆!',
+                        icon: "none",
+                        mask: true
+                    })
+                    getApp().globalData.LaunchOptions = wx.getLaunchOptionsSync();
+                    count = setTimeout(() => {
+                        wx.reLaunch({
+                            url: '/pages/login/phone',
+                        });
+                    }, 1000)
+                }
+            }
+        })
+    }
 }
 export {
-  HTTP
+    HTTP
 }