zs il y a 3 ans
Parent
commit
81a43b4b1a
4 fichiers modifiés avec 20 ajouts et 8 suppressions
  1. 2 3
      app.json
  2. 14 0
      pages/home/index.js
  3. 4 3
      pages/login/index.js
  4. 0 2
      pages/register/index.js

+ 2 - 3
app.json

@@ -2,7 +2,6 @@
   "pages": [
   "pages": [
     "pages/login/index",
     "pages/login/index",
     "pages/home/index",
     "pages/home/index",
-    
     "pages/search/index",
     "pages/search/index",
     "pages/administration/index",
     "pages/administration/index",
     "pages/administration/detail",
     "pages/administration/detail",
@@ -22,9 +21,9 @@
     "pages/auditTeam/index",
     "pages/auditTeam/index",
     "pages/match/index",
     "pages/match/index",
     "pages/match/detail",
     "pages/match/detail",
-    "pages/index/index",
     "pages/register/index",
     "pages/register/index",
-    "pages/logs/logs"
+    "pages/logs/logs",
+    "pages/index/index"
   ],
   ],
   "usingComponents": {
   "usingComponents": {
     "van-button": "/miniprogram_npm/vant-weapp/button/index",
     "van-button": "/miniprogram_npm/vant-weapp/button/index",

+ 14 - 0
pages/home/index.js

@@ -52,9 +52,23 @@ Page({
    * 生命周期函数--监听页面加载
    * 生命周期函数--监听页面加载
    */
    */
   onLoad: function (options) {
   onLoad: function (options) {
+    // 监听用户是否登录
+    this.watchLogin();
     // 计算高度
     // 计算高度
     this.searchHeight()
     this.searchHeight()
   },
   },
+  // 监听用户是否登录
+  watchLogin: function () {
+    wx.getStorage({
+      key: 'token',
+      success: res => {
+        if (res.data) wx.redirectTo({ url: '/pages/home/index', })
+      },
+      fail: res => {
+        wx.redirectTo({ url: '/pages/login/index', })
+      }
+    })
+  },
   // 计算高度
   // 计算高度
   searchHeight: function () {
   searchHeight: function () {
     let frameStyle = this.data.frameStyle;
     let frameStyle = this.data.frameStyle;

+ 4 - 3
pages/login/index.js

@@ -33,9 +33,10 @@ Page({
         success(res) {
         success(res) {
           if (res.data.errcode == 0) {
           if (res.data.errcode == 0) {
             console.log('登录成功');
             console.log('登录成功');
-            wx.navigateTo({
-              url: '/pages/home/index',//跳转地址
-            })
+            app.globalData.userInfo = res.data.data;//存用户信息到app.js
+            wx.setStorage({ key: "token", data: 'token' })// 存用户信息到storage,以便之后判断用户是否登录
+            wx.showToast({ title: `账号登录成功`, icon: 'success', duration: 2000 }) //登录成功提示
+            wx.navigateTo({ url: '/pages/home/index' })// 跳转页面
           } else {
           } else {
             wx.showToast({
             wx.showToast({
               title: res.data.errmsg,
               title: res.data.errmsg,

+ 0 - 2
pages/register/index.js

@@ -26,7 +26,6 @@ Page({
   },
   },
   // 提交注册
   // 提交注册
   onSubmit: function (e) {
   onSubmit: function (e) {
-    console.log("用户类别:" + type)
     const params = e.detail.value;
     const params = e.detail.value;
     params.type = type
     params.type = type
     if (!this.WxValidate.checkForm(params)) {
     if (!this.WxValidate.checkForm(params)) {
@@ -34,7 +33,6 @@ Page({
       wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
       wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
       return false
       return false
     } else {
     } else {
-      console.log(params);
       wx.request({
       wx.request({
         url: `${app.globalData.publicUrl}/courtAdmin/api/user`, //接口地址
         url: `${app.globalData.publicUrl}/courtAdmin/api/user`, //接口地址
         method: 'post',
         method: 'post',