From adcd2efd074eb3160c429ea8a5dfd537db1d1304 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期三, 17 十二月 2025 14:37:06 +0800
Subject: [PATCH] #

---
 zy-acs-flow/src/map/tool.js |  174 +++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 135 insertions(+), 39 deletions(-)

diff --git a/zy-acs-flow/src/map/tool.js b/zy-acs-flow/src/map/tool.js
index 3ebb75d..2bd45c6 100644
--- a/zy-acs-flow/src/map/tool.js
+++ b/zy-acs-flow/src/map/tool.js
@@ -31,7 +31,7 @@
 import ctuLoadedFullBattery from '/map/agv/ctuLoadedFullBattery.svg';
 
 let app, mapContainer, themeMode;
-let selectedSprite, effectCircle, effectTicker;
+let selectedSprite, effectOverlay, effectTicker;
 let tooltip;
 
 export function getApp() {
@@ -422,6 +422,38 @@
 }
 
 export const showSelectedEffect = (sprite) => {
+    if (!sprite) {
+        return;
+    }
+    // area
+    if (sprite.data?.type === DEVICE_TYPE.AREA) {
+        const { start, end } = sprite.data || {};
+        const hasBounds = start && end;
+        const minX = hasBounds ? Math.min(start.x, end.x) : 0;
+        const maxX = hasBounds ? Math.max(start.x, end.x) : 0;
+        const minY = hasBounds ? Math.min(start.y, end.y) : 0;
+        const maxY = hasBounds ? Math.max(start.y, end.y) : 0;
+        const width = hasBounds ? Math.abs(maxX - minX) : Math.abs(sprite.width);
+        const height = hasBounds ? Math.abs(maxY - minY) : Math.abs(sprite.height);
+        const centerX = hasBounds ? (minX + maxX) / 2 : sprite.x;
+        const centerY = hasBounds ? (minY + maxY) / 2 : sprite.y;
+        const color = DEVICE_SELECTED_EFFECT_COLOR[DEVICE_TYPE.AREA] || (themeMode === 'light' ? '#747d8c' : '#718093');
+        const lineWidth = Math.max(2, 4 / Math.abs(mapContainer.scale.x || 1));
+
+        effectOverlay = new PIXI.Graphics();
+        effectOverlay.lineStyle(lineWidth, color, 1);
+        effectOverlay.drawRect(-width / 2, -height / 2, width, height);
+        effectOverlay.position.set(centerX, centerY);
+        effectOverlay.zIndex = sprite.zIndex + 1;
+        effectOverlay.blendMode = PIXI.BLEND_MODES.NORMAL;
+        mapContainer.addChild(effectOverlay);
+
+        selectedSprite = sprite;
+        effectTicker = null;
+        return;
+    }
+
+    // others
     if (!sprite?.texture || !sprite?.texture?.valid) {
         return;
     }
@@ -440,15 +472,15 @@
 
     const alpha = 1;
 
-    effectCircle = new PIXI.Graphics();
-    effectCircle.beginFill(color, alpha);
-    effectCircle.drawCircle(0, 0, radius);
-    effectCircle.endFill();
-    effectCircle.position.set(sprite.x, sprite.y);
-    effectCircle.zIndex = -1;
-    effectCircle.blendMode = PIXI.BLEND_MODES.NORMAL;
+    effectOverlay = new PIXI.Graphics();
+    effectOverlay.beginFill(color, alpha);
+    effectOverlay.drawCircle(0, 0, radius);
+    effectOverlay.endFill();
+    effectOverlay.position.set(sprite.x, sprite.y);
+    effectOverlay.zIndex = -1;
+    effectOverlay.blendMode = PIXI.BLEND_MODES.NORMAL;
 
-    mapContainer.addChild(effectCircle);
+    mapContainer.addChild(effectOverlay);
 
     selectedSprite = sprite;
 
@@ -467,8 +499,8 @@
                 scalingUp = true;
             }
         }
