routine_phone.vue 3.2 KB

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