rt-sim-training-client/src/App.vue
2019-11-12 13:44:10 +08:00

90 lines
2.7 KiB
Vue

<template>
<div id="app">
<router-view />
<deomon-topic ref="deomonTopic" />
</div>
</template>
<script>
import { handleToken } from '@/utils/auth';
import { creatSubscribe, perpetualTopic, commonTopic } from '@/utils/stomp';
import DeomonTopic from '@/views/demonstration/deomonTopic';
import WindowResizeHandler from '@/mixin/WindowResizeHandler';
import Cookies from 'js-cookie';
import { ProjectIcon } from '@/scripts/ConstDic';
import { logout } from '@/api/login';
export default {
name: 'App',
components: {
DeomonTopic
},
mixins: [
WindowResizeHandler
],
watch: {
'$store.state.socket.roomInvite': function (val) {
if (val.creatorId) {
this.subscribeMessage(val);
}
}
},
mounted() {
this.prohibitSystemContextMenu();
this.subscribe();
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.pageDestory();
}
});
window.addEventListener('beforeunload', async e => {
beforeUnload_time = new Date().getTime();
if (isFireFox) {
await this.pageDestory();
}
});
},
methods: {
async pageDestory() {
const token = handleToken();
Cookies.remove('UserDesignName');
Cookies.remove('UserDesignToken');
Cookies.remove('UserName');
Cookies.remove('UserToken');
await logout(token);
},
resizeHandler() {
this.$store.dispatch('app/resize', {width: this._clientWidth, height: this._clientHeight});
},
prohibitSystemContextMenu() {
window.document.oncontextmenu = function () {
return false;
};
},
subscribe() {
this.$nextTick(() => {
if (!this.$route.path.includes('/login') && this.$route.path != '/404') {
const header = { group: '', 'X-Token': handleToken() };
creatSubscribe(perpetualTopic, header);
creatSubscribe(commonTopic, header);
}
});
},
subscribeMessage(res) {
if (this.$refs.deomonTopic) {
this.$refs.deomonTopic.doShow(res);
this.$store.dispatch('socket/setRoomInvite');
}
}
}
};
</script>