94 lines
2.9 KiB
Vue
94 lines
2.9 KiB
Vue
<template>
|
|
<div id="app">
|
|
<router-view />
|
|
<deomon-topic ref="deomonTopic" />
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import { getToken } from '@/utils/auth';
|
|
import { getSessionStorage } from '@/utils/auth';
|
|
import { ProjectIcon, loginInfo } from '@/scripts/ConstDic';
|
|
import DeomonTopic from '@/views/demonstration/deomonTopic';
|
|
import WindowResizeHandler from '@/mixin/WindowResizeHandler';
|
|
|
|
export default {
|
|
name: 'App',
|
|
components: {
|
|
DeomonTopic
|
|
},
|
|
mixins: [
|
|
WindowResizeHandler
|
|
],
|
|
computed: {
|
|
path() {
|
|
return window.location.pathname;
|
|
}
|
|
},
|
|
watch: {
|
|
'$store.state.socket.roomInvite': function (val) {
|
|
if (val.creatorId) {
|
|
this.subscribeMessage(val);
|
|
}
|
|
},
|
|
'$store.state.socket.beLogoutCount': async function(val) {
|
|
this.$alert(this.$t('tip.logoutTips'), this.$t('tip.hint'), {
|
|
confirmButtonText: this.$t('tip.confirm'),
|
|
callback: action => {
|
|
this.$store.dispatch('LogOut').then(resp => {
|
|
this.$router.push({path: loginInfo[getSessionStorage('project')].loginPath});
|
|
});
|
|
}
|
|
});
|
|
}
|
|
},
|
|
mounted() {
|
|
this.prohibitSystemContextMenu();
|
|
const project = window.sessionStorage.getItem('project');
|
|
document.querySelector("link[rel*='icon']").href = ProjectIcon[project];
|
|
|
|
var beforeUnload_time = 0;
|
|
var gap_time = 0;
|
|
var isFireFox = navigator.userAgent.indexOf('Firefox') > -1;
|
|
window.addEventListener('unload', async e => {
|
|
gap_time = new Date().getTime() - beforeUnload_time;
|
|
if (gap_time <= 5) {
|
|
await this.$store.dispatch('LogOut');
|
|
}
|
|
});
|
|
window.addEventListener('beforeunload', async e => {
|
|
beforeUnload_time = new Date().getTime();
|
|
if (isFireFox) {
|
|
await this.$store.dispatch('LogOut');
|
|
}
|
|
});
|
|
|
|
this.$nextTick(() => { this.subscribe(); });
|
|
},
|
|
methods: {
|
|
resizeHandler() {
|
|
this.$store.dispatch('app/resize', {width: this._clientWidth, height: this._clientHeight});
|
|
},
|
|
prohibitSystemContextMenu() {
|
|
window.document.oncontextmenu = function () {
|
|
return false;
|
|
};
|
|
},
|
|
subscribeMessage(res) {
|
|
if (this.$refs.deomonTopic) {
|
|
this.$refs.deomonTopic.doShow(res);
|
|
this.$store.dispatch('socket/setRoomInvite');
|
|
}
|
|
},
|
|
subscribe() {
|
|
const token = getToken();
|
|
if (token && this.$route.path != '/404' && !this.path.endsWith('login')) {
|
|
const header = { group: '', 'X-Token': token };
|
|
this.$store.dispatch('subscribe', {header, type: getSessionStorage('project')});
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
</script>
|