You've already forked Nano-Banana-AI-Image-Editor
新增 结果预览组件添加对鼠标滚轮缩放的支持;
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useRef, useEffect, useState } from 'react';
|
import React, { useRef, useEffect, useState, useCallback } from 'react';
|
||||||
import { Stage, Layer, Image as KonvaImage, Line } from 'react-konva';
|
import { Stage, Layer, Image as KonvaImage, Line } from 'react-konva';
|
||||||
import { useAppStore } from '../store/useAppStore';
|
import { useAppStore } from '../store/useAppStore';
|
||||||
import { Button } from './ui/Button';
|
import { Button } from './ui/Button';
|
||||||
@@ -29,6 +29,11 @@ export const ImageCanvas: React.FC = () => {
|
|||||||
const [isDrawing, setIsDrawing] = useState(false);
|
const [isDrawing, setIsDrawing] = useState(false);
|
||||||
const [currentStroke, setCurrentStroke] = useState<number[]>([]);
|
const [currentStroke, setCurrentStroke] = useState<number[]>([]);
|
||||||
|
|
||||||
|
const handleZoom = useCallback((delta: number) => {
|
||||||
|
const newZoom = Math.max(0.1, Math.min(3, canvasZoom + delta));
|
||||||
|
setCanvasZoom(newZoom);
|
||||||
|
}, [canvasZoom, setCanvasZoom]);
|
||||||
|
|
||||||
// 加载图像并在 canvasImage 变化时自动适应
|
// 加载图像并在 canvasImage 变化时自动适应
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (canvasImage) {
|
if (canvasImage) {
|
||||||
@@ -77,6 +82,21 @@ export const ImageCanvas: React.FC = () => {
|
|||||||
return () => window.removeEventListener('resize', updateSize);
|
return () => window.removeEventListener('resize', updateSize);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// 处理鼠标滚轮缩放
|
||||||
|
useEffect(() => {
|
||||||
|
const container = document.getElementById('canvas-container');
|
||||||
|
if (!container) return;
|
||||||
|
|
||||||
|
const handleWheel = (e: WheelEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const delta = e.deltaY > 0 ? -0.1 : 0.1;
|
||||||
|
handleZoom(delta);
|
||||||
|
};
|
||||||
|
|
||||||
|
container.addEventListener('wheel', handleWheel, { passive: false });
|
||||||
|
return () => container.removeEventListener('wheel', handleWheel);
|
||||||
|
}, [canvasZoom]);
|
||||||
|
|
||||||
const handleMouseDown = (e: any) => {
|
const handleMouseDown = (e: any) => {
|
||||||
if (selectedTool !== 'mask' || !image) return;
|
if (selectedTool !== 'mask' || !image) return;
|
||||||
|
|
||||||
@@ -140,11 +160,6 @@ export const ImageCanvas: React.FC = () => {
|
|||||||
setCurrentStroke([]);
|
setCurrentStroke([]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleZoom = (delta: number) => {
|
|
||||||
const newZoom = Math.max(0.1, Math.min(3, canvasZoom + delta));
|
|
||||||
setCanvasZoom(newZoom);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleReset = () => {
|
const handleReset = () => {
|
||||||
if (image) {
|
if (image) {
|
||||||
const isMobile = window.innerWidth < 768;
|
const isMobile = window.innerWidth < 768;
|
||||||
|
|||||||
Reference in New Issue
Block a user