wesley.chen vor 7 Jahren
Ursprung
Commit
f97009409f

+ 4 - 59
Furniture/app.js

xqd
@@ -9,66 +9,11 @@ App({
   onHide: function () {
     console.log('App Hide')
   },
-  request: function (object) {
-    if (!object.data)
-      object.data = {};
-    var access_token = wx.getStorageSync("access_token");
-    if (access_token) {
-      object.data.access_token = access_token;
-    }
-    wx.request({
-      url: object.url,
-      header: object.header || {
-        'content-type': 'application/x-www-form-urlencoded'
-      },
-      data: object.data || {},
-      method: object.method || "GET",
-      dataType: object.dataType || "json",
-      success: function (res) {
-      
-        // console.log(object.url)
 
-        object.success(res.data);
-
-      },
-      fail: function (res) {
-        console.warn('--- request fail >>>');
-        console.warn(res);
-        console.warn('<<< request fail ---');
-        var app = getApp();
-        if (app.is_on_launch) {
-          app.is_on_launch = false;
-          wx.showModal({
-            title: "网络请求出错",
-            content: res.errMsg,
-            showCancel: false,
-            success: function (res) {
-              if (res.confirm) {
-                if (object.fail)
-                  object.fail(res);
-              }
-            }
-          });
-        } else {
-          wx.showToast({
-            title: res.errMsg,
-            image: "/images/icon-warning.png",
-          });
-          if (object.fail)
-            object.fail(res);
-        }
-      },
-      complete: function (res) {
-        if (res.statusCode != 200) {
-          console.log('--- request http error >>>');
-          console.log(res);
-          console.log('<<< request http error ---');
-        }
-        if (object.complete)
-          object.complete(res);
-      }
-    });
-  },
+  login: require("utils/login.js"),
+  request: require("utils/request.js"),
+  utils: require("utils/utils.js"),
+  
   globalData: {
     hasLogin: false,
     store_id: 1

+ 2 - 2
Furniture/app.json

xqd
@@ -1,12 +1,12 @@
 {
   "pages": [
-    "page/login/login",
     "page/homePage/homePage",
     "page/user/user",
     "page/lifeCircle/lifeCircle",
     "page/contact/contact",
     "page/homePage/detail/detail",
-    "page/homePage/detail/conment/conment"
+    "page/homePage/detail/conment/conment",
+    "page/login/login"
   ],
   "window": {
     "navigationBarTextStyle": "black",

+ 0 - 2
Furniture/page/homePage/homePage.js

xqd
@@ -23,8 +23,6 @@ Page({
    */
   onLoad: function (options) {
     var that = this
-    var userinfo = wx.getStorageSync("user_info")
-    console.log(userinfo)
 
     var myAmapFun = new amapFile.AMapWX({ key: 'f74da0d1484bbbefb69059efa771b01d' });
     myAmapFun.getWeather({

+ 14 - 12
Furniture/page/login/login.js

xqd
@@ -42,24 +42,26 @@ Page({
               store_id: app.globalData.store_id
             },
             success: function (e) {
-          
-              if (e.data.userinfo.id) {
-                wx.setStorageSync("user_info", e.data.userinfo);
-
+              if (0 == e.status_code) {
+                wx.setStorageSync("access_token", e.data.token), wx.setStorageSync("user_info", e.data.userinfo);
                 var t = wx.getStorageSync("login_pre_page");
-                t && t.route || wx.switchTab({
-                  url: "/page/homePage/homePage"
+                t && t.route || wx.redirectTo({
+                  url: "/pages/homePage/homePage"
+                });
+                var o = 0;
+                (o = t.options && t.options.user_id ? t.options.user_id : t.options && t.options.scene ? t.options.scene : wx.getStorageSync("parent_id")) && 0 != o && getApp().bindParent({
+                  parent_id: o
+                }), wx.redirectTo({
+                  url: "/" + t.route + "?" + getApp().utils.objectToUrlParams(t.options)
                 });
-              } else ({
-                /*title: "提示",
+              } else console.log(e), wx.showModal({
+          
+                title: "提示",
                 content: e.msg,
-                showCancel: !1*/
+                showCancel: !1
               });
             },
             complete: function () {
-              wx.redirectTo({
-                url: "/page/homePage/homePage"
-              });
               wx.hideLoading();
             }
           });

+ 10 - 0
Furniture/utils/login.js

xqd
@@ -0,0 +1,10 @@
+module.exports = function (e) {
+  var g;
+  if ((g = getCurrentPages()).length) {
+    var r = g[g.length - 1];
+    r && "page/login/login" != r.route && wx.setStorageSync("login_pre_page", r);
+  }
+  wx.redirectTo({
+    url: "/page/login/login"
+  });
+};

+ 46 - 0
Furniture/utils/request.js

xqd
@@ -0,0 +1,46 @@
+module.exports = function (e) {
+  e.data || (e.data = {});
+  var a = wx.getStorageSync("access_token");
+  a && (e.data.access_token = a),
+    wx.request({
+      url: e.url,
+      header: e.header || {
+        "content-type": "application/x-www-form-urlencoded"
+      },
+      data: e.data || {},
+      method: e.method || "GET",
+      dataType: e.dataType || "json",
+      success: function (a) {
+        401 == a.data.data.code ? getApp().login() : e.success && e.success(a.data);
+      },
+      fail: function (a) {
+        console.warn("--- request fail >>>"), console.warn(a), console.warn("<<< request fail ---");
+        var t = getApp();
+        t.is_on_launch ? (t.is_on_launch = !1, wx.showModal({
+          title: "网络请求出错",
+          content: a.errMsg,
+          showCancel: !1,
+          success: function (a) {
+            a.confirm && e.fail && e.fail(a);
+          }
+        })) : (wx.showToast({
+          title: a.errMsg,
+          image: "/images/icon-warning.png"
+        }), e.fail && e.fail(a));
+      },
+      complete: function (t) {
+        200 != t.statusCode && (t.data.code && 500 == t.data.code && wx.showModal({
+          title: "系统错误",
+          content: t.data.data.type + "\r\n事件ID:" + t.data.data.event_id,
+          cancelText: "关闭",
+          confirmText: "复制",
+          success: function (a) {
+            a.confirm && wx.setClipboardData({
+              data: t.data.data.type + "\r\n事件ID:" + t.data.data.event_id + "\r\n " + e.url
+            });
+          }
+        }), console.log("--- request http error >>>"), console.log(t.statusCode), console.log(t.data),
+          console.log("<<< request http error ---")), e.complete && e.complete(t);
+      }
+    });
+};

+ 34 - 0
Furniture/utils/utils.js

xqd
@@ -0,0 +1,34 @@
+function formatTime(t) {
+  var r = t.getFullYear(), e = t.getMonth() + 1, a = t.getDate(), o = t.getHours(), n = t.getMinutes(), m = t.getSeconds();
+  return [r, e, a].map(formatNumber).join("/") + " " + [o, n, m].map(formatNumber).join(":");
+}
+
+function formatData(t) {
+  var r = t.getFullYear(), e = t.getMonth() + 1, a = t.getDate();
+  t.getHours(), t.getMinutes(), t.getSeconds();
+  return [r, e, a].map(formatNumber).join("-");
+}
+
+function formatNumber(t) {
+  return (t = t.toString())[1] ? t : "0" + t;
+}
+
+function objectToUrlParams(t) {
+  var r = "";
+  for (var e in t) r += "&" + e + "=" + t[e];
+  return r.substr(1);
+}
+
+module.exports = {
+  formatTime: formatTime,
+  objectToUrlParams: objectToUrlParams,
+  formatData: formatData,
+  scene_decode: function (t) {
+    var r = (t + "").split(","), e = {};
+    for (var a in r) {
+      var o = r[a].split(":");
+      0 < o.length && o[0] && (e[o[0]] = o[1] || null);
+    }
+    return e;
+  }
+};