lx 5 年之前
父节点
当前提交
841a97b520
共有 9 个文件被更改,包括 174 次插入7 次删除
  1. 5 1
      app.js
  2. 2 1
      app.json
  3. 81 0
      pages/auth/auth.js
  4. 4 0
      pages/auth/auth.json
  5. 9 0
      pages/auth/auth.wxml
  6. 70 0
      pages/auth/auth.wxss
  7. 二进制
      pages/auth/images/logo.jpg
  8. 0 2
      pages/index/index.js
  9. 3 3
      project.config.json

+ 5 - 1
app.js

@@ -21,7 +21,6 @@ App({
             success: res => {
               // 可以将 res 发送给后台解码出 unionId
               this.globalData.userInfo = res.userInfo
-
               // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
               // 所以此处加入 callback 以防止这种情况
               if (this.userInfoReadyCallback) {
@@ -29,6 +28,11 @@ App({
               }
             }
           })
+        }else{
+           // 未授权,跳转到授权页面
+           wx.reLaunch({
+            url: '/pages/auth/auth',
+          })
         }
       }
     })

+ 2 - 1
app.json

@@ -7,7 +7,8 @@
     "pages/me/me",
     "pages/details/details",
     "pages/next/next",
-    "pages/news/news"
+    "pages/news/news",
+    "pages/auth/auth"
   ],
   "window": {
     "backgroundTextStyle": "light",

+ 81 - 0
pages/auth/auth.js

@@ -0,0 +1,81 @@
+// pages/auth/auth.js
+const app = getApp();
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    canIUse: wx.canIUse('button.open-type.getUserInfo')
+  },
+  onAuth() {
+    wx.getSetting({
+      success: (res) => {
+        if (res.authSetting['scope.userInfo']) {
+          wx.reLaunch({
+            url: '/pages/index/index',
+          })
+        }
+      }
+    })
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+    wx.hideHomeButton({
+      success: function() {
+      },
+    })
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 4 - 0
pages/auth/auth.json

@@ -0,0 +1,4 @@
+{
+  "navigationBarTitleText": "用户授权",
+  "usingComponents": {}
+}

+ 9 - 0
pages/auth/auth.wxml

@@ -0,0 +1,9 @@
+<!--pages/auth/auth.wxml-->
+<view class="auth">
+  <!-- <image src="https://res.wx.qq.com/wxopenres/htmledition/images/favicon32f740.ico" class="img" mode="aspectFill"></image> -->
+  <image src="./images/logo.jpg" class="img" mode="aspectFill"></image>
+  <view class="title">微信授权页面</view>
+  <view class="describe">此页面是微信授权页面,点击下方按钮弹出授权或跳转页面</view>
+  <button class="btn" open-type='getUserInfo' wx:if="{{canIUse}}" bindgetuserinfo='onAuth'>点击微信授权</button>
+  <navigator wx:if="{{!canIUse}}" class="btn" url="/pages/auth/auth" open-type="reLaunch" hover-class="other-navigator-hover">已经授权点击调转</navigator>
+</view>

+ 70 - 0
pages/auth/auth.wxss

@@ -0,0 +1,70 @@
+/* pages/auth/auth.wxss */
+/* 开始 */
+page {
+  height: 100%;
+  display: table;
+}
+ 
+.auth {
+  margin-top: 0;
+  text-align: center;
+  display: table-cell;
+  flex-direction: column;
+  flex-wrap: wrap;
+  justify-content: center;
+  align-items: flex-start;
+  padding: 100rpx;
+  vertical-align: middle;
+}
+ 
+.img {
+  border-radius: 50%;
+  /* border: 1px solid #fff; */
+  /* background-color: #fff; */
+  margin: 0 0 60rpx;
+  display: inline-block;
+  width: 200rpx;
+  height: 200rpx;
+  line-height: 0;
+}
+ 
+.title {
+  display: inline-block;
+  width: 100%;
+  margin: 0 0 60rpx;
+}
+ 
+.describe {
+  color: #a7aaa9;
+  font-size: 26rpx;
+  margin: 0 0 60rpx;
+  border-radius: 50%;
+  text-align: center;
+  display: inline-block;
+  width: 100%;
+}
+ 
+.btn {
+  padding: 0 60rpx;
+  background-color: #19be6b;
+  color: #ffffff;
+  margin: 20rpx 0 200rpx;
+  text-align: center;
+  vertical-align: middle;
+  touch-action: manipulation;
+  cursor: pointer;
+  background-image: none;
+  white-space: nowrap;
+  user-select: none;
+  font-size: 14px;
+  border: 0 !important;
+  position: relative;
+  text-decoration: none;
+  height: 44px;
+  line-height: 44px;
+  box-shadow: inset 0 0 0 1px #19be6b;  
+  /* background: #fff !important; */
+  /* color: #19be6b !important; */
+  display: inline-block;
+  border-radius: 10rpx;
+}

二进制
pages/auth/images/logo.jpg


+ 0 - 2
pages/index/index.js

@@ -118,8 +118,6 @@ Page({
         reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
         time:"5天前"
       },
-
- 
     ],
 
   },

+ 3 - 3
project.config.json

@@ -20,15 +20,15 @@
 		"checkInvalidKey": true,
 		"checkSiteMap": true,
 		"uploadWithSourceMap": true,
-		"compileHotReLoad": false,
 		"babelSetting": {
 			"ignore": [],
 			"disablePlugins": [],
 			"outputPath": ""
 		},
-		"useIsolateContext": true,
 		"useCompilerModule": true,
-		"userConfirmedUseCompilerModuleSwitch": false
+		"userConfirmedUseCompilerModuleSwitch": false,
+		"compileHotReLoad": false,
+		"useIsolateContext": true
 	},
 	"compileType": "miniprogram",
 	"libVersion": "2.11.1",