-        effectCircle.scale.set(pulseScale);
-        effectCircle.position.set(sprite.x, sprite.y);
+        effectOverlay.scale.set(pulseScale);
+        effectOverlay.position.set(sprite.x, sprite.y);
     };
 
     app.ticker.add(effectTicker);
@@ -479,18 +511,11 @@
         app.ticker.remove(effectTicker);
         effectTicker = null;
     }
-    if (effectCircle) {
-        mapContainer?.removeChild(effectCircle);
-        effectCircle = null;
+    if (effectOverlay) {
+        mapContainer?.removeChild(effectOverlay);
+        effectOverlay = null;
     }
     selectedSprite = null;
-};
-
-export const updateEffect = () => {
-    if (!selectedSprite || !effectCircle) {
-        return;
-    }
-    effectCircle.position.set(selectedSprite.x, selectedSprite.y);
 };
 
 export const showRoutes = (curZone, setShowRoutes, setLoading) => {
@@ -881,15 +906,27 @@
 
 let areaDrawingCleanup = null;
 const AREA_COLOR = 0x3498db;
+const AREA_BORDER_COLOR = 0x6c7a89;
 
 const addAreaLabel = (draft, text, from, to) => {
     const centerX = (from.x + to.x) / 2;
     const centerY = (from.y + to.y) / 2;
-    const label = new PIXI.Text(text, {
-        fill: themeMode === 'dark' ? '#f1f2f6' : '#535353ff',
-        fontSize: 20 / Math.abs(mapContainer.scale.x || 1),
-        fontWeight: 'bold',
+    const currentScale = Math.abs(mapContainer.scale.x || 1);
+    const labelStyle = new PIXI.TextStyle({
+        fontFamily: 'Inter, "Segoe UI", sans-serif',
+        fill: themeMode === 'dark' ? '#f1f2f6' : '#606060ff',
+        fontSize: Math.max(16, 20 / currentScale),
+        fontWeight: 600,
+        letterSpacing: 10,
+        // stroke: themeMode === 'dark' ? '#1e272e' : '#ffffff',
+        // strokeThickness: Math.max(1, 2 / currentScale),
+        // dropShadow: true,
+        // dropShadowColor: themeMode === 'dark' ? '#00000066' : '#95a5a6',
+        // dropShadowBlur: 1.5,
+        // dropShadowAngle: Math.PI / 4,
+        // dropShadowDistance: 2,
     });
+    const label = new PIXI.Text(text ?? '', labelStyle);
     label.anchor.set(0.5);
     label.position.set(centerX, centerY);
     label.rotation = rotationParseNum(MAP_DEFAULT_ROTATION);
@@ -897,22 +934,47 @@
     draft.addChild(label);
 };
 
-export const loadAreas = (curZone) => {
+export const updateAreaSpriteName = (sprite, newName) => {
+    if (!sprite || sprite?.data?.type !== DEVICE_TYPE.AREA) {
+        return;
+    }
+    sprite.data.name = newName;
+    const label = sprite.children?.find((child) => child instanceof PIXI.Text);
+    if (label) {
+        label.text = newName ?? '';
+    }
+};
+
+export const removeAreaSprite = (sprite) => {
+    if (!sprite || sprite?.data?.type !== DEVICE_TYPE.AREA) {
+        return;
+    }
+    const parent = sprite.parent || mapContainer;
+    if (parent) {
+        parent.removeChild(sprite);
+    }
+    sprite.destroy({ children: true, texture: false, baseTexture: false });
+};
+
+export const loadAreas = (curZone, setCurSprite, callback) => {
     if (!mapContainer) return;
     clearAreas();
     fetchAreaList(curZone).then((areas) => {
         areas.forEach((area) => {
             const { name, color, id } = area || {};
-            const start = area?.start || (area?.startX != null ? { x: area.startX, y: area.startY } : null);
-            const end = area?.end || (area?.endX != null ? { x: area.endX, y: area.endY } : null);
-            if (!start || !end || !name) {
+            const start = area?.start;
+            const end = area?.end;
+            if (!start || !end || !name || !id) {
                 return;
             }
-            const g = createAreaGraphic({ name, start, end, color, id });
-            if (g) {
-                mapContainer.addChild(g);
+            const graphics = createAreaGraphic({ name, start, end, color, id }, setCurSprite);
+            if (graphics) {
+                mapContainer.addChild(graphics);
             }
         });
+        if (callback) {
+            callback(areas);
+        }
     });
 };
 
@@ -927,7 +989,7 @@
     }
 };
 
-const createAreaGraphic = ({ name, start, end, color, id }) => {
+const createAreaGraphic = ({ name, start, end, color, id }, setCurSprite) => {
     if (!mapContainer) return null;
     const from = start || { x: 0, y: 0 };
     const to = end || { x: 0, y: 0 };
@@ -935,8 +997,11 @@
 
     const draft = new PIXI.Graphics();
     draft.name = id ? `area_${id}` : 'area_' + generateID();
-    draft.zIndex = DEVICE_Z_INDEX.AREA;
-    draft.lineStyle(4 / Math.abs(mapContainer.scale.x || 1), areaColor, 0.8);
+    draft.zIndex = 0;
+    if (setCurSprite) {
+        draft.zIndex = DEVICE_Z_INDEX.AREA;
+    }
+    draft.lineStyle(1 / Math.abs(mapContainer.scale.x || 1), AREA_BORDER_COLOR, 0.9);
     draft.beginFill(areaColor, 0.18);
     draft.drawRect(
         Math.min(from.x, to.x),
@@ -946,11 +1011,17 @@
     );
     draft.endFill();
     addAreaLabel(draft, name, from, to);
-    draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.AREA, name, color: areaColor, id };
+    draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.AREA, name, color: areaColor, id, start: from, end: to };
+    draft.eventMode = 'static';
+    draft.cursor = 'pointer';
+    if (setCurSprite) {
+        draft.off('click');
+        draft.on('click', () => setCurSprite(draft));
+    }
     return draft;
 };
 
-export const startAreaDrawing = ({ promptText, onComplete, onFinish } = {}) => {
+export const startAreaDrawing = ({ promptText, onComplete, onFinish, setCurSprite } = {}) => {
     if (!mapContainer || !mapContainer.parent) {
         return false;
     }
@@ -973,7 +1044,7 @@
     const drawRect = (from, to) => {
         draft.clear();
         const strokeColor = areaColor;
-        draft.lineStyle(4 / Math.abs(mapContainer.scale.x || 1), strokeColor, 0.8);
+        draft.lineStyle(2 / Math.abs(mapContainer.scale.x || 1), AREA_BORDER_COLOR, 0.9);
         draft.beginFill(strokeColor, 0.18);
         draft.drawRect(
             Math.min(from.x, to.x),
@@ -1030,7 +1101,13 @@
         }
 
         addAreaLabel(draft, areaName, startPoint, endPoint);
-        draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.AREA, name: areaName, color: areaColor };
+        draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.AREA, name: areaName, color: areaColor, start: startPoint, end: endPoint };
+        draft.eventMode = 'static';
+        draft.cursor = 'pointer';
+        if (setCurSprite) {
+            draft.off('click');
+            draft.on('click', () => setCurSprite(draft));
+        }
 
         if (onComplete) {
             onComplete({
@@ -1048,3 +1125,22 @@
     stage.on('pointerup', handleUp);
     return true;
 };
+
+export const cancelAreaDrawing = () => {
+    if (areaDrawingCleanup) {
+        areaDrawingCleanup();
+    }
+};
+
+export const showAreas = (curZone, setShowAreas, setLoading) => {
+    setLoading(true);
+    loadAreas(curZone, null, (areas) => {
+        setLoading(false);
+        setShowAreas(true);
+    })
+};
+
+export const hideAreas = (curZone, setShowAreas) => {
+    clearAreas();
+    setShowAreas(false);
+};

--
Gitblit v1.9.1