From 2ab1396e33d328aea6532129560d1495d4f46153 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Wed, 3 Apr 2024 09:32:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=97=E8=BD=A6=E9=A9=BE=E9=A9=B6?= =?UTF-8?q?=E5=8F=B0=E4=BA=A4=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/Simulation.ts | 53 +++-------- src/configs/UrlManage.ts | 2 +- src/drawApp/graphics/TccButtonInteraction.ts | 22 ++--- src/drawApp/graphics/TccHandleInteraction.ts | 19 ++-- src/drawApp/graphics/TccKeyInteraction.ts | 94 ++++++++++---------- src/graphics/tccHandle/TccHandle.ts | 2 +- src/protos/request.ts | 16 ++-- 7 files changed, 87 insertions(+), 121 deletions(-) diff --git a/src/api/Simulation.ts b/src/api/Simulation.ts index cc845ab..a988806 100644 --- a/src/api/Simulation.ts +++ b/src/api/Simulation.ts @@ -184,51 +184,18 @@ export async function ibpKeyOperation(params: IbpKeyOperationParams) { return await api.post(`${UriBase}/ibp/key/operation`, params); } -export interface TccButtonOperationParams { - buttonId: number; - down: boolean; - mapId: number; +export interface TccOperationParams { simulationId: string; - tccId: number; + trainId: string; + deviceId: number; + controlType: request.TrainControl.TrainControlType; + button?: object; + driverKey?: object; + dirKey?: object; + handler?: object; } -export async function tccButtonOperation(params: TccButtonOperationParams) { - return await api.post(`${UriBase}/tcc/btn/operation`, params); -} - -export interface TccKeyOperationParams { - simulationId: string; - mapId: number; - tccId: number; - val: boolean; - keyId: number; -} - -export async function tccKeyOperation(params: TccKeyOperationParams) { - return await api.post(`${UriBase}/tcc/key/operation`, params); -} - -export interface TccKeyDirOperationParams { - simulationId: string; - mapId: number; - tccId: number; - val: number; - keyId: number; -} - -export async function tccKeyDirOperation(params: TccKeyDirOperationParams) { - return await api.post(`${UriBase}/tcc/key/operation`, params); -} - -export interface TccHandleOperationParams { - simulationId: string; - mapId: number; - tccId: number; - val: number; - handleId: number; -} - -export async function tccHandleOperation(params: TccHandleOperationParams) { - return await api.post(`${UriBase}/tcc/handle/operation`, params); +export async function tccOperation(params: TccOperationParams) { + return await api.post(`${UriBase}/train/control`, params); } export function checkMapData(data: { mapProto: string }) { diff --git a/src/configs/UrlManage.ts b/src/configs/UrlManage.ts index 6a575cd..d22c5bd 100644 --- a/src/configs/UrlManage.ts +++ b/src/configs/UrlManage.ts @@ -9,7 +9,7 @@ function getHost(): string { // return '192.168.3.7:9091'; // return '192.168.3.47:9091'; // return '192.168.3.37:9091'; - return '192.168.33.207:9091'; // 张骞 + //return '192.168.33.207:9091'; // 张骞 // return '192.168.33.93:9091'; // return '192.168.3.37:9091'; //卫志宏 // return 'test.joylink.club/bjrtsts-service'; // 测试 diff --git a/src/drawApp/graphics/TccButtonInteraction.ts b/src/drawApp/graphics/TccButtonInteraction.ts index 191ef9a..54ccd08 100644 --- a/src/drawApp/graphics/TccButtonInteraction.ts +++ b/src/drawApp/graphics/TccButtonInteraction.ts @@ -11,8 +11,9 @@ import { ITccButtonState, TccButton, } from 'src/graphics/tccButton/TccButton'; -import { tccButtonOperation } from 'src/api/Simulation'; +import { tccOperation } from 'src/api/Simulation'; import { errorNotify } from 'src/utils/CommonNotify'; +import { request } from 'src/protos/request'; export class TccButtonData extends GraphicDataBase implements ITccButtonData { constructor(data?: tccGraphicData.TccButton) { @@ -115,21 +116,20 @@ export class TccButtonOperateInteraction extends GraphicInteractionPlugin(); - if (!tccButton || !simulationId || !mapId) return; - tccButton.states.down = !tccButton.states.down; - tccButton.doRepaint(); - /* tccButtonOperation({ + if (!tccButton || !simulationId) return; + tccOperation({ simulationId, - mapId, - buttonId: tccButton.id, - tccId, - down: !tccButton.states.down, + trainId: tccId + '', + deviceId: tccButton.id, + controlType: request.TrainControl.TrainControlType.EMERGENT_BUTTON, + button: { + active: !tccButton.states.down, + }, }).catch((err) => { errorNotify('操作失败', { message: err.origin.response.data.title }); - }); */ + }); } } diff --git a/src/drawApp/graphics/TccHandleInteraction.ts b/src/drawApp/graphics/TccHandleInteraction.ts index 9f60ad3..812429e 100644 --- a/src/drawApp/graphics/TccHandleInteraction.ts +++ b/src/drawApp/graphics/TccHandleInteraction.ts @@ -11,8 +11,9 @@ import { GraphicInteractionPlugin, IGraphicScene, JlGraphic } from 'jl-graphic'; import { type FederatedMouseEvent, DisplayObject } from 'pixi.js'; import { useTccStore } from 'src/stores/tcc-store'; import { useLineStore } from 'src/stores/line-store'; -import { tccHandleOperation } from 'src/api/Simulation'; +import { tccOperation } from 'src/api/Simulation'; import { errorNotify } from 'src/utils/CommonNotify'; +import { request } from 'src/protos/request'; export class TccHandleData extends GraphicDataBase implements ITccHandleData { constructor(data?: tccGraphicData.TccHandle) { @@ -156,15 +157,17 @@ export class TccHandleInteraction extends GraphicInteractionPlugin { const target = e.target as DisplayObject; const tccHandle = target.getGraphic(); if (!tccHandle || !simulationId || !mapId) return; - tccHandle.doRepaint(); - /* tccHandleOperation({ + const handleVal = Math.floor(-(tccHandle._tccHandle.y / 144) * 100); + tccOperation({ simulationId, - mapId, - handleId: tccHandle.id, - tccId, - val: tccHandle._tccHandle.y, + trainId: tccId + '', + deviceId: tccHandle.id, + controlType: request.TrainControl.TrainControlType.HANDLER, + handler: { + val: handleVal, + }, }).catch((err) => { errorNotify('操作失败', { message: err.origin.response.data.title }); - }); */ + }); } } diff --git a/src/drawApp/graphics/TccKeyInteraction.ts b/src/drawApp/graphics/TccKeyInteraction.ts index 75a16aa..32e6059 100644 --- a/src/drawApp/graphics/TccKeyInteraction.ts +++ b/src/drawApp/graphics/TccKeyInteraction.ts @@ -11,10 +11,10 @@ import { Sprite, } from 'pixi.js'; import { useTccStore } from 'src/stores/tcc-store'; -import { threadId } from 'worker_threads'; import { useLineStore } from 'src/stores/line-store'; -import { tccKeyDirOperation, tccKeyOperation } from 'src/api/Simulation'; +import { tccOperation } from 'src/api/Simulation'; import { errorNotify } from 'src/utils/CommonNotify'; +import { request } from 'src/protos/request'; export class TccKeyData extends GraphicDataBase implements ITccKeyData { constructor(data?: tccGraphicData.TccKey) { @@ -97,7 +97,6 @@ export interface IKeyInteractionConfig { gearPositionAmount?: number; keyRotationMethod: KeyRotationMethod; doAfterChangeRotation: (g: JlGraphic, rotation: number) => void; - doFinish: () => void; } export abstract class KeyInteraction< G extends JlGraphic @@ -107,6 +106,7 @@ export abstract class KeyInteraction< mouseDownBeginPos = new Point(); mouseDownBeginRotation = 0; keyInteractionConfig: IKeyInteractionConfig; + lastTimenRotation = 0; constructor( name: string, app: IGraphicScene, @@ -122,7 +122,6 @@ export abstract class KeyInteraction< g.onmouseup = (e) => { e.stopPropagation(); this.isMouseDown = false; - this.keyInteractionConfig.doFinish(); }; } totalUnbind(g: G): void { @@ -148,6 +147,7 @@ export abstract class KeyInteraction< this.isMouseDown = true; this.mouseDownBeginPos = this.app.toCanvasCoordinates(e.global); this.mouseDownBeginRotation = this.ratatingSprite.rotation; + this.lastTimenRotation = this.ratatingSprite.rotation; } onMousemove(e: FederatedMouseEvent) { const target = e.target as DisplayObject; @@ -160,46 +160,44 @@ export abstract class KeyInteraction< g.position, mouseEndPos ); + let changeRotation = 0; if ( this.keyInteractionConfig.keyRotationMethod == KeyRotationMethod.jumpChange ) { if (direction == 'ssz') { if (angle < 45) { - this.ratatingSprite.rotation = this.mouseDownBeginRotation; + changeRotation = this.mouseDownBeginRotation; } - if (angle >= 45 && angle < 90) { - this.ratatingSprite.rotation = - this.mouseDownBeginRotation + Math.PI / 4; + if ( + angle >= 45 && + angle < 90 && + this.mouseDownBeginRotation !== Math.PI / 4 + ) { + changeRotation = this.mouseDownBeginRotation + Math.PI / 4; } else if ( angle >= 90 && this.mouseDownBeginRotation == -Math.PI / 4 ) { - this.ratatingSprite.rotation = - this.mouseDownBeginRotation + Math.PI / 2; + changeRotation = this.mouseDownBeginRotation + Math.PI / 2; + } + if (this.lastTimenRotation !== changeRotation) { + this.lastTimenRotation = changeRotation; + this.keyInteractionConfig.doAfterChangeRotation(g, changeRotation); } - this.keyInteractionConfig.doAfterChangeRotation( - g, - this.ratatingSprite.rotation - ); } if (direction == 'nsz') { if (angle < 45) { - this.ratatingSprite.rotation = this.mouseDownBeginRotation; + changeRotation = this.mouseDownBeginRotation; } else if (angle >= 45 && angle < 90) { - this.ratatingSprite.rotation = - this.mouseDownBeginRotation - Math.PI / 4; - } else if ( - angle >= 90 && - this.mouseDownBeginRotation == Math.PI / 4 - ) { - this.ratatingSprite.rotation = - this.mouseDownBeginRotation - Math.PI / 2; + changeRotation = this.mouseDownBeginRotation - Math.PI / 4; + } else if (angle >= 90 && changeRotation == Math.PI / 4) { + changeRotation = this.mouseDownBeginRotation - Math.PI / 2; + } + if (this.lastTimenRotation !== changeRotation) { + this.lastTimenRotation = changeRotation; + this.keyInteractionConfig.doAfterChangeRotation(g, changeRotation); } - this.keyInteractionConfig.doAfterChangeRotation( - g, - this.ratatingSprite.rotation - ); } } else { if (direction == 'ssz') { @@ -223,9 +221,6 @@ export class TccKeyInteraction extends KeyInteraction { doAfterChangeRotation: (g: JlGraphic, rotation: number) => { this.changeState(g, rotation); }, - doFinish: () => { - this.onFinish(); - }, }); } static init(app: IGraphicScene) { @@ -266,17 +261,20 @@ export class TccKeyInteraction extends KeyInteraction { const target = e.target as DisplayObject; const tccKey = target.getGraphic(); if (!tccKey || !simulationId || !mapId) return; - tccKey.state.position = tccKey?.state.position == 0 ? 1 : 0; - tccKey.doRepaint(); - /* tccKeyOperation({ + const state = tccKey?.state.position == 0 ? true : false; + const driverKeyType = tccKey?.datas.code == '司控器钥匙1' ? 0 : 1; + tccOperation({ simulationId, - mapId, - keyId: tccKey.id, - tccId, - val: !tccKey.state.position, + trainId: tccId + '', + deviceId: tccKey.id, + controlType: request.TrainControl.TrainControlType.DRIVER_KEY_SWITCH, + driverKey: { + val: state, + dt: driverKeyType, + }, }).catch((err) => { errorNotify('操作失败', { message: err.origin.response.data.title }); - }); */ + }); } changeState(g: JlGraphic, rotation: number) { let position = 0; @@ -292,22 +290,20 @@ export class TccKeyInteraction extends KeyInteraction { break; } (g as TccKey).state.position = position; - g.doRepaint(); - } - onFinish() { const simulationId = useLineStore().simulationId; - const mapId = useLineStore().mapId; const tccId = useTccStore().tccId; - if (!simulationId || !mapId) return; - /* tccKeyDirOperation({ + if (!simulationId) return; + tccOperation({ simulationId, - mapId, - keyId: g.id, - tccId, - val: (g as TccKey).state.position, + trainId: tccId + '', + deviceId: g.id, + controlType: request.TrainControl.TrainControlType.DIRECTION_KEY_SWITCH, + dirKey: { + val: position, + }, }).catch((err) => { errorNotify('操作失败', { message: err.origin.response.data.title }); - }); */ + }); } } diff --git a/src/graphics/tccHandle/TccHandle.ts b/src/graphics/tccHandle/TccHandle.ts index 258d0fc..c346e01 100644 --- a/src/graphics/tccHandle/TccHandle.ts +++ b/src/graphics/tccHandle/TccHandle.ts @@ -54,7 +54,7 @@ export class TccHandle extends JlGraphic { return this.getStates(); } doRepaint(): void { - this._tccHandle.rotation = (-Math.PI / 2) * this.state.gear; + this._tccHandle.y = -Math.floor((this.state.gear * 144) / 100); this._tccHandle.texture = this.tccHandleTextures.tccHandle; } } diff --git a/src/protos/request.ts b/src/protos/request.ts index 5a70d21..09c9241 100644 --- a/src/protos/request.ts +++ b/src/protos/request.ts @@ -1422,7 +1422,7 @@ export namespace request { #one_of_decls: number[][] = []; constructor(data?: any[] | { simulationId?: string; - trainId?: number; + trainId?: string; deviceId?: number; controlType?: TrainControl.TrainControlType; button?: TrainControl.EmergentButton; @@ -1466,9 +1466,9 @@ export namespace request { pb_1.Message.setField(this, 1, value); } get trainId() { - return pb_1.Message.getFieldWithDefault(this, 2, 0) as number; + return pb_1.Message.getFieldWithDefault(this, 2, "") as string; } - set trainId(value: number) { + set trainId(value: string) { pb_1.Message.setField(this, 2, value); } get deviceId() { @@ -1521,7 +1521,7 @@ export namespace request { } static fromObject(data: { simulationId?: string; - trainId?: number; + trainId?: string; deviceId?: number; controlType?: TrainControl.TrainControlType; button?: ReturnType; @@ -1559,7 +1559,7 @@ export namespace request { toObject() { const data: { simulationId?: string; - trainId?: number; + trainId?: string; deviceId?: number; controlType?: TrainControl.TrainControlType; button?: ReturnType; @@ -1599,8 +1599,8 @@ export namespace request { const writer = w || new pb_1.BinaryWriter(); if (this.simulationId.length) writer.writeString(1, this.simulationId); - if (this.trainId != 0) - writer.writeUint32(2, this.trainId); + if (this.trainId.length) + writer.writeString(2, this.trainId); if (this.deviceId != 0) writer.writeUint32(3, this.deviceId); if (this.controlType != TrainControl.TrainControlType.EMERGENT_BUTTON) @@ -1626,7 +1626,7 @@ export namespace request { message.simulationId = reader.readString(); break; case 2: - message.trainId = reader.readUint32(); + message.trainId = reader.readString(); break; case 3: message.deviceId = reader.readUint32(); From 3e44d8fae4ba6617213a897d4ff8c3fad1725968 Mon Sep 17 00:00:00 2001 From: joylink_fanyuhong <18706759286@163.com> Date: Wed, 3 Apr 2024 10:13:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=85=B3=E9=97=AD=E5=88=97=E8=BD=A6?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/draw-app/dialogs/SetTrainLink.vue | 6 +++++- src/configs/UrlManage.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/draw-app/dialogs/SetTrainLink.vue b/src/components/draw-app/dialogs/SetTrainLink.vue index 5ec2853..def0f40 100644 --- a/src/components/draw-app/dialogs/SetTrainLink.vue +++ b/src/components/draw-app/dialogs/SetTrainLink.vue @@ -38,10 +38,11 @@ diff --git a/src/configs/UrlManage.ts b/src/configs/UrlManage.ts index 6a575cd..de7f757 100644 --- a/src/configs/UrlManage.ts +++ b/src/configs/UrlManage.ts @@ -9,7 +9,7 @@ function getHost(): string { // return '192.168.3.7:9091'; // return '192.168.3.47:9091'; // return '192.168.3.37:9091'; - return '192.168.33.207:9091'; // 张骞 + // return '192.168.33.207:9091'; // 张骞 // return '192.168.33.93:9091'; // return '192.168.3.37:9091'; //卫志宏 // return 'test.joylink.club/bjrtsts-service'; // 测试