index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="auth">
  3. <image src="/static/detail-bg2.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" v-if="!isAuth">登录授权</button>
  9. <button type="primary" class="allow" open-type="getPhoneNumber" style="font-size: 12px;"
  10. @getphonenumber="getPhoneNumber" v-if="isAuth && !isNeedPhone">手机号码授权</button>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. var md5 = require("../../common/md5.js");
  16. export default {
  17. data(){
  18. return {
  19. iv:'',
  20. encryptedData:'',
  21. isNeedPhone:getApp().globalData.user_phone,
  22. isAuth:getApp().globalData.isAuth
  23. }
  24. },
  25. onLoad() {
  26. },
  27. methods:{
  28. getUserInfo(e) {
  29. if (e.detail.errMsg == "getUserInfo:ok") {
  30. console.log(e)
  31. getApp().globalData.user_headUrl = e.detail.userInfo.avatarUrl;
  32. getApp().globalData.user_name = e.detail.userInfo.nickName;
  33. this.iv = e.detail.iv;
  34. this.encryptedData = e.detail.encryptedData;
  35. this.loginUserInfo()
  36. } else {
  37. console.log("用户信息授权失败");
  38. getApp().globalData.isAuth = false;
  39. }
  40. },
  41. getPhoneNumber(e){
  42. let that = this;
  43. if (e.detail.errMsg == 'getPhoneNumber:ok') { //允许授权执行跳转
  44. that.phoneRequest(e.detail.iv, e.detail.encryptedData, getApp().globalData.session_key)
  45. } else { //
  46. that.isNeedPhone = false;
  47. }
  48. },
  49. phoneRequest(myIv,myEncryptedData,sKey){
  50. let that = this;
  51. uni.request({
  52. url:getApp().globalData.shareUrl, //需要设置为全局
  53. method: 'POST',
  54. header: {
  55. 'content-type': 'application/x-www-form-urlencoded'
  56. },
  57. data: {
  58. method: 'getPhoneNumber',
  59. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  60. uid:getApp().globalData.user_id,
  61. sign: md5('getPhoneNumber' + getApp().globalData.globalTimestamp),
  62. iv:myIv,
  63. sessionKey:sKey,
  64. encryptedData:myEncryptedData,
  65. },
  66. success: res => {
  67. console.log(res)
  68. }
  69. });
  70. },
  71. refuseBtn(){
  72. uni.navigateBack({
  73. });
  74. },
  75. loginUserInfo(){
  76. let that = this;
  77. uni.request({
  78. url:getApp().globalData.shareUrl, //需要设置为全局
  79. method: 'POST',
  80. header: {
  81. 'content-type': 'application/x-www-form-urlencoded'
  82. },
  83. data: {
  84. method: 'auth',
  85. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  86. id:getApp().globalData.user_id,
  87. sign: md5('auth' + getApp().globalData.globalTimestamp),
  88. nickname:getApp().globalData.user_name,
  89. headimg:getApp().globalData.user_headUrl,
  90. // iv:that.iv,
  91. // session_key:getApp().globalData.session_key,
  92. // encryptedData:that.encryptedData,
  93. auth_status:1,
  94. shangjiid:getApp().globalData.lastId
  95. },
  96. success: res => {
  97. getApp().globalData.user_id = res.data.msg.id;
  98. getApp().globalData.open_id = res.data.msg.openid;
  99. getApp().globalData.isAuth = true;
  100. getApp().globalData.user_headUrl = res.data.msg.headimg;
  101. getApp().globalData.user_name = res.data.msg.name;
  102. getApp().globalData.user_status = res.data.msg.status;
  103. getApp().globalData.user_phone = res.data.msg.phone;
  104. // uni.navigateBack({
  105. // });
  106. }
  107. });
  108. },
  109. }
  110. }
  111. </script>
  112. <style>
  113. .auth{
  114. margin-top: 0;
  115. text-align: center;
  116. display: flex;
  117. flex-direction: column;
  118. justify-content: center;
  119. align-items: center;
  120. padding: 100upx;
  121. vertical-align: middle;
  122. }
  123. .auth image{
  124. width: 200upx;
  125. height: 200upx;
  126. }
  127. .auth view {
  128. display: flex;
  129. width: 490upx;
  130. justify-content: space-between;
  131. }
  132. .auth-title {
  133. font-size: 32upx;
  134. }
  135. .auth-content {
  136. font-size: 26upx;
  137. color: #a7aaa9;
  138. }
  139. .allow {
  140. background-color: #27BCEF;
  141. margin: 20rpx 0 200rpx;
  142. text-align: center;
  143. vertical-align: middle;
  144. touch-action: manipulation;
  145. cursor: pointer;
  146. background-image: none;
  147. white-space: nowrap;
  148. user-select: none;
  149. font-size: 14px;
  150. border: 0 !important;
  151. position: relative;
  152. text-decoration: none;
  153. height: 44px;
  154. width: 250rpx;
  155. line-height: 44px;
  156. box-shadow: inset 0 0 0 1px #27BCEF;
  157. background: #fff !important;
  158. color: #27BCEF !important;
  159. display: inline-block;
  160. border-radius: 10rpx;
  161. }
  162. .refuse {
  163. background-color: #19be6b;
  164. margin: 20rpx 20rpx 200rpx 20rpx;
  165. text-align: center;
  166. vertical-align: middle;
  167. touch-action: manipulation;
  168. cursor: pointer;
  169. background-image: none;
  170. white-space: nowrap;
  171. user-select: none;
  172. font-size: 14px;
  173. border: 0 !important;
  174. position: relative;
  175. text-decoration: none;
  176. height: 44px;
  177. width: 250rpx;
  178. line-height: 44px;
  179. box-shadow: inset 0 0 0 1px #8a8a8a;
  180. background: #fff !important;
  181. color: #8a8a8a !important;
  182. display: inline-block;
  183. border-radius: 10rpx;
  184. }
  185. .margin-top-3{
  186. margin-top: 10%;
  187. }
  188. </style>