forked from github/dataease
feat(登录): 关闭浏览器之前执行登出
This commit is contained in:
parent
3232c2b934
commit
d8f84426aa
@ -239,6 +239,9 @@ export default {
|
||||
},
|
||||
|
||||
mounted() {
|
||||
window.addEventListener('beforeunload', (e) => this.beforeunloadHandler(e))
|
||||
window.addEventListener('unload', (e) => this.unloadHandler(e))
|
||||
|
||||
this.initCurrentRoutes()
|
||||
bus.$on('set-top-menu-info', this.setTopMenuInfo)
|
||||
bus.$on('set-top-menu-active-info', this.setTopMenuActiveInfo)
|
||||
@ -251,6 +254,9 @@ export default {
|
||||
})
|
||||
},
|
||||
beforeDestroy() {
|
||||
window.removeEventListener('beforeunload', (e) => this.beforeunloadHandler(e))
|
||||
window.removeEventListener('unload', (e) => this.unloadHandler(e))
|
||||
|
||||
bus.$off('set-top-menu-info', this.setTopMenuInfo)
|
||||
bus.$off('set-top-menu-active-info', this.setTopMenuActiveInfo)
|
||||
bus.$off('set-top-text-info', this.setTopTextInfo)
|
||||
@ -269,6 +275,16 @@ export default {
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
beforeunloadHandler() {
|
||||
this.beforeUnload_time = new Date().getTime()
|
||||
},
|
||||
unloadHandler(e) {
|
||||
this.gap_time = new Date().getTime() - this.beforeUnload_time
|
||||
if (this.gap_time <= 5) {
|
||||
this.logout().then(res => {})
|
||||
}
|
||||
},
|
||||
|
||||
// 通过当前路径找到二级菜单对应项,存到store,用来渲染左侧菜单
|
||||
initCurrentRoutes() {
|
||||
const {
|
||||
|
@ -1,10 +1,10 @@
|
||||
import Cookies from 'js-cookie'
|
||||
import i18n from '@/lang'
|
||||
import { $error, $confirm } from '@/utils/message'
|
||||
import {seizeLogin} from '@/api/user'
|
||||
import { seizeLogin } from '@/api/user'
|
||||
import router from '@/router'
|
||||
import store from "@/store";
|
||||
import { Loading } from 'element-ui';
|
||||
import store from '@/store'
|
||||
import { Loading } from 'element-ui'
|
||||
export function timeSection(date, type, labelFormat = 'yyyy-MM-dd') {
|
||||
if (!date) {
|
||||
return null
|
||||
@ -367,7 +367,7 @@ export const showMultiLoginMsg = () => {
|
||||
const content = infos.map(info => buildMultiLoginErrorItem(info)).join('</br>')
|
||||
let msgContent = '<strong>' + i18n.t('multi_login_lang.title') + '</strong>'
|
||||
msgContent += content + '<p>' + i18n.t('multi_login_lang.label') + '</p>'
|
||||
$error(msgContent, 10000, true);
|
||||
$error(msgContent, 10000, true)
|
||||
}
|
||||
const multiLoginError2 = Cookies.get('MultiLoginError2')
|
||||
if (multiLoginError2) {
|
||||
@ -378,11 +378,11 @@ export const showMultiLoginMsg = () => {
|
||||
msgContent += content + '<p>' + i18n.t('multi_login_lang.confirm') + '</p>'
|
||||
$confirm(msgContent, () => seize(infos[0]), {
|
||||
dangerouslyUseHTMLString: true
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
const seize = model => {
|
||||
let loadingInstance = Loading.service({});
|
||||
const loadingInstance = Loading.service({})
|
||||
const token = model.token
|
||||
const param = {
|
||||
token
|
||||
@ -391,7 +391,7 @@ const seize = model => {
|
||||
const resultToken = res.data.token
|
||||
store.dispatch('user/refreshToken', resultToken)
|
||||
router.push('/')
|
||||
loadingInstance.close();
|
||||
loadingInstance.close()
|
||||
})
|
||||
}
|
||||
const buildMultiLoginErrorItem = (info) => {
|
||||
|
@ -30,8 +30,7 @@ module.exports = {
|
||||
overlay: {
|
||||
warnings: false,
|
||||
errors: true
|
||||
},
|
||||
before: require('./mock/mock-server.js')
|
||||
}
|
||||
},
|
||||
|
||||
pages: {
|
||||
|
Loading…
Reference in New Issue
Block a user