Commit fb1648ecbaed13d8553e6e5c302613670f1f15d1
1 parent
e923bc66
v3.8.2 修改登录超时刷新页面跳转登录页面还提示重新登录问题
Showing
10 changed files
with
50 additions
and
16 deletions
yudao-ui-admin/.env.demo1024
yudao-ui-admin/.env.development
yudao-ui-admin/.env.production
yudao-ui-admin/.env.staging
yudao-ui-admin/src/main.js
| ... | ... | @@ -15,6 +15,7 @@ import plugins from './plugins' // plugins |
| 15 | 15 | |
| 16 | 16 | import './assets/icons' // icon |
| 17 | 17 | import './permission' // permission control |
| 18 | +import './tongji' // 百度统计 | |
| 18 | 19 | import { getDicts } from "@/api/system/dict/data"; |
| 19 | 20 | import { getConfigKey } from "@/api/infra/config"; |
| 20 | 21 | import { parseTime, resetForm, addDateRange, addBeginAndEndTime, handleTree} from "@/utils/ruoyi"; | ... | ... |
yudao-ui-admin/src/permission.js
| ... | ... | @@ -4,9 +4,11 @@ import { Message } from 'element-ui' |
| 4 | 4 | import NProgress from 'nprogress' |
| 5 | 5 | import 'nprogress/nprogress.css' |
| 6 | 6 | import { getToken } from '@/utils/auth' |
| 7 | +import { isRelogin } from '@/utils/request' | |
| 7 | 8 | |
| 8 | 9 | NProgress.configure({ showSpinner: false }) |
| 9 | 10 | |
| 11 | +// 增加三方登陆 update by 芋艿 | |
| 10 | 12 | const whiteList = ['/login', '/social-login', '/auth-redirect', '/bind', '/register', '/oauthLogin/gitee'] |
| 11 | 13 | |
| 12 | 14 | router.beforeEach((to, from, next) => { |
| ... | ... | @@ -19,21 +21,23 @@ router.beforeEach((to, from, next) => { |
| 19 | 21 | NProgress.done() |
| 20 | 22 | } else { |
| 21 | 23 | if (store.getters.roles.length === 0) { |
| 22 | - // 获取字典数据 | |
| 24 | + isRelogin.show = true | |
| 25 | + // 获取字典数据 add by 芋艿 | |
| 23 | 26 | store.dispatch('dict/loadDictDatas') |
| 24 | 27 | // 判断当前用户是否已拉取完user_info信息 |
| 25 | 28 | store.dispatch('GetInfo').then(() => { |
| 29 | + isRelogin.show = false | |
| 26 | 30 | store.dispatch('GenerateRoutes').then(accessRoutes => { |
| 27 | 31 | // 根据roles权限生成可访问的路由表 |
| 28 | 32 | router.addRoutes(accessRoutes) // 动态添加可访问路由表 |
| 29 | 33 | next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 |
| 30 | 34 | }) |
| 31 | 35 | }).catch(err => { |
| 32 | - store.dispatch('LogOut').then(() => { | |
| 33 | - Message.error(err) | |
| 34 | - next({ path: '/' }) | |
| 35 | - }) | |
| 36 | + store.dispatch('LogOut').then(() => { | |
| 37 | + Message.error(err) | |
| 38 | + next({ path: '/' }) | |
| 36 | 39 | }) |
| 40 | + }) | |
| 37 | 41 | } else { |
| 38 | 42 | next() |
| 39 | 43 | } | ... | ... |
yudao-ui-admin/src/tongji.js
0 → 100644
| 1 | +// Baidu 统计 integration | |
| 2 | +import router from './router' | |
| 3 | + | |
| 4 | +window._hmt = window._hmt || []; // 用于 router push | |
| 5 | +const HM_ID = process.env.VUE_APP_BAIDU_CODE || ''; // 有值的时候,才开启 | |
| 6 | +(function() { | |
| 7 | + if (!HM_ID) { | |
| 8 | + return; | |
| 9 | + } | |
| 10 | + const hm = document.createElement("script") | |
| 11 | + hm.src = "https://hm.baidu.com/hm.js?" + HM_ID | |
| 12 | + const s = document.getElementsByTagName("script")[0] | |
| 13 | + s.parentNode.insertBefore(hm, s) | |
| 14 | +})() | |
| 15 | + | |
| 16 | +router.afterEach(function (to) { | |
| 17 | + if (!HM_ID) { | |
| 18 | + return; | |
| 19 | + } | |
| 20 | + _hmt.push(['_trackPageview', to.fullPath]) | |
| 21 | +}) | ... | ... |
yudao-ui-admin/src/utils/dict.js
yudao-ui-admin/src/utils/request.js
| ... | ... | @@ -7,7 +7,7 @@ import Cookies from "js-cookie"; |
| 7 | 7 | import {getTenantEnable} from "@/utils/ruoyi"; |
| 8 | 8 | |
| 9 | 9 | // 是否显示重新登录 |
| 10 | -let isReloginShow; | |
| 10 | +export let isRelogin = { show: false }; | |
| 11 | 11 | |
| 12 | 12 | axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' |
| 13 | 13 | // 创建axios实例 |
| ... | ... | @@ -66,23 +66,20 @@ service.interceptors.response.use(res => { |
| 66 | 66 | // 获取错误信息 |
| 67 | 67 | const msg = errorCode[code] || res.data.msg || errorCode['default'] |
| 68 | 68 | if (code === 401) { |
| 69 | - if (!isReloginShow) { | |
| 70 | - isReloginShow = true; | |
| 69 | + if (!isRelogin.show) { | |
| 70 | + isRelogin.show = true; | |
| 71 | 71 | MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { |
| 72 | 72 | confirmButtonText: '重新登录', |
| 73 | 73 | cancelButtonText: '取消', |
| 74 | 74 | type: 'warning' |
| 75 | 75 | } |
| 76 | 76 | ).then(() => { |
| 77 | - isReloginShow = false; | |
| 77 | + isRelogin.show = false; | |
| 78 | 78 | store.dispatch('LogOut').then(() => { |
| 79 | - // 如果是登录页面不需要重新加载 | |
| 80 | - if (window.location.hash.indexOf("#/login") !== 0) { | |
| 81 | - location.href = '/index'; | |
| 82 | - } | |
| 79 | + location.href = '/index'; | |
| 83 | 80 | }) |
| 84 | 81 | }).catch(() => { |
| 85 | - isReloginShow = false; | |
| 82 | + isRelogin.show = false; | |
| 86 | 83 | }); |
| 87 | 84 | } |
| 88 | 85 | return Promise.reject('无效的会话,或者会话已过期,请重新登录。') | ... | ... |