routine_phone.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view v-if="isPhoneBox">
  3. <view class="mobile-bg"></view>
  4. <view class="mobile-mask animated" :class="{slideInUp:isUp}">
  5. <view class="info-box">
  6. <image :src="logoUrl"></image>
  7. <view class="title">{{$t(`获取授权`)}}</view>
  8. <view class="txt">{{$t(`获取微信的手机号授权`)}}</view>
  9. </view>
  10. <button class="sub_btn" open-type="getPhoneNumber"
  11. @getphonenumber="getphonenumber">{{$t(`获取微信手机号`)}}</button>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. const app = getApp();
  17. import Routine from '@/libs/routine';
  18. import {
  19. loginMobile,
  20. getCodeApi,
  21. getUserInfo
  22. } from "@/api/user";
  23. import {
  24. getLogo,
  25. silenceAuth,
  26. getUserPhone
  27. } from '@/api/public';
  28. export default {
  29. name: 'routine_phone',
  30. props: {
  31. isPhoneBox: {
  32. type: Boolean,
  33. default: false,
  34. },
  35. logoUrl: {
  36. type: String,
  37. default: '',
  38. },
  39. authKey: {
  40. type: String,
  41. default: '',
  42. }
  43. },
  44. data() {
  45. return {
  46. keyCode: '',
  47. account: '',
  48. codeNum: '',
  49. isStatus: false
  50. }
  51. },
  52. mounted() {},
  53. methods: {
  54. // #ifdef MP
  55. // 小程序获取手机号码
  56. getphonenumber(e) {
  57. uni.showLoading({
  58. title: this.$t(`正在登录中`)
  59. });
  60. Routine.getCode()
  61. .then(code => {
  62. this.getUserPhoneNumber(e.detail.encryptedData, e.detail.iv, code);
  63. })
  64. .catch(error => {
  65. uni.hideLoading();
  66. });
  67. },
  68. // 小程序获取手机号码回调
  69. getUserPhoneNumber(encryptedData, iv, code) {
  70. getUserPhone({
  71. encryptedData: encryptedData,
  72. iv: iv,
  73. code: code,
  74. spread_spid: app.globalData.spid,
  75. spread_code: app.globalData.code,
  76. key: this.authKey
  77. })
  78. .then(res => {
  79. let time = res.data.expires_time - this.$Cache.time();
  80. this.$store.commit('LOGIN', {
  81. token: res.data.token,
  82. time: time
  83. });
  84. // this.getUserInfo();
  85. this.$emit('loginSuccess', {
  86. isStatus: true,
  87. new_user: res.data.userInfo.new_user
  88. })
  89. })
  90. .catch(res => {
  91. uni.hideLoading();
  92. });
  93. },
  94. /**
  95. * 获取个人用户信息
  96. */
  97. getUserInfo: function() {
  98. let that = this;
  99. getUserInfo().then(res => {
  100. uni.hideLoading();
  101. that.userInfo = res.data
  102. that.$store.commit("SETUID", res.data.uid);
  103. that.$store.commit("UPDATE_USERINFO", res.data);
  104. that.isStatus = true
  105. this.close(res.data.new_user || 0)
  106. });
  107. },
  108. // #endif
  109. close(new_user) {
  110. this.$emit('close', {
  111. isStatus: this.isStatus,
  112. new_user
  113. })
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss">
  119. .mobile-bg {
  120. position: fixed;
  121. left: 0;
  122. top: 0;
  123. width: 100%;
  124. height: 100%;
  125. background: rgba(0, 0, 0, 0.5);
  126. }
  127. .mobile-mask {
  128. z-index: 20;
  129. position: fixed;
  130. left: 0;
  131. bottom: 0;
  132. width: 100%;
  133. padding: 67rpx 30rpx;
  134. background: #fff;
  135. .info-box {
  136. display: flex;
  137. flex-direction: column;
  138. align-items: center;
  139. justify-content: center;
  140. image {
  141. width: 150rpx;
  142. height: 150rpx;
  143. border-radius: 10rpx;
  144. }
  145. .title {
  146. margin-top: 30rpx;
  147. margin-bottom: 20rpx;
  148. font-size: 36rpx;
  149. }
  150. .txt {
  151. font-size: 30rpx;
  152. color: #868686;
  153. }
  154. }
  155. .sub_btn {
  156. width: 690rpx;
  157. height: 86rpx;
  158. line-height: 86rpx;
  159. margin-top: 60rpx;
  160. background: var(--view-theme);
  161. border-radius: 43rpx;
  162. color: #fff;
  163. font-size: 28rpx;
  164. text-align: center;
  165. }
  166. }
  167. .animated {
  168. animation-duration: .4s
  169. }
  170. </style>