diff --git a/src/api/Simulation.ts b/src/api/Simulation.ts index 488ec78..259d381 100644 --- a/src/api/Simulation.ts +++ b/src/api/Simulation.ts @@ -471,3 +471,11 @@ export async function xcjUpdateParams(data: { }) { return await api.put(`${UriBase}/xcj/operation`, data); } + +/** 列车取消连接 */ +export async function cancelTrainConn(data: { + trainId: string; + id: string; +}) { + return await api.delete(`${UriBase}/train/unconn/${data.trainId}/${data.id}`); +} diff --git a/src/components/draw-app/dialogs/SetTrainLink.vue b/src/components/draw-app/dialogs/SetTrainLink.vue index e541252..c1902f7 100644 --- a/src/components/draw-app/dialogs/SetTrainLink.vue +++ b/src/components/draw-app/dialogs/SetTrainLink.vue @@ -68,8 +68,8 @@ onMounted(() => { list.push({ label: '半实物', value: 1 }); } else if (element.connType === 2) { list.push({ label: 'PC仿真', value: 2 }); - } else if (element.connType === 0) { - list.push({ label: '取消连接', value: 0 }); + // } else if (element.connType === 0) { + // list.push({ label: '取消连接', value: 0 }); } }); connectOptions.value = list; diff --git a/src/components/line-app/infos/TrainInfo.vue b/src/components/line-app/infos/TrainInfo.vue index 5d06c13..dacbef1 100644 --- a/src/components/line-app/infos/TrainInfo.vue +++ b/src/components/line-app/infos/TrainInfo.vue @@ -191,6 +191,8 @@ import { Dialog } from 'quasar'; import { state } from 'src/protos/device_state'; import SetTrainLink from 'src/components/draw-app/dialogs/SetTrainLink.vue'; import { useTccStore } from 'src/stores/tcc-store'; +import { cancelTrainConn } from 'src/api/Simulation'; +import { errorNotify, successNotify } from 'src/utils/CommonNotify'; interface KeyType { label: string; @@ -612,6 +614,10 @@ const options = [ label: '列车驾驶台', value: 3, }, + { + label: '取消连接', + value: 4, + }, ]; function doTrainOperation(option: { label: string; value: number }) { @@ -621,9 +627,31 @@ function doTrainOperation(option: { label: string; value: number }) { linkTrain(); } else if (option.value == 3) { openTccDialog(); + } else if (option.value == 4) { + cancelTrainLink(); } } +function cancelTrainLink() { + if (!lineStore.selectedGraphics) return; + const train = lineStore.selectedGraphics[0] as Train; + Dialog.create({ + title: '确认', + message: `确认取消【${train.states.id}】列车的连接吗?`, + cancel: true, + }).onOk(async () => { + cancelTrainConn({ + id: lineStore.simulationId || '', + trainId: train.code, + }) + .then(() => { + successNotify('列车取消连接成功!'); + }) + .catch((err) => { + errorNotify('列车取消连接失败!', err); + }); + }); +} function linkTrain() { if (!lineStore.selectedGraphics) return; if (lineStore.deviceOpreratDialogInstance) return; diff --git a/src/drawApp/graphics/TrainInteraction.ts b/src/drawApp/graphics/TrainInteraction.ts index 4103107..030f3d5 100644 --- a/src/drawApp/graphics/TrainInteraction.ts +++ b/src/drawApp/graphics/TrainInteraction.ts @@ -10,7 +10,7 @@ import { ContextMenu, } from 'jl-graphic'; import { DisplayObject, FederatedMouseEvent } from 'pixi.js'; -import { removeTrain } from 'src/api/Simulation'; +import { removeTrain, cancelTrainConn } from 'src/api/Simulation'; import { useLineStore } from 'src/stores/line-store'; import { successNotify, errorNotify } from '../../utils/CommonNotify'; import { Dialog } from 'quasar'; @@ -696,6 +696,9 @@ const TrainParam: MenuItemOptions = { const TrainLink: MenuItemOptions = { name: '列车连接', }; +const CancelLink: MenuItemOptions = { + name: '取消连接', +}; const removeTrainConfig: MenuItemOptions = { name: '清除列车', }; @@ -703,7 +706,7 @@ const TrainOperateMenu: ContextMenu = ContextMenu.init({ name: '列车操作菜单', groups: [ { - items: [TrainParam, TrainLink, removeTrainConfig], + items: [TrainParam, TrainLink, CancelLink, removeTrainConfig], }, ], }); @@ -771,6 +774,24 @@ export class TrainOperateInteraction extends GraphicInteractionPlugin { persistent: true, }); }; + CancelLink.handler = () => { + Dialog.create({ + title: '确认', + message: `确认取消【${train.states.id}】列车的连接吗?`, + cancel: true, + }).onOk(async () => { + cancelTrainConn({ + id: simulationId, + trainId: train.code, + }) + .then(() => { + successNotify('列车取消连接成功!'); + }) + .catch((err) => { + errorNotify('列车取消连接失败!', err); + }); + }); + }; removeTrainConfig.handler = () => { Dialog.create({ title: '确认',