From ce79f7c56c3832d1a4ebdb1d7d1c2bbd87d8b004 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期一, 21 十月 2024 13:56:03 +0800
Subject: [PATCH] #
---
zy-acs-flow/src/map/tool.js | 146 ++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 134 insertions(+), 12 deletions(-)
diff --git a/zy-acs-flow/src/map/tool.js b/zy-acs-flow/src/map/tool.js
index ca422a7..c84c2ca 100644
--- a/zy-acs-flow/src/map/tool.js
+++ b/zy-acs-flow/src/map/tool.js
@@ -4,7 +4,14 @@
DEVICE_TYPE,
DEVICE_Z_INDEX,
AGV_STATUS_MODE,
+ DEVICE_SPRITE_TINT,
+ DEVICE_SELECTED_EFFECT_PADDING,
+ DEVICE_SELECTED_EFFECT_COLOR,
+ POINT_ROUTE_DIRECTION,
+ DEVICE_SPRITE_TINT_DARK,
} from './constants';
+import { getRouteList } from './http';
+import PointRoute from "./PointRoute";
import shelf from '/map/shelf.svg';
import charge from '/map/charge.svg';
@@ -21,6 +28,7 @@
let app, mapContainer, themeMode;
let selectedSprite, effectCircle, effectTicker;
+let tooltip;
export function getApp() {
return app;
@@ -44,6 +52,21 @@
export function setThemeMode(param) {
themeMode = param;
+ if (mapContainer) {
+ // mapContainer.children.forEach(child => {
+ // const deviceType = child.data?.type;
+ // if (deviceType) {
+ // if (themeMode === 'dark') {
+ // const tint = DEVICE_SPRITE_TINT_DARK[deviceType]
+ // if (tint) {
+ // child.tint = tint;
+ // }
+ // } else {
+ // DEVICE_SPRITE_TINT[deviceType] != null && (child.tint = DEVICE_SPRITE_TINT[deviceType]);
+ // }
+ // }
+ // })
+ }
}
@@ -101,6 +124,9 @@
default:
break;
}
+ const tintType = themeMode === 'dark' ? DEVICE_SPRITE_TINT_DARK : DEVICE_SPRITE_TINT;
+ tintType[deviceType] != null && (sprite.tint = tintType[deviceType]);
+
if (sprite && deviceType !== DEVICE_TYPE.AGV) {
sprite.blendMode = PIXI.BLEND_MODES.MULTIPLY;
}
@@ -218,23 +244,30 @@
}
export const beInsight = (sprite, setCurSprite) => {
+ if (!sprite?.data?.type) { return }
+
sprite.off('pointerup');
sprite.off('pointermove');
sprite.off('pointerdown');
+ sprite.off('pointerover');
+ sprite.off('pointerout');
sprite.off('click');
- sprite.on("click", onClick);
-
- function onClick(event) {
+ sprite.on("click", (event) => {
setCurSprite(sprite);
- }
+ });
+ sprite.on('pointerover', onSpriteMouseOver);
+ sprite.on('pointermove', onSpriteMouseMove);
+ sprite.on('pointerout', onSpriteMouseOut);
}
export const beMovable = (sprite) => {
sprite.off('pointerup');
sprite.off('pointermove');
sprite.off('pointerdown');
+ sprite.off('pointerover');
+ sprite.off('pointerout');
sprite.off('click');
sprite.on("pointerdown", onDragStart);
@@ -269,15 +302,71 @@
}
export const beSettings = (sprite, setSpriteSettings) => {
+ if (!sprite?.data?.type) { return }
+
sprite.off('pointerup');
sprite.off('pointermove');
sprite.off('pointerdown');
+ sprite.off('pointerover');
+ sprite.off('pointerout');
sprite.off('click');
- sprite.on("click", onClick);
-
- function onClick(event) {
+ sprite.on("click", (event) => {
setSpriteSettings(sprite);
+ });
+
+ sprite.on('pointerover', onSpriteMouseOver);
+ sprite.on('pointermove', onSpriteMouseMove);
+ sprite.on('pointerout', onSpriteMouseOut);
+}
+
+const createSpriteTooltip = (sprite) => {
+ const style = new PIXI.TextStyle({
+ fontFamily: 'Roboto',
+ fontSize: 12,
+ fill: themeMode === 'light' ? '#000' : '#eee',
+ });
+ const text = new PIXI.Text(`${sprite.data?.type} ${sprite.data?.no}`, style);
+ const background = new PIXI.Graphics();
+ // shadow
+ background.beginFill(themeMode === 'light' ? '#000' : '#eee', 0.1);
+ background.drawRoundedRect(4, 4, text.width + 6, text.height + 6, 4);
+ background.endFill();
+ // background
+ background.beginFill(themeMode === 'light' ? '#fff' : '#333', 1);
+ background.drawRoundedRect(0, 0, text.width + 8, text.height + 8, 4);
+ background.endFill();
+
+ text.x = 5;
+ text.y = 3;
+ background.addChild(text);
+ tooltip = new PIXI.Container();
+ tooltip.name = "tooltip";
+ tooltip.addChild(background);
+ return tooltip;
+}
+
+function onSpriteMouseOver(event) {
+ if (tooltip) {
+ app.stage.removeChild(tooltip);
+ }
+ tooltip = createSpriteTooltip(this);// this => sprite
+ tooltip.x = event.data.global.x + 10;
+ tooltip.y = event.data.global.y + 10;
+ app.stage.addChild(tooltip);
+}
+
+function onSpriteMouseMove(event) {
+ if (tooltip) {
+ tooltip.x = event.data.global.x + 10;
+ tooltip.y = event.data.global.y + 10;
+ }
+}
+
+function onSpriteMouseOut() {
+ if (tooltip && tooltip.parent) {
+ tooltip.parent.removeChild(tooltip);
+ tooltip = null;
}
}
@@ -337,10 +426,17 @@
const { width, height } = sprite;
const maxDimension = Math.max(width, height);
- const radius = (maxDimension / 2) + maxDimension / 5;
+ const radius = (maxDimension / 2) + (DEVICE_SELECTED_EFFECT_PADDING[sprite.data?.type] || 10);
- const color = themeMode === 'light' ? 0x2f68ac : 0xffffff;
- const alpha = .5;
+ let color;
+ const spriteEffectColor = DEVICE_SELECTED_EFFECT_COLOR[sprite.data?.type];
+ if (spriteEffectColor) {
+ color = spriteEffectColor;
+ } else {
+ color = themeMode === 'light' ? '#747d8c' : '#718093';
+ }
+
+ const alpha = 1;
effectCircle = new PIXI.Graphics();
effectCircle.beginFill(color, alpha);
@@ -383,7 +479,6 @@
}
if (effectCircle) {
mapContainer.removeChild(effectCircle);
- effectCircle.destroy();
effectCircle = null;
}
selectedSprite = null;
@@ -393,10 +488,37 @@
if (!selectedSprite || !effectCircle) {
return;
}
- // 鏇存柊鍦嗙殑浣嶇疆锛岀‘淇濊窡闅弒prite
effectCircle.position.set(selectedSprite.x, selectedSprite.y);
};
+export const showRoutes = (curZone, setShowRoutes) => {
+ setShowRoutes(true);
+ getRouteList(curZone, (routeList) => {
+ routeList.forEach(route => {
+ const startPoint = querySprite(DEVICE_TYPE.POINT, route.startCodeStr);
+ const endPoint = querySprite(DEVICE_TYPE.POINT, route.endCodeStr);
+ const pointRoute = new PointRoute(POINT_ROUTE_DIRECTION[route.direction]);
+ pointRoute.setPoint(startPoint, endPoint);
+ pointRoute.clear();
+ pointRoute.lineStyle(8, themeMode === 'light' ? '#2d3436' : '#dcdde1');
+ pointRoute.moveTo(startPoint.position.x, startPoint.position.y);
+ pointRoute.lineTo(endPoint.position.x, endPoint.position.y);
+ pointRoute.alpha = 1;
+ mapContainer.addChild(pointRoute);
+ })
+ })
+};
+
+export const hideRoutes = (curZone, setShowRoutes) => {
+ setShowRoutes(false);
+ for (let i = mapContainer.children.length - 1; i >= 0; i--) {
+ const child = mapContainer.children[i];
+ if (child?.type === DEVICE_TYPE.ROUTE) {
+ mapContainer.removeChild(child);
+ }
+ }
+}
+
export const multipleSelectEnhancer = (selectedSprites, setCurSprite, setBatchSprites) => {
selectedSprites = selectedSprites.filter(sprite => sprite.data?.type);
--
Gitblit v1.9.1