From e894f02e387f77f77f06fe50cd36e1dec70c8d46 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Wed, 3 Apr 2024 11:17:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=BD=A6=E9=A9=BE=E9=A9=B6=E5=8F=B0?= =?UTF-8?q?=E4=BA=A4=E4=BA=92=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drawApp/graphics/TccHandleInteraction.ts | 36 +++++--------------- src/drawApp/tccScene.ts | 3 ++ src/graphics/tccHandle/TccHandle.ts | 2 +- src/stores/tcc-store.ts | 28 +++++++++++++++ 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/drawApp/graphics/TccHandleInteraction.ts b/src/drawApp/graphics/TccHandleInteraction.ts index 812429e..c625b47 100644 --- a/src/drawApp/graphics/TccHandleInteraction.ts +++ b/src/drawApp/graphics/TccHandleInteraction.ts @@ -10,10 +10,6 @@ import { state } from 'src/protos/device_state'; 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 { 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) { @@ -103,15 +99,15 @@ export class TccHandleInteraction extends GraphicInteractionPlugin { g._tccHandle.eventMode = 'static'; g._tccHandle.cursor = 'Move'; g._tccHandle.onmousedown = (e) => { + e.stopPropagation(); this.onMouseDown(e); }; g._tccHandle.onmouseup = (e) => { - this.onMouseUp(e); + e.stopPropagation(); + this.onMouseUp(); }; g.onmousemove = (e) => { - this.onMouseMove(e); - }; - g.onmouseleave = (e) => { + e.stopPropagation(); this.onMouseMove(e); }; } @@ -120,12 +116,13 @@ export class TccHandleInteraction extends GraphicInteractionPlugin { g._tccHandle.onmousedown = null; g._tccHandle.onmouseup = null; g.onmousemove = null; - g.onmouseleave = null; } onMouseDown(e: FederatedMouseEvent) { const target = e.target as DisplayObject; const tccHandle = target.getGraphic(); if (!tccHandle) return; + useTccStore().tccHandleId = tccHandle.id; + useTccStore().mouseDownOnTccHandle = true; this.isMouseDown = true; this.mouseDownBeginPos = e.clientY; this.mouseDownTccHandleBeginPos = tccHandle._tccHandle.y; @@ -149,25 +146,8 @@ export class TccHandleInteraction extends GraphicInteractionPlugin { } } } - onMouseUp(e: FederatedMouseEvent) { + onMouseUp() { this.isMouseDown = false; - const simulationId = useLineStore().simulationId; - const mapId = useLineStore().mapId; - const tccId = useTccStore().tccId; - const target = e.target as DisplayObject; - const tccHandle = target.getGraphic(); - if (!tccHandle || !simulationId || !mapId) return; - const handleVal = Math.floor(-(tccHandle._tccHandle.y / 144) * 100); - tccOperation({ - simulationId, - trainId: tccId + '', - deviceId: tccHandle.id, - controlType: request.TrainControl.TrainControlType.HANDLER, - handler: { - val: handleVal, - }, - }).catch((err) => { - errorNotify('操作失败', { message: err.origin.response.data.title }); - }); + useTccStore().mouseDownOnTccHandle = false; } } diff --git a/src/drawApp/tccScene.ts b/src/drawApp/tccScene.ts index c007eb9..a882aa9 100644 --- a/src/drawApp/tccScene.ts +++ b/src/drawApp/tccScene.ts @@ -59,6 +59,9 @@ export function initTccScene(lineApp: IGraphicApp, sceneName: string) { }; tccScene.canvas.onmouseup = () => { tccStore.canvasMouseDown = false; + if (tccStore.mouseDownOnTccHandle) { + tccStore.onMouseUpFromTccHandle(); + } }; lineApp.on('destroy', () => { tccScene.canvas.onmousedown = null; diff --git a/src/graphics/tccHandle/TccHandle.ts b/src/graphics/tccHandle/TccHandle.ts index c346e01..9a9ee93 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.y = -Math.floor((this.state.gear * 144) / 100); + this._tccHandle.y = -(this.state.gear * 144) / 100; this._tccHandle.texture = this.tccHandleTextures.tccHandle; } } diff --git a/src/stores/tcc-store.ts b/src/stores/tcc-store.ts index 1b7c1de..161b3e6 100644 --- a/src/stores/tcc-store.ts +++ b/src/stores/tcc-store.ts @@ -1,6 +1,11 @@ import { defineStore } from 'pinia'; import { initTccScene } from 'src/drawApp/tccScene'; import { getLineApp } from 'src/drawApp/lineApp'; +import { useLineStore } from './line-store'; +import { tccOperation } from 'src/api/Simulation'; +import { errorNotify } from 'src/utils/CommonNotify'; +import { request } from 'src/protos/request'; +import { TccHandle } from 'src/graphics/tccHandle/TccHandle'; export const useTccStore = defineStore('tcc', { state: () => ({ @@ -8,6 +13,8 @@ export const useTccStore = defineStore('tcc', { tccId: 0, isTccDialogOpen: false, canvasMouseDown: false, + mouseDownOnTccHandle: false, + tccHandleId: 0, }), actions: { getTccScene() { @@ -30,5 +37,26 @@ export const useTccStore = defineStore('tcc', { this.trainControlMapId = 0; this.isTccDialogOpen = false; }, + onMouseUpFromTccHandle() { + const simulationId = useLineStore().simulationId; + const tccHandle = this.getTccScene().queryStore.queryById( + this.tccHandleId + ); + if (!simulationId) return; + const handleVal = Number( + (-(tccHandle._tccHandle.y / 144) * 100).toFixed() + ); + tccOperation({ + simulationId, + trainId: this.tccId + '', + deviceId: this.tccHandleId, + controlType: request.TrainControl.TrainControlType.HANDLER, + handler: { + val: handleVal, + }, + }).catch((err) => { + errorNotify('操作失败', { message: err.origin.response.data.title }); + }); + }, }, });