App.vue 1.59 KB
<script>
import {
  getInfo
} from '@/common/login.js';
import * as api from '@/common/api.js';
import config from '@/config.js';

let loginUrl=['login/login', 'login/register']
let firstload = false
export default {
  onLaunch: function(options) {
    console.log('App Launch', options);
    firstload = true

    this.globalData.baseUrl_api = config.baseUrl_api;
    if(loginUrl.indexOf(options.path)==-1){
      let userName = uni.getStorageSync('userName')
      if (userName) {
        getInfo().then(() => {
          this.globalData.isLogin = true;
          let firstLoadCallback = getApp().firstLoadCallback;
          if (firstLoadCallback) {
            firstLoadCallback();
          }
        }).catch(() => {
          uni.redirectTo({
            url: '/login/login'
          })
        })
      } else {
        this.globalData.isLogin = false;
        uni.redirectTo({
          url: '/login/login'
        })
      }
    }
  },
  onShow: function() {
	// if(firstload&&!this.globalData.isLogin){
	// 	console.log('App Show');
	// 	uni.redirectTo({
	// 	  url: '/login/login'
	// 	})
	// }
	
	if(firstload){
		getInfo().then(() => {
		  this.globalData.isLogin = true;
		  let firstLoadCallback = getApp().firstLoadCallback;
		  if (firstLoadCallback) {
		    firstLoadCallback();
		  }
		}).catch(() => {
		  uni.redirectTo({
		    url: '/login/login'
		  })
		})
	}
	
  },
  onHide: function() {
    console.log('App Hide');
  }
};
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '/common/uni.css';
	@import '/common/mystyle.scss';
</style>