bindmobile.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="login-container">
  3. <view class="wechatapp">
  4. <view class="header">
  5. <open-data class="" type="userAvatarUrl"></open-data>
  6. </view>
  7. </view>
  8. <view class="auth-title">申请获取以下权限</view>
  9. <view class="auth-subtitle">为了为您提供更优质的服务,我们需要获得你的手机号</view>
  10. <view class="login-btn">
  11. <!-- #ifdef MP-WEIXIN -->
  12. <button open-type="getPhoneNumber" class="btn-normal" @getphonenumber="getPhoneNumber">授权获取</button>
  13. <!-- #endif -->
  14. </view>
  15. <view class="no-login-btn">
  16. <button class="btn-normal" @click="onNotLogin">暂不授权</button>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. background: '',
  25. listData: [],
  26. sessionKey: ''
  27. }
  28. },
  29. onLoad() {
  30. let self = this;
  31. wx.login({
  32. success(res) {
  33. // 发送用户信息
  34. self._post('user.user/getSession', {
  35. code: res.code
  36. }, result => {
  37. self.sessionKey = result.data.session_key;
  38. });
  39. }
  40. });
  41. },
  42. methods: {
  43. onNotLogin: function() {
  44. uni.switchTab({
  45. url: '/pages/index/index'
  46. })
  47. },
  48. getPhoneNumber(e) {
  49. var self = this;
  50. if (e.detail.errMsg !== 'getPhoneNumber:ok') {
  51. return false;
  52. }
  53. uni.showLoading({
  54. title: "正在处理",
  55. mask: true
  56. });
  57. // 发送用户信息
  58. self._post('user.user/bindMobile', {
  59. session_key: self.sessionKey,
  60. encrypted_data: e.detail.encryptedData,
  61. iv: e.detail.iv,
  62. }, result => {
  63. // 执行回调函数
  64. uni.navigateBack();
  65. }, false, () => {
  66. uni.hideLoading();
  67. });
  68. },
  69. },
  70. }
  71. </script>
  72. <style>
  73. .login-container {
  74. padding: 30rpx;
  75. }
  76. .wechatapp {
  77. padding: 80rpx 0 48rpx;
  78. border-bottom: 1rpx solid #e3e3e3;
  79. margin-bottom: 72rpx;
  80. text-align: center;
  81. }
  82. .wechatapp .header {
  83. width: 190rpx;
  84. height: 190rpx;
  85. border: 2px solid #fff;
  86. margin: 0rpx auto 0;
  87. border-radius: 50%;
  88. overflow: hidden;
  89. box-shadow: 1px 0px 5px rgba(50, 50, 50, 0.3);
  90. }
  91. .auth-title {
  92. color: #585858;
  93. font-size: 34rpx;
  94. margin-bottom: 40rpx;
  95. }
  96. .auth-subtitle {
  97. color: #888;
  98. margin-bottom: 88rpx;
  99. font-size: 28rpx;
  100. }
  101. .login-btn {
  102. padding: 0 20rpx;
  103. }
  104. .login-btn button {
  105. height: 88rpx;
  106. line-height: 88rpx;
  107. background: #04be01;
  108. color: #fff;
  109. font-size: 30rpx;
  110. border-radius: 999rpx;
  111. text-align: center;
  112. }
  113. .no-login-btn {
  114. margin-top: 20rpx;
  115. padding: 0 20rpx;
  116. }
  117. .no-login-btn button {
  118. height: 88rpx;
  119. line-height: 88rpx;
  120. background: #dfdfdf;
  121. color: #fff;
  122. font-size: 30rpx;
  123. border-radius: 999rpx;
  124. text-align: center;
  125. }
  126. </style>