Files
smart-admin/smart_admin_v1/smart-admin-h5/src/components/mixin/session-mixin.js
2022-10-27 22:54:37 +08:00

26 lines
784 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import cookie from '@/lib/cookie';
import { userApi } from 'api/user';
/**
* 此 mixin为登录以后的页面用的因为所有的有效路由排除登录、注册、404,500 这个几个特殊页面)都会走 App.vue里的router
* @author zhuoda
*/
export default {
created: function() {
const token = cookie.getToken();
// 如果登录过获取token
if (token && !this.$store.state.user.isHaveGotSessionInfo) {
(async() => {
try {
console.debug(' request session info ');
const res = await userApi.getSession();
const loginInfo = res.data;
this.$store.commit('user/updateSession', loginInfo);
} catch (e) {
this.$smartSentry.captureException(e);
}
})();
}
}
};