From 714696d5a169d9a39b4dc7d0237287c9a81630f4 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期二, 09 十二月 2025 16:35:06 +0800
Subject: [PATCH] #
---
zy-acs-flow/src/map/http.js | 38 ++++++++++++
zy-acs-flow/src/map/tool.js | 103 +++++++++++++++++++++++++++-------
zy-acs-flow/src/map/MapPage.jsx | 6 +
3 files changed, 124 insertions(+), 23 deletions(-)
diff --git a/zy-acs-flow/src/map/MapPage.jsx b/zy-acs-flow/src/map/MapPage.jsx
index 5cc814a..9fa5b90 100644
--- a/zy-acs-flow/src/map/MapPage.jsx
+++ b/zy-acs-flow/src/map/MapPage.jsx
@@ -126,6 +126,7 @@
modeRef.current = mode;
Tool.removeSelectedEffect();
+ Tool.clearZones();
player.hideGridLines();
setInsightVisible(false);
@@ -171,6 +172,8 @@
break
case MAP_MODE.ZONING_MODE:
Tool.removeAgvGraphics();
+
+ Tool.loadZones(curZone);
break
default:
break
@@ -354,8 +357,9 @@
onClick={() => {
const started = Tool.startZoneDrawing({
promptText: translate('page.map.prompt.zoneName'),
- onComplete: ({ name }) => {
+ onComplete: ({ name, start, end, color }) => {
if (name) {
+ Http.saveZoneData(curZone, { name, start, end, color });
notify.success(translate('page.map.msg.zoneCreated', { name }));
}
},
diff --git a/zy-acs-flow/src/map/http.js b/zy-acs-flow/src/map/http.js
index b126eed..7fc2322 100644
--- a/zy-acs-flow/src/map/http.js
+++ b/zy-acs-flow/src/map/http.js
@@ -372,4 +372,42 @@
console.error(error.message);
}
return false;
+}
+
+
+export const fetchZoneList = async (zoneId) => {
+ try {
+ const res = await request.post('/map/zone/list', {
+ zoneId: zoneId,
+ }, {
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
+ });
+ const { code, msg, data } = res.data;
+ if (code === 200) {
+ return data || [];
+ } else {
+ notify.error(msg);
+ return [];
+ }
+ } catch (error) {
+ notify.error(error.message);
+ console.error(error.message);
+ return [];
+ }
+}
+
+export const saveZoneData = async (zoneId, zoneData) => {
+ try {
+ const res = await request.post('/map/zone/save', {
+ zoneId: zoneId,
+ zone: zoneData,
+ });
+ const { code, msg } = res.data;
+ if (code !== 200) {
+ notify.error(msg);
+ }
+ } catch (error) {
+ notify.error(error.message);
+ console.error(error.message);
+ }
}
\ No newline at end of file
diff --git a/zy-acs-flow/src/map/tool.js b/zy-acs-flow/src/map/tool.js
index b88ce16..676dbf4 100644
--- a/zy-acs-flow/src/map/tool.js
+++ b/zy-acs-flow/src/map/tool.js
@@ -14,7 +14,7 @@
ANIMATE_DURING_TIME,
AGV_ANGLE_OFFSET_VAL,
} from './constants';
-import { getRouteList } from './http';
+import { getRouteList, fetchZoneList } from './http';
import PointRoute from "./PointRoute";
import shelf from '/map/shelf.svg';
@@ -880,6 +880,75 @@
// zone operator -------------------------------
let zoneDrawingCleanup = null;
+const ZONE_COLOR = 0x3498db;
+
+const addZoneLabel = (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',
+ });
+ label.anchor.set(0.5);
+ label.position.set(centerX, centerY);
+ label.rotation = rotationParseNum(MAP_DEFAULT_ROTATION);
+ label.scale.set(MAP_MIRROR ? -1 : 1, 1);
+ draft.addChild(label);
+};
+
+export const loadZones = (curArea) => {
+ if (!mapContainer) return;
+ clearZones();
+ fetchZoneList(curArea).then((zones) => {
+ zones.forEach((zone) => {
+ const { name, color, id } = zone || {};
+ const start = zone?.start || (zone?.startX != null ? { x: zone.startX, y: zone.startY } : null);
+ const end = zone?.end || (zone?.endX != null ? { x: zone.endX, y: zone.endY } : null);
+ if (!start || !end || !name) {
+ return;
+ }
+ const g = createZoneGraphic({ name, start, end, color, id });
+ if (g) {
+ mapContainer.addChild(g);
+ }
+ });
+ });
+};
+
+export const clearZones = () => {
+ if (!mapContainer) return;
+ for (let i = mapContainer.children.length - 1; i >= 0; i--) {
+ const child = mapContainer.children[i];
+ if (child?.data?.type === DEVICE_TYPE.ZONE) {
+ mapContainer.removeChild(child);
+ child.destroy({ children: true, texture: false, baseTexture: false });
+ }
+ }
+};
+
+const createZoneGraphic = ({ name, start, end, color, id }) => {
+ if (!mapContainer) return null;
+ const from = start || { x: 0, y: 0 };
+ const to = end || { x: 0, y: 0 };
+ const zoneColor = color || ZONE_COLOR;
+
+ const draft = new PIXI.Graphics();
+ draft.name = id ? `zone_${id}` : 'zone_' + generateID();
+ draft.zIndex = DEVICE_Z_INDEX.ZONE;
+ draft.lineStyle(4 / Math.abs(mapContainer.scale.x || 1), zoneColor, 0.8);
+ draft.beginFill(zoneColor, 0.18);
+ draft.drawRect(
+ Math.min(from.x, to.x),
+ Math.min(from.y, to.y),
+ Math.abs(from.x - to.x),
+ Math.abs(from.y - to.y),
+ );
+ draft.endFill();
+ addZoneLabel(draft, name, from, to);
+ draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.ZONE, name, color: zoneColor, id };
+ return draft;
+};
export const startZoneDrawing = ({ promptText, onComplete, onFinish } = {}) => {
if (!mapContainer || !mapContainer.parent) {
@@ -897,7 +966,7 @@
let drawing = false;
let startPoint = null;
- const zoneColor = 0x3498db;
+ const zoneColor = ZONE_COLOR;
const originalCursor = stage.cursor;
stage.cursor = 'crosshair';
@@ -913,22 +982,6 @@
Math.abs(from.y - to.y),
);
draft.endFill();
- };
-
- const addZoneLabel = (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',
- // fontFamily: 'Microsoft YaHei',
- });
- label.anchor.set(0.5);
- label.position.set(centerX, centerY);
- label.rotation = rotationParseNum(MAP_DEFAULT_ROTATION);
- label.scale.set(MAP_MIRROR ? -1 : 1, 1)
- draft.addChild(label);
};
const cleanupListeners = () => {
@@ -976,11 +1029,17 @@
return;
}
- addZoneLabel(zoneName, startPoint, endPoint);
- draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.ZONE, name: zoneName };
+ addZoneLabel(draft, zoneName, startPoint, endPoint);
+ draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.ZONE, name: zoneName, color: zoneColor };
if (onComplete) {
- onComplete({ name: zoneName, start: startPoint, end: endPoint, graphics: draft });
+ onComplete({
+ name: zoneName,
+ start: startPoint,
+ end: endPoint,
+ color: zoneColor,
+ graphics: draft
+ });
}
};
@@ -988,4 +1047,4 @@
stage.on('pointermove', handleMove);
stage.on('pointerup', handleUp);
return true;
-};
\ No newline at end of file
+};
--
Gitblit v1.9.1