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

152 lines
4.8 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" />
2022-10-11 09:55:01 +08:00
<deomon-list ref="deomonList" @enterQcode="qcodeEntry" />
<qcode ref="qcode" />
2021-04-16 09:48:03 +08:00
<img v-show="loading" :src="loadingImg" class="AppAll">
<div
v-if="!$store.state.user.baseUrl"
v-loading="!$store.state.user.baseUrl"
element-loading-text="拼命加载中"
element-loading-background="rgba(0, 0, 0, 0)"
element-loading-spinner="el-icon-loading"
style="width: 100%;height: 100%;"
>
<img :src="appLoading" class="centerImg">
</div>
2019-07-02 16:29:52 +08:00
</div>
</template>
<script>
2022-09-22 17:03:13 +08:00
import { getToken, getUserIdKey } from '@/utils/auth';
2019-11-14 13:59:33 +08:00
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';
2020-09-01 15:07:47 +08:00
import LoadingImg from '@/assets/loading.gif';
import AppLoading from '@/assets/appLoading.png';
2020-12-24 15:33:06 +08:00
import { openIndexedDB } from '@/utils/indexedDb';
2022-10-11 09:55:01 +08:00
import DeomonList from '@/views/demonstration/deomonList/index';
import Qcode from '@/layout/components/Qcode.vue';
2019-09-02 10:38:10 +08:00
2019-07-02 16:29:52 +08:00
export default {
2019-11-05 16:40:36 +08:00
name: 'App',
components: {
2022-10-11 09:55:01 +08:00
DeomonTopic,
DeomonList,
Qcode
2019-11-05 16:40:36 +08:00
},
mixins: [
WindowResizeHandler
],
2020-09-01 15:07:47 +08:00
data() {
return {
loadingImg: LoadingImg,
appLoading: AppLoading,
2020-09-09 10:28:56 +08:00
loading: false
2020-09-01 15:07:47 +08:00
};
},
2019-11-05 16:40:36 +08:00
watch: {
2020-06-30 18:35:57 +08:00
'$store.state.socket.simulationInvite': function (val) {
if (val.creator) {
2019-11-05 16:40:36 +08:00
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) {
if (this.$store.state.socket.loggedOutMsg.token === getToken()) {
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});
});
}
});
2020-01-14 18:18:54 +08:00
});
}
2020-09-01 15:07:47 +08:00
},
'$store.state.app.transitionAnimationsCount': function(val) {
2020-09-09 10:28:56 +08:00
this.loading = true;
2020-09-01 15:07:47 +08:00
},
2020-09-09 10:28:56 +08:00
'$store.state.app.animationsCloseCount': function(val) {
this.loading = false;
2022-10-11 09:55:01 +08:00
},
'$route': function(val) {
2022-10-11 15:14:24 +08:00
if (val.path == '/simulation/multiplayerSimulation') {
2022-10-11 09:55:01 +08:00
this.quickEntry();
}
2019-11-05 16:40:36 +08:00
}
},
created() {
const project = getSessionStorage('project');
if (project) {
2020-06-15 14:26:31 +08:00
document.querySelector("link[rel*='icon']").href = loginInfo[project].linkIcon || ProjectIcon[project];
}
},
2019-11-05 16:40:36 +08:00
mounted() {
this.prohibitSystemContextMenu();
2019-11-12 13:44:10 +08:00
window.addEventListener('beforeunload', async e => {
if (!this.$route.query.noPreLogout) {
await this.$store.dispatch('preLogout');
}
2019-11-12 13:44:10 +08:00
});
2022-09-20 17:25:21 +08:00
window.addEventListener('storage', e => {
2022-09-26 15:11:55 +08:00
if (this.$route.path.includes('trainingDesign') || this.$route.path.includes('trainingPreview')) {
if (e.key == getUserIdKey('nextNew')) {
2022-09-20 17:54:14 +08:00
const operate = JSON.parse(e.newValue);
2022-09-22 17:03:13 +08:00
this.$store.dispatch('training/nextNew', operate);
2022-09-20 17:54:14 +08:00
}
2022-09-20 17:25:21 +08:00
}
2022-09-22 17:03:13 +08:00
2022-09-20 17:25:21 +08:00
});
2020-12-24 15:33:06 +08:00
this.$nextTick(() => {
openIndexedDB();
});
2019-11-05 16:40:36 +08:00
},
2022-08-02 18:01:42 +08:00
beforeDestroy() {
this.$store.dispatch('subscribe_un', {});
},
2019-11-05 16:40:36 +08:00
methods: {
2022-10-11 09:55:01 +08:00
quickEntry() {
this.$refs.deomonList.doShow();
},
qcodeEntry() {
this.$refs.qcode.doShow();
},
2019-11-05 16:40:36 +08:00
resizeHandler() {
this.$store.dispatch('app/resize', { width: this._clientWidth, height: this._clientHeight });
2019-11-05 16:40:36 +08:00
},
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-11-23 17:32:17 +08:00
if (!(getSessionStorage('project').includes('design'))) {
2020-05-21 16:59:36 +08:00
this.$refs.deomonTopic.doShow(res);
}
2020-06-30 18:35:57 +08:00
this.$store.dispatch('socket/setSimulationInvite');
2019-11-12 17:27:30 +08:00
}
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>
2021-04-16 09:48:03 +08:00
<style lang="scss" scoped>
.AppAll{position: absolute;top: 0;left: 0;width: 100%;height: 100%;z-index: 2003}
.centerImg {
position: absolute;
left:50%;
top: 50%;
width: 480px;
height: 456px;
margin-left: -240px;
margin-top: -228px;
}
2021-04-16 09:48:03 +08:00
</style>