From 769669bf42ece51876ed7ec3433cb52c5e2a2509 Mon Sep 17 00:00:00 2001
From: vincentlu <t1341870251@gmail.com>
Date: 星期二, 09 十二月 2025 15:48:54 +0800
Subject: [PATCH] #
---
zy-acs-flow/src/map/tool.js | 32 ++++++++++++++++++++------------
zy-acs-flow/src/map/MapPage.jsx | 12 ++++++++++--
2 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/zy-acs-flow/src/map/MapPage.jsx b/zy-acs-flow/src/map/MapPage.jsx
index 4684b02..5cc814a 100644
--- a/zy-acs-flow/src/map/MapPage.jsx
+++ b/zy-acs-flow/src/map/MapPage.jsx
@@ -49,6 +49,7 @@
const [deviceVisible, setDeviceVisible] = useState(false);
const [settingsVisible, setSettingsVisible] = useState(false);
const [batchSelectionVisible, setBatchSelectionVisible] = useState(false);
+ const [zoneDrawing, setZoneDrawing] = useState(false);
const [curSprite, setCurSprite] = useState(null);
const [batchSprites, setBatchSprites] = useState([]);
@@ -346,18 +347,25 @@
{mode === MAP_MODE.ZONING_MODE && (
<>
<Button
- variant="contained"
+ variant={zoneDrawing ? "outlined" : "contained"}
color="primary"
sx={{ mr: 2 }}
+ disabled={zoneDrawing}
onClick={() => {
- Tool.startZoneDrawing({
+ const started = Tool.startZoneDrawing({
promptText: translate('page.map.prompt.zoneName'),
onComplete: ({ name }) => {
if (name) {
notify.success(translate('page.map.msg.zoneCreated', { name }));
}
+ },
+ onFinish: () => {
+ setZoneDrawing(false);
}
});
+ if (started) {
+ setZoneDrawing(true);
+ }
}}
>
{translate('page.map.action.addZone')}
diff --git a/zy-acs-flow/src/map/tool.js b/zy-acs-flow/src/map/tool.js
index 34262de..5b1b8a0 100644
--- a/zy-acs-flow/src/map/tool.js
+++ b/zy-acs-flow/src/map/tool.js
@@ -881,27 +881,29 @@
let zoneDrawingCleanup = null;
-export const startZoneDrawing = ({ promptText, onComplete } = {}) => {
+export const startZoneDrawing = ({ promptText, onComplete, onFinish } = {}) => {
if (!mapContainer || !mapContainer.parent) {
- return;
+ return false;
}
- mapContainer?.parent?.off('mousedown');
-
if (zoneDrawingCleanup) {
zoneDrawingCleanup();
}
const stage = mapContainer.parent;
+ stage.off('mousedown');
const draft = new PIXI.Graphics();
draft.name = 'zone_' + generateID();
draft.zIndex = DEVICE_Z_INDEX.ZONE;
let drawing = false;
let startPoint = null;
+ const zoneColor = 0x3498db;
+ const originalCursor = stage.cursor;
+ stage.cursor = 'crosshair';
const drawRect = (from, to) => {
draft.clear();
- const strokeColor = themeMode === 'dark' ? 0x74b9ff : 0x2ecc71;
+ const strokeColor = zoneColor;
draft.lineStyle(4 / Math.abs(mapContainer.scale.x || 1), strokeColor, 0.8);
draft.beginFill(strokeColor, 0.18);
draft.drawRect(
@@ -913,16 +915,17 @@
draft.endFill();
};
- const addZoneLabel = (text) => {
- const bounds = draft.getBounds();
+ 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' : '#2d3436',
- fontSize: 48 / Math.abs(mapContainer.scale.x || 1),
+ fill: themeMode === 'dark' ? '#f1f2f6' : '#535353ff',
+ fontSize: 20 / Math.abs(mapContainer.scale.x || 1),
fontWeight: 'bold',
- fontFamily: 'Microsoft YaHei',
+ // fontFamily: 'Microsoft YaHei',
});
label.anchor.set(0.5);
- label.position.set(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
+ label.position.set(centerX, centerY);
draft.addChild(label);
};
@@ -931,6 +934,10 @@
stage.off('pointerup', handleUp);
stage.off('pointerdown', handleDown);
zoneDrawingCleanup = null;
+ stage.cursor = originalCursor;
+ if (onFinish) {
+ onFinish();
+ }
};
zoneDrawingCleanup = cleanupListeners;
@@ -967,7 +974,7 @@
return;
}
- addZoneLabel(zoneName);
+ addZoneLabel(zoneName, startPoint, endPoint);
draft.data = { ...(draft.data || {}), type: DEVICE_TYPE.ZONE, name: zoneName };
if (onComplete) {
@@ -978,4 +985,5 @@
stage.on('pointerdown', handleDown);
stage.on('pointermove', handleMove);
stage.on('pointerup', handleUp);
+ return true;
};
\ No newline at end of file
--
Gitblit v1.9.1