mobilePhone.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. import { J_STORAGE_KEY } from '../../config/constant'
  22. const NET = require('../../utils/request')
  23. const API = require('../../config/api')
  24. export default {
  25. data() {
  26. return {
  27. avatarUrl: ''
  28. }
  29. },
  30. onLoad(options) {
  31. this.avatarUrl = uni.getStorageSync('avatarUrl')
  32. },
  33. onBackPress(options) {
  34. this.back()
  35. return true
  36. },
  37. methods: {
  38. back() {
  39. uni.switchTab({
  40. url: 'login'
  41. })
  42. },
  43. getPhoneNumber(e) {
  44. if (e.detail.errMsg === 'getPhoneNumber:ok') {
  45. const that = this
  46. uni.login({
  47. provider: 'weixin',
  48. success: (res) => {
  49. that.code = res.code
  50. NET.request(API.GetSessionKey, {
  51. code: that.code
  52. }, 'POST').then((res1) => {
  53. NET.request(API.SetWxPhone, {
  54. wechatOpenId: res1.data.wechatOpenId,
  55. sessionKey: res1.data.sessionKey,
  56. encryptedData: e.detail.encryptedData,
  57. iv: e.detail.iv,
  58. headImage: this.avatarUrl
  59. }, 'POST').then((res2) => {
  60. const item = res2.data
  61. uni.setStorageSync(J_STORAGE_KEY, item)
  62. setTimeout(() => {
  63. this.$switchTab('/pages/tabbar/user/index')
  64. uni.hideLoading()
  65. }, 1000)
  66. })
  67. .catch((res) => {
  68. })
  69. })
  70. .catch((err) => {
  71. })
  72. },
  73. fail: () => {
  74. uni.showToast({
  75. title: '微信登录授权失败',
  76. icon: 'none'
  77. })
  78. }
  79. })
  80. } else {
  81. uni.showToast({
  82. title: '获取手机授权失败',
  83. icon: 'none'
  84. })
  85. }
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss">
  91. .container {
  92. .login-logoBox {
  93. margin-top: 154upx;
  94. .login-logo {
  95. width: 250upx;
  96. height: 250upx;
  97. }
  98. }
  99. .loginTitle-text {
  100. margin-top: 222upx;
  101. }
  102. .loginWxBut {
  103. background-image: linear-gradient(135deg, #FFA100 10%, #FF7911 100%);
  104. color: #FFFFFF;
  105. height: 88upx;
  106. width: 600upx;
  107. text-align: center;
  108. line-height: 88upx;
  109. border-radius: 88upx;
  110. margin-top: 49upx;
  111. }
  112. .loginBut {
  113. background-color: #FFFFFF;
  114. color: #C5AA7B;
  115. height: 88upx;
  116. width: 600upx;
  117. text-align: center;
  118. line-height: 88upx;
  119. border-radius: 88upx;
  120. border: 2upx solid #C5AA7B;
  121. margin-top: 30upx;
  122. }
  123. .register-text {
  124. color: #47A7EE;
  125. }
  126. }
  127. </style>