Procházet zdrojové kódy

授权登录调整

zjh před 5 roky
rodič
revize
98e9c5b5a7
10 změnil soubory, kde provedl 95 přidání a 50 odebrání
  1. 1 1
      api/urls.js
  2. 1 3
      app.js
  3. 34 28
      pages/auth/auth.js
  4. 9 4
      pages/drop/drop.js
  5. 27 4
      pages/me/me.js
  6. 2 1
      pages/me/me.wxml
  7. 1 2
      pages/me/me.wxss
  8. 10 3
      pages/rise/rise.js
  9. 9 3
      pages/search/search.js
  10. 1 1
      utils/api.js

+ 1 - 1
api/urls.js

@@ -1,4 +1,4 @@
-const host = 'http://192.168.1.73:28002';
+const host = 'https://m.fda.s-privacy.cn';
 
 const urls ={
     hz:host + '/api/his/hz',

+ 1 - 3
app.js

@@ -48,9 +48,7 @@ App({
           })
         }else{
            // 未授权,跳转到授权页面
-           wx.reLaunch({
-            url: '/pages/auth/auth',
-          })
+
         }
       }
     })

+ 34 - 28
pages/auth/auth.js

@@ -17,41 +17,47 @@ Page({
           wx.getUserInfo({
             success: res => {
              app.globalData.userInfo = res.userInfo
-              wx.reLaunch({
-                url: '/pages/index/index',
-              })
+
             }
           })
 
         }
       }
     })
