#
vincentlu
2025-12-09 769669bf42ece51876ed7ec3433cb52c5e2a2509
#
2个文件已修改
44 ■■■■■ 已修改文件
zy-acs-flow/src/map/MapPage.jsx 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-acs-flow/src/map/tool.js 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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')}
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;
};