| 12345678910111213141516171819202122232425262728293031323334353637 |
- import router from './router';
- import store from './store';
- const whiteList = ['/login', '/auth-redirect', '/bind', '/register'];
- router.beforeEach((to, from, next) => {
- let queryLoginName = to.query.loginName || null;
- if (queryLoginName) {
- localStorage.setItem('loginName', queryLoginName);
- }
- const username = localStorage.getItem('loginName');
- // 测试使用 账户密码登录页面,正式环境禁用
- if (to.path == '/logincs' && process.env.NODE_ENV == 'production') {
- next('/');
- } else {
- if (username) {
- /* has token*/
- if (!store.state.user.userInfo) {
- // 获取移动端获取用户信息接口
- store
- .dispatch('getUserInfo')
- .then(() => {
- next();
- })
- .catch(() => {
- next();
- });
- } else {
- next();
- }
- } else {
- alert('获取签名失败');
- next();
- }
- }
- });
|