loginMixin.ts 911 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Vue, Component } from 'vue-property-decorator';
  2. import {namespace} from 'vuex-class';
  3. import { types } from '@/common/store/index';
  4. const baseModule = namespace('base');
  5. @Component({})
  6. export default class LoginMixin extends Vue {
  7. @baseModule.Getter('_userInfo') _userInfo: any;
  8. @baseModule.Getter('_token') token: any;
  9. @baseModule.Mutation(types.SET_USERINFO) _setUserInfo: any;
  10. isAuthorization(){
  11. if(!this.token){
  12. this.$Router.push('/pages/login/login');
  13. return true;
  14. }
  15. }
  16. /**
  17. * 获取用户信息
  18. * GET
  19. * */
  20. getUserInfo () {
  21. // uni.showLoading({
  22. // title: '加载中',
  23. // });
  24. return this.$http.get({
  25. url:this.$api.getUserInfo
  26. })
  27. .then((res:any) => {
  28. // uni.hideLoading();
  29. if (res) {
  30. // let {info, ...extra } = res;
  31. this._setUserInfo(res.info)
  32. }
  33. })
  34. .catch((err:any) => {
  35. // uni.hideLoading();
  36. console.log(err)
  37. })
  38. }
  39. }