From 527d16a6df99900378cc70720856bc2b5a01f798 Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Mon, 8 May 2023 15:43:16 +0800 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 4af4e7ea9c440cdf1a7dba0f6ed6b4774910b2ee Author: dong <58670809@qq.com> Date: Sat May 6 18:11:16 2023 +0800 登录时判断用户已经加入的仿真 --- src/api/login.js | 14 ++- src/views/newMap/display/index.vue | 10 +- .../display/simulationMenu/simulationMenu.vue | 13 ++- src/views/trainingPlatform/simulation.vue | 107 +++++++++++++----- 4 files changed, 107 insertions(+), 37 deletions(-) diff --git a/src/api/login.js b/src/api/login.js index ce4f7564e..6799bf964 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -101,7 +101,7 @@ export function getOrgList() { return request({ url: '/api/orgProject/list', method: 'get' - }) + }); } /** @@ -111,5 +111,15 @@ export function selectOrgnization(orgId) { return request({ url: `/api/orgProject/signIn/${orgId}`, method: 'put' - }) + }); +} + +/** + * 获取用户已经加入的仿真 + */ +export function getSimulationJoined() { + return request({ + url: '/simulation/joined/by/me', + method: 'get' + }); } diff --git a/src/views/newMap/display/index.vue b/src/views/newMap/display/index.vue index f4a5a05ce..e08ad49ca 100644 --- a/src/views/newMap/display/index.vue +++ b/src/views/newMap/display/index.vue @@ -111,11 +111,11 @@ export default { this.$store.dispatch('trainingNew/clearStepOverCount'); this.$store.dispatch('trainingNew/trainingEnd'); this.$store.dispatch('trainingNew/changeTeachMode', ''); - if (this.$store.state.training.simulationCreator) { - destroySimulationByAdmin(this.group); - } else { - exitSimulation(this.group); - } + // if (this.$store.state.training.simulationCreator) { + // destroySimulationByAdmin(this.group); + // } else { + // exitSimulation(this.group); + // } this.$store.dispatch('socket/resetRailCtcRunplanInitMsg'); // 清除阶段计划 this.$store.dispatch('socket/clearDispatchCommandMsg'); // 清除调度命令 this.$store.dispatch('map/setLinkSwitchMap', {}); diff --git a/src/views/newMap/display/simulationMenu/simulationMenu.vue b/src/views/newMap/display/simulationMenu/simulationMenu.vue index 52de8e999..771d3518d 100644 --- a/src/views/newMap/display/simulationMenu/simulationMenu.vue +++ b/src/views/newMap/display/simulationMenu/simulationMenu.vue @@ -32,7 +32,7 @@ import ExamPanel from '../exam/examPanel'; import getErrorTip from '@/scripts/errorTip'; import DeviceManage from './deviceManage'; import { SimulationUserType } from '@/scripts/ConstDic'; -import { destroySimulationByAdmin, ranAsPlan} from '@/api/simulation'; +import { destroySimulationByAdmin, exitSimulation, ranAsPlan} from '@/api/simulation'; import { EventBus } from '@/scripts/event-bus'; import SimulationControl from './simulationControl'; import SimulationId from '../simulationId'; @@ -193,10 +193,15 @@ export default { }); }, back() { + if (this.$store.state.training.simulationCreator) { + destroySimulationByAdmin(this.group); + } else { + exitSimulation(this.group); + } if (this.projectDevice && this.$store.state.training.simulationCreator) { - destroySimulationByAdmin(this.group).then(() => { - this.logout(); - }); + // destroySimulationByAdmin(this.group).then(() => { + this.logout(); + // }); } else if (this.$route.query.third) { if (this.$route.query.project === 'cgy' || this.$route.query.project === 'drts') { window.parent.postMessage('back', '*'); diff --git a/src/views/trainingPlatform/simulation.vue b/src/views/trainingPlatform/simulation.vue index 3e1b94b3a..7c863de2d 100644 --- a/src/views/trainingPlatform/simulation.vue +++ b/src/views/trainingPlatform/simulation.vue @@ -55,9 +55,10 @@ import { getMapIdPermisson } from '@/api/userRulesManage'; import { queryMapFunctionList } from '@/api/trainingPlatform'; import selectRole from './selectRole/list'; import { launchFullscreen } from '@/utils/screen'; -import { createSimulation } from '@/api/simulation'; +import { createSimulation, destroySimulationByAdmin, exitSimulation } from '@/api/simulation'; import { getSessionStorage } from '@/utils/auth'; import { jointSimulationByPermission } from '@/api/jointSimulation'; +import { getSimulationJoined } from '@/api/login'; export default { name: 'Simulation', components: { @@ -233,10 +234,60 @@ export default { } }, mounted() { + this.getJoinedSimulation(); this.loadInitData(); this.initMapSystem(); }, methods: { + // 获取用户已经加入的仿真 + getJoinedSimulation() { + return new Promise((resolve, reject) => { + getSimulationJoined().then(res => { + const data = res.data; + if (data) { + this.$confirm('存在未完成的仿真', '警告', { + confirmButtonText: '继续仿真', + cancelButtonText: '退出仿真', + type: 'warning', + // showClose: false, // 是否显示右上角x + distinguishCancelAndClose: true, // close和cancel执行的方法是否有区别 + closeOnClickModal: false // 是否可以点击空白处关闭弹窗 + }).then(() => { + const path = '/display/demon'; + const query = { + lineCode: data.map.lineCode, + group: data.group, + mapId: data.map.id, + simType: data.paramVO.type, + project: this.$route.query.project || 'login' + }; + if (data.paramVO && data.paramVO.domConfig && data.paramVO.domConfig.client) { + query.client = data.paramVO.domConfig.client; + } + if (data.paramVO && data.paramVO.domConfig && data.paramVO.domConfig.singleClient) { + query.singleClient = data.paramVO.domConfig.singleClient; + } + if (this.loadingProjectList.includes(query.project)) { + this.$store.dispatch('app/transitionAnimations'); + } + this.$router.push({ path, query }); + launchFullscreen(); + }).catch((e) => { + if (e == 'cancel') { + if (data.creator.id == this.$store.state.user.id) { + destroySimulationByAdmin(data.group); + } else { + exitSimulation(data.group); + } + } + }); + } + resolve(data); + }).catch(err => { + reject(err); + }); + }); + }, getAbilityList(list) { const arr = []; list && list.forEach(item => { @@ -284,32 +335,36 @@ export default { } }, enterSimulation(system) { - createSimulation(system.id).then(resp => { - const query = { - lineCode: this.$route.query.lineCode, - group: resp.data, - mapId: system.mapId, - simType: system.simType, - project: this.project - }; - if (system.paramVO && system.paramVO.domConfig && system.paramVO.domConfig.client) { - query.client = system.paramVO.domConfig.client; + this.getJoinedSimulation().then(data => { + if (!data) { + createSimulation(system.id).then(resp => { + const query = { + lineCode: this.$route.query.lineCode, + group: resp.data, + mapId: system.mapId, + simType: system.simType, + project: this.project + }; + if (system.paramVO && system.paramVO.domConfig && system.paramVO.domConfig.client) { + query.client = system.paramVO.domConfig.client; + } + if (system.paramVO && system.paramVO.domConfig && system.paramVO.domConfig.singleClient) { + query.singleClient = system.paramVO.domConfig.singleClient; + } + if (this.loadingProjectList.includes(this.project)) { + this.$store.dispatch('app/transitionAnimations'); + } + this.$router.push({ path: `/display/demon`, query: query }); + launchFullscreen(); + }).catch(error=>{ + if (error.code == 10003) { + this.$messageBox(this.$t('error.createSimulationFailed') + ':您的仿真权限不足!'); + } else { + this.$messageBox(this.$t('error.createSimulationFailed') + error.message); + } + this.disabled = false; + }); } - if (system.paramVO && system.paramVO.domConfig && system.paramVO.domConfig.singleClient) { - query.singleClient = system.paramVO.domConfig.singleClient; - } - if (this.loadingProjectList.includes(this.project)) { - this.$store.dispatch('app/transitionAnimations'); - } - this.$router.push({ path: `/display/demon`, query: query }); - launchFullscreen(); - }).catch(error=>{ - if (error.code == 10003) { - this.$messageBox(this.$t('error.createSimulationFailed') + ':您的仿真权限不足!'); - } else { - this.$messageBox(this.$t('error.createSimulationFailed') + error.message); - } - this.disabled = false; }); }, async joinSimulation() {