Authorize.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view>
  3. <view class='Popup' v-if='isShowAuth'>
  4. <view class="logo-auth">
  5. <image :src='logoUrl' mode="aspectFit"></image>
  6. </view>
  7. <view class='title'>授权提醒</view>
  8. <view class='tip'>请授权头像等信息,以便为您提供更好的服务</view>
  9. <view class='bottom flex'>
  10. <view class='item' @click='close'>随便逛逛</view>
  11. <!-- #ifdef APP-PLUS
  12. <button class='item grant' @click="setUserInfo">去授权</button>
  13. #endif -->
  14. <!-- #ifdef MP -->
  15. <button class='item grant' type="primary" open-type="getUserInfo" lang="zh_CN" @getuserinfo="setUserInfo">去授权</button>
  16. <!-- #endif -->
  17. </view>
  18. </view>
  19. <view class='mask' v-if='isShowAuth' @click='close'></view>
  20. </view>
  21. </template>
  22. <script>
  23. const app = getApp();
  24. import Cache from '../utils/cache';
  25. import { getLogo } from '../api/public';
  26. import { LOGO_URL } from '../config/cache';
  27. import { mapGetters } from 'vuex';
  28. import Routine from '../libs/routine';
  29. export default {
  30. name:'Authorize',
  31. props:{
  32. isAuto:{
  33. type:Boolean,
  34. default:true
  35. },
  36. isGoIndex:{
  37. type:Boolean,
  38. default:true
  39. },
  40. isShowAuth:{
  41. type:Boolean,
  42. default:false
  43. }
  44. },
  45. data(){
  46. return {
  47. logoUrl:''
  48. }
  49. },
  50. computed:mapGetters(['isLogin','userInfo']),
  51. watch:{
  52. isLogin(n){
  53. n === true && this.$emit('onLoadFun',this.userInfo);
  54. }
  55. },
  56. created() {
  57. this.getLogoUrl();
  58. this.setAuthStatus();
  59. },
  60. methods:{
  61. setAuthStatus(){
  62. Routine.authorize().then(res=>{
  63. if(res.islogin === false)
  64. this.setUserInfo();
  65. else
  66. this.$emit('onLoadFun',this.userInfo);
  67. }).catch(res=>{
  68. if (this.isAuto)
  69. this.$emit('authColse',true);
  70. })
  71. },
  72. getUserInfo(code){
  73. Routine.getUserInfo().then(res=>{
  74. let userInfo = res.userInfo
  75. userInfo.code = code;
  76. userInfo.spread_spid = app.globalData.spid;//获取推广人ID
  77. userInfo.spread_code = app.globalData.code;//获取推广人分享二维码ID
  78. Routine.authUserInfo(userInfo).then(res=>{
  79. uni.hideLoading();
  80. this.$emit('authColse',false);
  81. this.$emit('onLoadFun',this.userInfo);
  82. }).catch(res=>{
  83. uni.hideLoading();
  84. uni.showToast({
  85. title:res.msg,
  86. icon:'none',
  87. duration:2000
  88. });
  89. })
  90. }).catch(res =>{
  91. uni.hideLoading();
  92. })
  93. },
  94. setUserInfo(){
  95. uni.showLoading({title:'正在登录中'});
  96. Routine.getCode().then(code=>{
  97. console.log(code,'GGGGGGGGGGGGG');
  98. uni.navigateTo({
  99. url:"/pages/users/login/index?key=4"
  100. })
  101. this.getUserInfo(code);
  102. }).catch(res=>{
  103. uni.hideLoading();
  104. })
  105. },
  106. getLogoUrl(){
  107. this.logoUrl = app.globalData.site_logo
  108. // let that = this;
  109. // if (Cache.has(LOGO_URL)) {
  110. // this.logoUrl = Cache.get(LOGO_URL);
  111. // return;
  112. // }
  113. // getLogo().then(res=>{
  114. // that.logoUrl = res.data.logo_url
  115. // Cache.set(LOGO_URL,that.logoUrl);
  116. // })
  117. },
  118. close(){
  119. let pages = getCurrentPages(), currPage = pages[pages.length - 1];
  120. if(this.isGoIndex){
  121. uni.switchTab({url:'/pages/index/index'});
  122. } else {
  123. this.$emit('authColse',false);
  124. }
  125. // if (currPage && currPage.isShowAuth != undefined){
  126. // currPage.isShowAuth = true;
  127. // }
  128. },
  129. }
  130. }
  131. </script>
  132. <style scoped lang='scss'>
  133. .Popup{width:500rpx;background-color:#fff;position:fixed;top:50%;left:50%;margin-left:-250rpx;transform:translateY(-50%);z-index:320;}
  134. .Popup{
  135. .logo-auth{
  136. z-index: -1;
  137. position: absolute;
  138. left: 50%;
  139. top: 0%;
  140. transform: translate(-50%,-50%);
  141. width:150rpx;
  142. height:150rpx;
  143. display:flex;
  144. align-items: center;
  145. justify-content: center;
  146. border: 8rpx solid #fff;
  147. border-radius: 50%;
  148. background: #fff;
  149. }
  150. image{
  151. height: 42rpx;
  152. margin-top: -54rpx;
  153. }
  154. }
  155. .Popup .title{font-size:28rpx;color:#000;text-align:center;margin-top: 30rpx}
  156. .Popup .tip{font-size:22rpx;color:#555;padding:0 24rpx;margin-top:25rpx;}
  157. .Popup .bottom .item{width:50%;height:80rpx;background-color:#eeeeee;text-align:center;line-height:80rpx;font-size:24rpx;color:#666;margin-top:54rpx;}
  158. .Popup .bottom .item.on{width: 100%}
  159. .flex{display:flex;}
  160. .Popup .bottom .item.grant{font-size:28rpx;color:#fff;font-weight:bold;background-color:#e93323;border-radius:0;padding:0;}
  161. .mask{position:fixed;top:0;right:0;left:0;bottom:0;background-color:rgba(0,0,0,0.65);z-index:310;}
  162. </style>