-        // 登录
-        wx.login({
-          success: res => {
-            console.log(res)
-            // 发送 res.code 到后台换取 openId, sessionKey, unionId
-            if (res.code) {
-              //发起网络请求
-              wx.request({
-                url: Api.postgetOpenId(),
-                data: {
-                  codeId: res.code
-                },
-                success (res) {
-                  console.log(res)
-                  if(res.statusCode==200){
-                    // app.globalData.openid=res.data.data.openid
-                    wx.setStorageSync('openid', res.data.data.openid)
-        
-                  }
-                }
-              })
-            } else {
-              console.log('登录失败!' + res.errMsg)
+    //登录
+    wx.login({
+      success: res => {
+        // console.log(res)
+        // 发送 res.code 到后台换取 openId, sessionKey, unionId
+        if (res.code) {
+          //发起网络请求
+          wx.request({
+            url: Api.postgetOpenId(),
+            data: {
+              codeId: res.code
+            },
+            success (res) {
+              // console.log(res)
+              if(res.statusCode==200){
+                // app.globalData.openid=res.data.data.openid
+                wx.setStorageSync('openid', res.data.data.openid)
+                var pages = getCurrentPages(); // 当前页面
+                var beforePage = pages[pages.length - 2]
+                wx.navigateBack({
+                 success: function() {
+                     beforePage.onLoad(); // 执行前一个页面的onLoad方法
+                 }
+             })
+              }else{
+
+              }
             }
-          }
-        })
+          })
+        } else {
+          console.log('登录失败!' + res.errMsg)
+        }
+      }
+    })
   },
 
   /**

+ 9 - 4
pages/drop/drop.js

@@ -396,9 +396,14 @@ Page({
   },
   open: function (e) {
     // console.log(e)
-    wx.navigateTo({
-      url: '../item/item?row='+JSON.stringify(e.currentTarget.dataset.row)
-    });
-
+    if(wx.getStorageSync('openid')){
+      wx.navigateTo({
+        url: '../item/item?row='+JSON.stringify(e.currentTarget.dataset.row)
+      });
+    }else{
+      wx.navigateTo ({
+        url: '/pages/auth/auth',
+      })
+    }
   }
 })

+ 27 - 4
pages/me/me.js

@@ -9,6 +9,7 @@ Page({
     userInfo: {
       avatarUrl:"../../images/person.png"
     }, 
+    loginif:false
   },
 
   /**
@@ -16,6 +17,15 @@ Page({
    */
   onLoad: function (options) {
     console.log(app.globalData);
+    if(wx.getStorageSync('openid')){
+      this.setData({
+        loginif:true
+      })
+    }else{
+      this.setData({
+        loginif:false
+      })
+    }
     if (app.globalData.userInfo) {
       this.setData({
         userInfo: app.globalData.userInfo, 
@@ -39,6 +49,11 @@ Page({
       })
     };
   },
+  login:function(){
+    wx.navigateTo ({
+      url: '/pages/auth/auth',
+    })
+  },
   getUserInfo: function(e) {
     //点击取消按钮
     if (e.detail.userInfo == null) {
@@ -65,7 +80,7 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
-
+   this.onLoad()
   },
 
   /**
@@ -103,9 +118,17 @@ Page({
 
   },
   gotoAttention(){
-    wx.navigateTo({
-      url: '../attention/attention',
-    })
+    if(wx.getStorageSync('openid')){
+      wx.navigateTo({
+        url: '../attention/attention',
+      })
+    }else{
+      wx.showLoading({title: '请先授权登录'})
+      setTimeout(function(){
+        wx.hideLoading()
+      },600);
+    }
+
   },
   gotoAbout(){
     wx.showToast({

+ 2 - 1
pages/me/me.wxml

@@ -1,7 +1,8 @@
 <view class="container">
   <view class="topView">
    <cover-image src='{{userInfo.avatarUrl}}'  class="personLogo"></cover-image>
-      <text class="phoneText">{{userInfo.nickName}}</text>
+      <text class="phoneText" wx:if="{{loginif}}">{{userInfo.nickName}}</text>
+      <button class="phoneText" type="primary" bindtap="login" wx:else> 微信授权登录</button>
   </view>
   <!-- <view>
      <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber"></button>

+ 1 - 2
pages/me/me.wxss

@@ -10,7 +10,7 @@
    width:72px;
    height:72px; 
    float:left;
-   margin-left:6%;
+   margin: 0 30rpx;
    border-radius:50%;
    display:inline-block;
 }
@@ -18,7 +18,6 @@
   color:white;
   display:inline-block;
   float:left;
-  margin-left:7%;
   margin-top:6%;
 }
 .seasonCard,.yearCard{

+ 10 - 3
pages/rise/rise.js

@@ -397,9 +397,16 @@ Page({
   },
   open: function (e) {
     // console.log(e)
-    wx.navigateTo({
-      url: '../item/item?row='+JSON.stringify(e.currentTarget.dataset.row)
-    });
+    if(wx.getStorageSync('openid')){
+      wx.navigateTo({
+        url: '../item/item?row='+JSON.stringify(e.currentTarget.dataset.row)
+      });
+    }else{
+      wx.navigateTo ({
+        url: '/pages/auth/auth',
+      })
+    }
+
 
   }
 })

+ 9 - 3
pages/search/search.js

@@ -133,9 +133,15 @@ Page({
  detail:function(e){
   console.log(e);
   this.save();
-  wx.navigateTo({
-    url: '../item/item?row='+JSON.stringify(e.currentTarget.dataset.row)
-  });
+  if(wx.getStorageSync('openid')){
+    wx.navigateTo({
+      url: '../item/item?row='+JSON.stringify(e.currentTarget.dataset.row)
+    });
+  }else{
+    wx.navigateTo ({
+      url: '/pages/auth/auth',
+    })
+  }
  },
   /**
    * 生命周期函数--监听页面初次渲染完成

+ 1 - 1
utils/api.js

@@ -1,6 +1,6 @@
 
 var wxRequest = require('wxRequest.js') 
-var HOST_URI = 'http://192.168.1.73:28002';
+var HOST_URI = 'https://m.fda.s-privacy.cn';
 module.exports = {  
   // 获取涨幅上周实际
   getinclast: function (obj) {