routine_phone.vue 3.2 KB

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