From 78b7b6be9f8409607d20eb91d0f9385084dc1507 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Fri, 30 Aug 2024 10:13:13 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=89=8B=E6=9F=84=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E9=A2=91=E7=8E=87+=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E7=99=BE=E5=88=86=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drawApp/graphics/TccHandleInteraction.ts | 36 ++++++++++++++++---- src/graphics/tccHandle/TccHandle.ts | 16 ++++++++- src/stores/tcc-store.ts | 18 ++-------- 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/drawApp/graphics/TccHandleInteraction.ts b/src/drawApp/graphics/TccHandleInteraction.ts index d793c42..07eb7bd 100644 --- a/src/drawApp/graphics/TccHandleInteraction.ts +++ b/src/drawApp/graphics/TccHandleInteraction.ts @@ -3,6 +3,7 @@ import { ITccHandleData, ITccHandleState, TccHandle, + zeroOffset, } from 'src/graphics/tccHandle/TccHandle'; import { tccGraphicData } from 'src/protos/tccGraphics'; import { GraphicDataBase, GraphicStateBase } from './GraphicDataBase'; @@ -105,7 +106,7 @@ export class TccHandleInteraction extends GraphicInteractionPlugin { }; g._tccHandle.onmouseup = (e) => { e.stopPropagation(); - this.onMouseUp(); + this.onMouseUp(e); }; g.onmousemove = (e) => { e.stopPropagation(); @@ -123,6 +124,7 @@ export class TccHandleInteraction extends GraphicInteractionPlugin { const target = e.target as DisplayObject; const tccHandle = target.getGraphic(); if (!tccHandle) return; + tccHandle.canDoRepaint = false; useTccStore().tccHandleId = tccHandle.id; useTccStore().mouseDownOnTccHandle = true; this.isMouseDown = true; @@ -146,13 +148,35 @@ export class TccHandleInteraction extends GraphicInteractionPlugin { } else if (tccHandle._tccHandle.y <= -145) { tccHandle._tccHandle.y = -144; } - clearTimeout(this.timeout); - this.timeout = setTimeout(() => { - useTccStore().onMouseUpFromTccHandle(); - }, 100); + let transFormHandleVal = 0; + if ( + tccHandle._tccHandle.y >= -zeroOffset && + tccHandle._tccHandle.y <= zeroOffset + ) { + tccHandle._tccHandle.y = 0; + } else if (tccHandle._tccHandle.y < -zeroOffset) { + transFormHandleVal = tccHandle._tccHandle.y + zeroOffset; + } else { + transFormHandleVal = tccHandle._tccHandle.y - zeroOffset; + } + tccHandle._stateVal = Number( + (-(transFormHandleVal / (144 - zeroOffset)) * 100).toFixed() + ); + tccHandle.labelGraphic.text = Math.abs(tccHandle._stateVal) + '%'; + tccHandle.labelGraphic.y = tccHandle._tccHandle.y; + if (this.timeout == undefined) { + this.timeout = setTimeout(() => { + useTccStore().onMouseUpFromTccHandle(); + this.timeout = undefined; + }, 100); + } } } - onMouseUp() { + onMouseUp(e: FederatedMouseEvent) { + const target = e.target as DisplayObject; + const tccHandle = target.getGraphic(); + if (!tccHandle) return; + tccHandle.canDoRepaint = true; this.isMouseDown = false; useTccStore().mouseDownOnTccHandle = false; } diff --git a/src/graphics/tccHandle/TccHandle.ts b/src/graphics/tccHandle/TccHandle.ts index 03330fd..1f6a238 100644 --- a/src/graphics/tccHandle/TccHandle.ts +++ b/src/graphics/tccHandle/TccHandle.ts @@ -3,6 +3,7 @@ import { GraphicState, JlGraphic, JlGraphicTemplate, + VectorText, } from 'jl-graphic'; import Tcc_Handle_Assets from './tcc-handle-spritesheet.png'; import Tcc_Handle_JSON from './tcc-handle-data.json'; @@ -30,7 +31,9 @@ export class TccHandle extends JlGraphic { _tccHandle: Sprite; _tccHandleBackground: Sprite; tccHandleTextures: TccHandleTextures; - __state = 0; + labelGraphic = new VectorText(); + _stateVal = 0; + canDoRepaint = true; constructor(tccHandleTextures: TccHandleTextures) { super(TccHandle.Type); @@ -44,6 +47,8 @@ export class TccHandle extends JlGraphic { this._tccHandleBackground.position.x = -20; this.addChild(this._tccHandleBackground); this.addChild(this._tccHandle); + this.setTextGraphic(this.labelGraphic); + this.addChild(this.labelGraphic); } get code(): string { return this.datas.code; @@ -55,6 +60,7 @@ export class TccHandle extends JlGraphic { return this.getStates(); } doRepaint(): void { + if (!this.canDoRepaint) return; const pos = -(this.state.gear * (144 - zeroOffset)) / 100; if (pos > 0) { this._tccHandle.y = pos + zeroOffset; @@ -63,8 +69,16 @@ export class TccHandle extends JlGraphic { } else { this._tccHandle.y = 0; } + this.labelGraphic.y = this._tccHandle.y; + this.labelGraphic.text = Math.abs(this.state.gear) + '%'; this._tccHandle.texture = this.tccHandleTextures.tccHandle; } + setTextGraphic(g: VectorText) { + g.position.x = 50; + g.setVectorFontSize(15); + g.anchor.set(0.5); + g.style.fill = '0xff0000'; + } } export class TccHandleTemplate extends JlGraphicTemplate { diff --git a/src/stores/tcc-store.ts b/src/stores/tcc-store.ts index 3b85023..25e55f8 100644 --- a/src/stores/tcc-store.ts +++ b/src/stores/tcc-store.ts @@ -5,7 +5,7 @@ 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, zeroOffset } from 'src/graphics/tccHandle/TccHandle'; +import { TccHandle } from 'src/graphics/tccHandle/TccHandle'; import { TccKey } from 'src/graphics/tccKey/TccKey'; import { IGraphicApp } from 'jl-graphic'; @@ -47,27 +47,13 @@ export const useTccStore = defineStore('tcc', { .getScene(`tcc${this.tccId}`) .queryStore.queryById(this.tccHandleId); if (!simulationId) return; - let transFormHandleVal = 0; - if ( - tccHandle._tccHandle.y >= -zeroOffset && - tccHandle._tccHandle.y <= zeroOffset - ) { - tccHandle._tccHandle.y = 0; - } else if (tccHandle._tccHandle.y < -zeroOffset) { - transFormHandleVal = tccHandle._tccHandle.y + zeroOffset; - } else { - transFormHandleVal = tccHandle._tccHandle.y - zeroOffset; - } - const handleVal = Number( - (-(transFormHandleVal / (144 - zeroOffset)) * 100).toFixed() - ); tccOperation({ simulationId, trainId: this.tccId + '', deviceId: this.tccHandleId, controlType: request.TrainControl.TrainControlType.HANDLER, handler: { - val: handleVal, + val: tccHandle._stateVal, }, }).catch((err) => { errorNotify('操作失败', { message: err.origin.response.data.title }); From 30681803ec7b33ece1070a7b9f439b17e49677e1 Mon Sep 17 00:00:00 2001 From: joylink_fanyuhong <18706759286@163.com> Date: Fri, 30 Aug 2024 10:20:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E5=8F=82=E6=95=B0=20-=E6=9C=80=E5=A4=A7=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/TrainModelManage.vue | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/pages/TrainModelManage.vue b/src/pages/TrainModelManage.vue index 8382104..da0cc1b 100644 --- a/src/pages/TrainModelManage.vue +++ b/src/pages/TrainModelManage.vue @@ -287,16 +287,6 @@ hint="" /> -
- -