index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <view class="auth">
  3. <image src="../../static/rabotHead.png" mode=""></image>
  4. <text class="margin-top-3 auth-title">欢迎使用阿拉灯神丁</text>
  5. <text class="margin-top-3 auth-content">此页面是微信授权页面,授权之后你可以获取更优质的服务,您的隐私将会受到保护</text>
  6. <view class="margin-top-3">
  7. <button type='default' class="refuse" @click="refuseBtn">暂不授权</button>
  8. <button type='primary' class="allow" open-type="getUserInfo" @getuserinfo="getUserInfo">允许授权</button>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. var md5 = require("../../common/md5.js");
  14. export default {
  15. data(){
  16. return {
  17. iv:'',
  18. encryptedData:''
  19. }
  20. },
  21. onLoad() {
  22. },
  23. methods:{
  24. getUserInfo(e) {
  25. console.log(e);
  26. if (e.detail.errMsg == "getUserInfo:ok") {
  27. this.iv = e.detail.iv;
  28. this.encryptedData = e.detail.encryptedData;
  29. this.loginUserInfo()
  30. } else {
  31. console.log("用户信息授权失败");
  32. getApp().globalData.isAuth = false;
  33. }
  34. },
  35. refuseBtn(){
  36. uni.navigateBack({
  37. });
  38. },
  39. loginUserInfo(){
  40. let that = this;
  41. uni.request({
  42. url:getApp().globalData.shareUrl, //需要设置为全局
  43. method: 'POST',
  44. header: {
  45. 'content-type': 'application/x-www-form-urlencoded'
  46. },
  47. data: {
  48. method: 'auth',
  49. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  50. uid:getApp().globalData.user_id,
  51. sign: md5('auth' + getApp().globalData.globalTimestamp),
  52. nickname:getApp().globalData.user_name,
  53. headimg:getApp().globalData.user_headUrl,
  54. iv:that.iv,
  55. session_key:getApp().globalData.session_key,
  56. encryptedData:that.encryptedData
  57. },
  58. success: res => {
  59. getApp().globalData.user_id = res.data.msg.id;
  60. getApp().globalData.open_id = res.data.msg.openid;
  61. getApp().globalData.isAuth = true;
  62. getApp().globalData.times = res.data.msg.times;
  63. getApp().globalData.total_times = res.data.msg.total_times;
  64. getApp().globalData.user_headUrl = res.data.msg.headimg;
  65. getApp().globalData.user_name = res.data.msg.name;
  66. uni.navigateBack({
  67. });
  68. }
  69. });
  70. },
  71. }
  72. }
  73. </script>
  74. <style>
  75. .auth{
  76. margin-top: 0;
  77. text-align: center;
  78. display: flex;
  79. flex-direction: column;
  80. justify-content: center;
  81. align-items: center;
  82. padding: 100upx;
  83. vertical-align: middle;
  84. }
  85. .auth image{
  86. width: 200upx;
  87. height: 200upx;
  88. }
  89. .auth view {
  90. display: flex;
  91. width: 490upx;
  92. justify-content: space-between;
  93. }
  94. .auth-title {
  95. font-size: 32upx;
  96. }
  97. .auth-content {
  98. font-size: 26upx;
  99. color: #a7aaa9;
  100. }
  101. .allow {
  102. background-color: #27BCEF;
  103. margin: 20rpx 0 200rpx;
  104. text-align: center;
  105. vertical-align: middle;
  106. touch-action: manipulation;
  107. cursor: pointer;
  108. background-image: none;
  109. white-space: nowrap;
  110. user-select: none;
  111. font-size: 14px;
  112. border: 0 !important;
  113. position: relative;
  114. text-decoration: none;
  115. height: 44px;
  116. width: 250rpx;
  117. line-height: 44px;
  118. box-shadow: inset 0 0 0 1px #27BCEF;
  119. background: #fff !important;
  120. color: #27BCEF !important;
  121. display: inline-block;
  122. border-radius: 10rpx;
  123. }
  124. .refuse {
  125. background-color: #19be6b;
  126. margin: 20rpx 20rpx 200rpx 20rpx;
  127. text-align: center;
  128. vertical-align: middle;
  129. touch-action: manipulation;
  130. cursor: pointer;
  131. background-image: none;
  132. white-space: nowrap;
  133. user-select: none;
  134. font-size: 14px;
  135. border: 0 !important;
  136. position: relative;
  137. text-decoration: none;
  138. height: 44px;
  139. width: 250rpx;
  140. line-height: 44px;
  141. box-shadow: inset 0 0 0 1px #8a8a8a;
  142. background: #fff !important;
  143. color: #8a8a8a !important;
  144. display: inline-block;
  145. border-radius: 10rpx;
  146. }
  147. .margin-top-3{
  148. margin-top: 10%;
  149. }
  150. </style>