mobilePhone.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="container flex-items-plus flex-column">
  3. <view class="login-logoBox">
  4. <image class="login-logo" src="../../static/images/origin/loginLogo.png"></image>
  5. </view>
  6. <view class="loginTitle-text flex-column-plus flex-items font-color-666 fs26">
  7. <label>为了给您提供更好的服务</label>
  8. <label>我们需要您的授权哦~</label>
  9. </view>
  10. <view>
  11. <button
  12. class="loginWxBut fs28 mar-top-100" open-type="getPhoneNumber"
  13. @getphonenumber="getPhoneNumber"
  14. >
  15. 微信手机号授权
  16. </button>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. const NET = require('../../utils/request')
  22. const API = require('../../config/api')
  23. export default {
  24. data() {
  25. return {
  26. avatarUrl: ''
  27. }
  28. },
  29. onLoad(options) {
  30. this.avatarUrl = uni.getStorageSync('avatarUrl')
  31. },
  32. onBackPress(options) {
  33. this.back()
  34. return true
  35. },
  36. methods: {
  37. back() {
  38. uni.switchTab({
  39. url: 'login'
  40. })
  41. },
  42. getPhoneNumber(e) {
  43. if (e.detail.errMsg === 'getPhoneNumber:ok') {
  44. const that = this
  45. uni.login({
  46. provider: 'weixin',
  47. success: (res) => {
  48. that.code = res.code
  49. NET.request(API.GetSessionKey, {
  50. code: that.code
  51. }, 'POST').then((res1) => {
  52. NET.request(API.SetWxPhone, {
  53. wechatOpenId: res1.data.wechatOpenId,
  54. sessionKey: res1.data.sessionKey,
  55. encryptedData: e.detail.encryptedData,
  56. iv: e.detail.iv,
  57. headImage: this.avatarUrl
  58. }, 'POST').then((res2) => {
  59. const item = res2.data
  60. uni.setStorageSync('storage_key', item)
  61. setTimeout(function () {
  62. uni.switchTab({
  63. url: '../../pages/tabbar/user/index',
  64. success() {
  65. uni.hideLoading()
  66. }
  67. })
  68. }, 1000)
  69. })
  70. .catch((res) => {
  71. })
  72. })
  73. .catch((err) => {
  74. })
  75. },
  76. fail: () => {
  77. uni.showToast({
  78. title: '微信登录授权失败',
  79. icon: 'none'
  80. })
  81. }
  82. })
  83. } else {
  84. uni.showToast({
  85. title: '获取手机授权失败',
  86. icon: 'none'
  87. })
  88. }
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss">
  94. .container {
  95. .login-logoBox {
  96. margin-top: 154upx;
  97. .login-logo {
  98. width: 250upx;
  99. height: 250upx;
  100. }
  101. }
  102. .loginTitle-text {
  103. margin-top: 222upx;
  104. }
  105. .loginWxBut {
  106. background-image: linear-gradient(135deg, #FFA100 10%, #FF7911 100%);
  107. color: #FFFFFF;
  108. height: 88upx;
  109. width: 600upx;
  110. text-align: center;
  111. line-height: 88upx;
  112. border-radius: 88upx;
  113. margin-top: 49upx;
  114. }
  115. .loginBut {
  116. background-color: #FFFFFF;
  117. color: #C5AA7B;
  118. height: 88upx;
  119. width: 600upx;
  120. text-align: center;
  121. line-height: 88upx;
  122. border-radius: 88upx;
  123. border: 2upx solid #C5AA7B;
  124. margin-top: 30upx;
  125. }
  126. .register-text {
  127. color: #47A7EE;
  128. }
  129. }
  130. </style>