routine_phone.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <!-- 授权弹窗 -->
  3. <view v-if="isPhoneBox" :style="colorStyle">
  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. import colors from '@/mixins/color.js';
  27. export default{
  28. name:'routine_phone',
  29. mixins:[colors],
  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. },
  54. methods:{
  55. // #ifdef MP
  56. // 小程序获取手机号码
  57. getphonenumber(e){
  58. uni.showLoading({ title: '正在登录中' });
  59. Routine.getCode()
  60. .then(code => {
  61. this.getUserPhoneNumber(e.detail.encryptedData, e.detail.iv, code);
  62. })
  63. .catch(error => {
  64. uni.hideLoading();
  65. });
  66. },
  67. // 小程序获取手机号码回调
  68. getUserPhoneNumber(encryptedData, iv, code) {
  69. getUserPhone({
  70. encryptedData: encryptedData,
  71. iv: iv,
  72. code: code,
  73. spread_spid: app.globalData.spid,
  74. spread_code: app.globalData.code,
  75. key:this.authKey
  76. })
  77. .then(res => {
  78. let time = res.data.expires_time - this.$Cache.time();
  79. this.$store.commit('LOGIN', {
  80. token: res.data.token,
  81. time: time
  82. });
  83. // this.getUserInfo();
  84. this.$emit('close', {
  85. isStatus: true,
  86. store_user_avatar: res.data.userInfo.store_user_avatar
  87. })
  88. })
  89. .catch(res => {
  90. this.$util.Tips({
  91. title: res
  92. });
  93. uni.hideLoading();
  94. });
  95. },
  96. /**
  97. * 获取个人用户信息
  98. */
  99. getUserInfo: function() {
  100. let that = this;
  101. getUserInfo().then(res => {
  102. uni.hideLoading();
  103. that.userInfo = res.data
  104. that.$store.commit("SETUID", res.data.uid);
  105. that.$store.commit("UPDATE_USERINFO", res.data);
  106. that.isStatus = true
  107. this.close(res.data.store_user_avatar || 0)
  108. });
  109. },
  110. // #endif
  111. close(store_user_avatar) {
  112. this.$emit('close', {
  113. isStatus: this.isStatus,
  114. store_user_avatar
  115. })
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="scss">
  121. .mobile-bg{
  122. position: fixed;
  123. left: 0;
  124. top: 0;
  125. width: 100%;
  126. height: 100%;
  127. background: rgba(0,0,0,0.5);
  128. z-index: 667;
  129. }
  130. .mobile-mask {
  131. z-index: 668;
  132. position: fixed;
  133. left: 0;
  134. bottom: 0;
  135. width: 100%;
  136. padding: 67rpx 30rpx;
  137. background: #fff;
  138. height: 560rpx;
  139. border-radius: 48rpx 48rpx 0 0;
  140. .info-box{
  141. display:flex;
  142. flex-direction: column;
  143. align-items: center;
  144. justify-content: center;
  145. image{
  146. width: 150rpx;
  147. height: 150rpx;
  148. border-radius: 10rpx;
  149. }
  150. .title{
  151. margin-top: 30rpx;
  152. margin-bottom: 20rpx;
  153. font-size: 36rpx;
  154. }
  155. .txt{
  156. font-size: 30rpx;
  157. color: #868686;
  158. }
  159. }
  160. .sub_btn{
  161. width: 536rpx;
  162. height: 86rpx;
  163. line-height: 86rpx;
  164. margin: 60rpx auto 0 auto;
  165. background: var(--view-theme);
  166. border-radius: 43rpx;
  167. color: #fff;
  168. font-size: 28rpx;
  169. text-align: center;
  170. }
  171. }
  172. .animated{
  173. animation-duration:.4s
  174. }
  175. </style>