| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- import router from './router';
- import store from './store';
- const whiteList = ['/login', '/auth-redirect', '/bind', '/register'];
- router.beforeEach((to, from, next) => {
- const username = localStorage.getItem('loginName');
- if (username) {
- /* has token*/
- if (!store.state.user.userInfo) {
- // 获取移动端获取用户信息接口
- store
- .dispatch('getUserInfo')
- .then(() => {
- getDict(next);
- })
- .catch(() => {
- next();
- });
- } else {
- next();
- }
- } else {
- next();
- // // 没有token
- // if (whiteList.indexOf(to.path) !== -1) {
- // // 在免登录白名单,直接进入
- // next();
- // } else {
- // next(`/login?redirect=${to.fullPath}`); // 否则全部重定向到登录页
- // NProgress.done();
- // }
- }
- });
- const getDict = async function () {
- let gz_Option = await getDictOption({}, 'gz_customer_post'); //公装业务员岗位
- let jz_Option = await getDictOption({}, 'jz_post_name'); //家装业务员岗位
- let postName = store.state.user.userInfo.postName;
- if (gz_Option.indexof(postName) == -1 || jz_Option.indexof(postName) == -1) {
- localStorage.setItem('isGZorJZ', 'false');
- } else {
- localStorage.setItem('isGZorJZ', 'true');
- }
- next();
- };
|