routine_phone.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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">获取授权</view>
  8. <view class="txt">获取微信的手机号授权</view>
  9. </view>
  10. <button class="sub_btn" open-type="getPhoneNumber" @getphonenumber="getphonenumber">获取微信手机号</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: '加载中' });
  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. console.log(res);
  83. uni.hideLoading();
  84. });
  85. },
  86. /**
  87. * 获取个人用户信息
  88. */
  89. getUserInfo: function() {
  90. let that = this;
  91. getUserInfo().then(res => {
  92. uni.hideLoading();
  93. that.userInfo = res.data
  94. that.$store.commit("SETUID", res.data.uid);
  95. that.$store.commit("UPDATE_USERINFO", res.data);
  96. that.isStatus = true
  97. this.close()
  98. });
  99. },
  100. // #endif
  101. close(){
  102. this.$emit('close',{isStatus:this.isStatus})
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="scss">
  108. .mobile-bg{
  109. position: fixed;
  110. left: 0;
  111. top: 0;
  112. width: 100%;
  113. height: 100%;
  114. background: rgba(0,0,0,0.5);
  115. }
  116. .mobile-mask {
  117. z-index: 20;
  118. position: fixed;
  119. left: 0;
  120. bottom: 0;
  121. width: 100%;
  122. padding: 67rpx 30rpx;
  123. background: #fff;
  124. .info-box{
  125. display:flex;
  126. flex-direction: column;
  127. align-items: center;
  128. justify-content: center;
  129. image{
  130. width: 150rpx;
  131. height: 150rpx;
  132. border-radius: 10rpx;
  133. }
  134. .title{
  135. margin-top: 30rpx;
  136. margin-bottom: 20rpx;
  137. font-size: 36rpx;
  138. }
  139. .txt{
  140. font-size: 30rpx;
  141. color: #868686;
  142. }
  143. }
  144. .sub_btn{
  145. width: 690rpx;
  146. height: 86rpx;
  147. line-height: 86rpx;
  148. margin-top: 60rpx;
  149. background: #E93323;
  150. border-radius: 43rpx;
  151. color: #fff;
  152. font-size: 28rpx;
  153. text-align: center;
  154. }
  155. }
  156. .animated{
  157. animation-duration:.4s
  158. }
  159. </style>