Showing
3 changed files
with
24 additions
and
13 deletions
| 1 | import router from './router' | 1 | import router from './router' |
| 2 | import store from './store' | 2 | import store from './store' |
| 3 | import { Message } from 'element-ui' | 3 | import { Message } from 'element-ui' |
| 4 | -import { getToken, removeToken } from '@/utils/auth' | 4 | +import { getToken, setToken, removeToken } from '@/utils/auth' |
| 5 | +import settings from "@/settings" | ||
| 5 | 6 | ||
| 6 | 7 | ||
| 7 | const whiteList = ['/login', '/auth-redirect', '/bind', '/register'] | 8 | const whiteList = ['/login', '/auth-redirect', '/bind', '/register'] |
| 9 | + | ||
| 8 | router.beforeEach((to, from, next) => { | 10 | router.beforeEach((to, from, next) => { |
| 9 | if (getToken()) { | 11 | if (getToken()) { |
| 10 | /* has token*/ | 12 | /* has token*/ |
| ... | @@ -14,16 +16,19 @@ router.beforeEach((to, from, next) => { | ... | @@ -14,16 +16,19 @@ router.beforeEach((to, from, next) => { |
| 14 | if (store.getters.roles.length === 0) { | 16 | if (store.getters.roles.length === 0) { |
| 15 | // 判断当前用户是否已拉取完user_info信息 | 17 | // 判断当前用户是否已拉取完user_info信息 |
| 16 | store.dispatch('GetInfo').then(() => { | 18 | store.dispatch('GetInfo').then(() => { |
| 17 | - //获取用户表头 | ||
| 18 | store.dispatch('GetTableHeaders').then(() => { | 19 | store.dispatch('GetTableHeaders').then(() => { |
| 19 | - // 根据roles权限生成可访问的路由表 | ||
| 20 | store.dispatch('GenerateRoutes').then(accessRoutes => { | 20 | store.dispatch('GenerateRoutes').then(accessRoutes => { |
| 21 | + // 根据roles权限生成可访问的路由表 | ||
| 21 | router.addRoutes(accessRoutes) // 动态添加可访问路由表 | 22 | router.addRoutes(accessRoutes) // 动态添加可访问路由表 |
| 22 | next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 | 23 | next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 |
| 23 | }) | 24 | }) |
| 24 | }) | 25 | }) |
| 25 | }).catch(err => { | 26 | }).catch(err => { |
| 26 | - | 27 | + Message.error(err) |
| 28 | + // store.dispatch('LogOut').then(() => { | ||
| 29 | + // // next({ path: '/' }) | ||
| 30 | + // window.location.href = settings.loginURL;//wsso系统跳转 | ||
| 31 | + // }) | ||
| 27 | }) | 32 | }) |
| 28 | } else { | 33 | } else { |
| 29 | next() | 34 | next() |
| ... | @@ -38,7 +43,12 @@ router.beforeEach((to, from, next) => { | ... | @@ -38,7 +43,12 @@ router.beforeEach((to, from, next) => { |
| 38 | setToken(token) | 43 | setToken(token) |
| 39 | next({ path: '/' }) | 44 | next({ path: '/' }) |
| 40 | } else { | 45 | } else { |
| 41 | - next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页 | 46 | + if (whiteList.indexOf(to.path) !== -1) { |
| 47 | + // 在免登录白名单,直接进入 | ||
| 48 | + next() | ||
| 49 | + } else { | ||
| 50 | + window.location.href = settings.loginURL;//wsso系统跳转 | ||
| 51 | + } | ||
| 42 | } | 52 | } |
| 43 | } | 53 | } |
| 44 | }) | 54 | }) | ... | ... |
| ... | @@ -49,7 +49,7 @@ module.exports = { | ... | @@ -49,7 +49,7 @@ module.exports = { |
| 49 | * 后端接口 | 49 | * 后端接口 |
| 50 | */ | 50 | */ |
| 51 | baseURL: `https://imacuat.zmd.apac.fedex.com/iMAC`, | 51 | baseURL: `https://imacuat.zmd.apac.fedex.com/iMAC`, |
| 52 | - downLoadURL: `https://imacuat.zmd.apac.fedex.com/iMAC`,//下载、导出地址 | 52 | + downLoadURL: `https://imacuat.zmd.apac.fedex.com/iMAC`,//下载、导出地址 |
| 53 | 53 | ||
| 54 | /** | 54 | /** |
| 55 | * 项目存放地址 | 55 | * 项目存放地址 | ... | ... |
| ... | @@ -9,9 +9,9 @@ axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' | ... | @@ -9,9 +9,9 @@ axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' |
| 9 | // 创建axios实例 | 9 | // 创建axios实例 |
| 10 | const service = axios.create({ | 10 | const service = axios.create({ |
| 11 | // axios中请求配置有baseURL选项,表示请求URL公共部分 | 11 | // axios中请求配置有baseURL选项,表示请求URL公共部分 |
| 12 | - baseURL: settings.baseURL, //接口地址 | 12 | + baseURL: settings.baseURL, |
| 13 | // 超时 | 13 | // 超时 |
| 14 | - timeout: 30000 | 14 | + timeout: 90000, |
| 15 | }) | 15 | }) |
| 16 | 16 | ||
| 17 | // request拦截器 | 17 | // request拦截器 |
| ... | @@ -52,14 +52,14 @@ service.interceptors.request.use(config => { | ... | @@ -52,14 +52,14 @@ service.interceptors.request.use(config => { |
| 52 | // 响应拦截器 | 52 | // 响应拦截器 |
| 53 | service.interceptors.response.use(res => { | 53 | service.interceptors.response.use(res => { |
| 54 | if (res.headers['token']) { | 54 | if (res.headers['token']) { |
| 55 | - setToken(decodeURI(res.headers['token'])) | 55 | + setToken(res.headers['token']) |
| 56 | } | 56 | } |
| 57 | // 未设置状态码则默认成功状态 | 57 | // 未设置状态码则默认成功状态 |
| 58 | const code = res.data.code || 200; | 58 | const code = res.data.code || 200; |
| 59 | // 获取错误信息 | 59 | // 获取错误信息 |
| 60 | const msg = errorCode[code] || res.data.msg || errorCode['default'] | 60 | const msg = errorCode[code] || res.data.msg || errorCode['default'] |
| 61 | if (code === 301) { | 61 | if (code === 301) { |
| 62 | - MessageBox.confirm('登录状态已过期,需重新登录', '系统提示', { | 62 | + MessageBox.confirm('登录状态已过期,需重新登录!msg:' + msg, '系统提示', { |
| 63 | closeOnClickModal: false, | 63 | closeOnClickModal: false, |
| 64 | showCancelButton: false, | 64 | showCancelButton: false, |
| 65 | confirmButtonText: '重新登录', | 65 | confirmButtonText: '重新登录', |
| ... | @@ -67,9 +67,10 @@ service.interceptors.response.use(res => { | ... | @@ -67,9 +67,10 @@ service.interceptors.response.use(res => { |
| 67 | } | 67 | } |
| 68 | ).then(() => { | 68 | ).then(() => { |
| 69 | store.dispatch('LogOut').then(() => { | 69 | store.dispatch('LogOut').then(() => { |
| 70 | - location.href = settings.routerBase + '/index'; | 70 | + // location.href = '/'; |
| 71 | + window.location.href = settings.loginURL;//wsso系统跳转 | ||
| 71 | }) | 72 | }) |
| 72 | - }) | 73 | + }); |
| 73 | } else if (code === 403) { | 74 | } else if (code === 403) { |
| 74 | //无权限页面 | 75 | //无权限页面 |
| 75 | location.href = '/401'; | 76 | location.href = '/401'; |
| ... | @@ -80,7 +81,7 @@ service.interceptors.response.use(res => { | ... | @@ -80,7 +81,7 @@ service.interceptors.response.use(res => { |
| 80 | type: 'error' | 81 | type: 'error' |
| 81 | }) | 82 | }) |
| 82 | return Promise.reject(new Error(msg)) | 83 | return Promise.reject(new Error(msg)) |
| 83 | - } else if (code !== 200 && code !== 201 && code !== 202 && code != 203 && code != 603) { | 84 | + } else if (code !== 200 && code !== 201 && code !== 202 && code !== 603) { |
| 84 | Message({ | 85 | Message({ |
| 85 | message: msg, | 86 | message: msg, |
| 86 | type: 'error' | 87 | type: 'error' | ... | ... |
-
Please register or login to post a comment