rt-sim-training-client/src/App.vue

102 lines
3.3 KiB
Vue
Raw Normal View History

2019-07-02 16:29:52 +08:00
<template>
<div id="app">
<router-view />
2019-09-02 10:38:10 +08:00
<deomon-topic ref="deomonTopic" />
2019-07-02 16:29:52 +08:00
</div>
</template>
<script>
2019-11-14 13:59:33 +08:00
import { getToken } from '@/utils/auth';
import { getSessionStorage } from '@/utils/auth';
import { loginInfo, ProjectIcon } from '@/scripts/ProjectConfig';
import DeomonTopic from '@/views/demonstration/deomonTopic';
2019-09-02 10:38:10 +08:00
import WindowResizeHandler from '@/mixin/WindowResizeHandler';
2019-07-02 16:29:52 +08:00
export default {
2019-11-05 16:40:36 +08:00
name: 'App',
components: {
DeomonTopic
},
mixins: [
WindowResizeHandler
],
2019-11-19 10:54:52 +08:00
computed: {
path() {
return window.location.pathname;
}
},
2019-11-05 16:40:36 +08:00
watch: {
'$store.state.socket.roomInvite': function (val) {
if (val.creatorId) {
this.subscribeMessage(val);
}
2019-11-14 13:59:33 +08:00
},
2019-11-18 10:34:18 +08:00
'$store.state.socket.beLogoutCount': async function(val) {
2020-01-14 18:18:54 +08:00
this.$store.dispatch('disconnect').then(()=>{
this.$alert(this.$t('tip.logoutTips'), this.$t('tip.hint'), {
confirmButtonText: this.$t('tip.confirm'),
callback: action => {
this.$store.dispatch('exit').then(resp => {
this.$router.push({path: loginInfo[getSessionStorage('project')].loginPath});
});
}
});
2019-11-14 13:59:33 +08:00
});
2019-11-05 16:40:36 +08:00
}
},
created() {
const project = getSessionStorage('project');
if (project) {
2020-06-15 13:03:24 +08:00
document.querySelector("link[rel*='icon']").href = loginInfo[this.project].linkIcon || ProjectIcon[this.project];
}
},
2019-11-05 16:40:36 +08:00
mounted() {
this.prohibitSystemContextMenu();
2019-11-12 13:44:10 +08:00
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) {
2019-11-28 18:45:37 +08:00
await this.$store.dispatch('exit');
2019-11-12 13:44:10 +08:00
}
});
window.addEventListener('beforeunload', async e => {
beforeUnload_time = new Date().getTime();
if (isFireFox) {
2019-11-28 18:45:37 +08:00
await this.$store.dispatch('exit');
2019-11-12 13:44:10 +08:00
}
});
2019-11-12 17:27:30 +08:00
2019-11-19 10:54:52 +08:00
this.$nextTick(() => { this.subscribe(); });
2019-11-05 16:40:36 +08:00
},
methods: {
resizeHandler() {
this.$store.dispatch('app/resize', {width: this._clientWidth, height: this._clientHeight});
},
prohibitSystemContextMenu() {
window.document.oncontextmenu = function () {
return false;
};
},
2019-11-12 17:27:30 +08:00
subscribeMessage(res) {
2019-12-10 15:06:29 +08:00
if (this.$refs.deomonTopic && !window.location.href.includes('trainroom')) {
2020-05-22 11:07:10 +08:00
if (getSessionStorage('project') != 'refereeJsxt' && getSessionStorage('project') != 'jsxt') {
2020-05-21 16:59:36 +08:00
this.$refs.deomonTopic.doShow(res);
}
2019-11-12 17:27:30 +08:00
this.$store.dispatch('socket/setRoomInvite');
}
},
2019-11-05 16:40:36 +08:00
subscribe() {
2019-11-19 10:54:52 +08:00
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')});
}
2019-11-05 16:40:36 +08:00
}
}
2019-08-08 11:29:03 +08:00
};
2019-07-02 16:29:52 +08:00
</script>