chore: improve image edit
This commit is contained in:
@@ -2,7 +2,7 @@ import { createFromIconfontCN } from '@ant-design/icons';
|
|||||||
// import './iconfont/iconfont.js';
|
// import './iconfont/iconfont.js';
|
||||||
|
|
||||||
const IconFont = createFromIconfontCN({
|
const IconFont = createFromIconfontCN({
|
||||||
scriptUrl: '//at.alicdn.com/t/c/font_4613488_djdkmiu9k3b.js'
|
scriptUrl: '//at.alicdn.com/t/c/font_4613488_pr3u3llgke.js'
|
||||||
});
|
});
|
||||||
|
|
||||||
export default IconFont;
|
export default IconFont;
|
||||||
|
|||||||
@@ -20,4 +20,16 @@
|
|||||||
.overlay-canvas:hover {
|
.overlay-canvas:hover {
|
||||||
cursor: 'none !important';
|
cursor: 'none !important';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.upload-mask {
|
||||||
|
&:hover {
|
||||||
|
.close-btn {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-btn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
|
ClearOutlined,
|
||||||
|
CloseOutlined,
|
||||||
DownloadOutlined,
|
DownloadOutlined,
|
||||||
ExpandOutlined,
|
ExpandOutlined,
|
||||||
FormatPainterOutlined,
|
FormatPainterOutlined,
|
||||||
SyncOutlined,
|
|
||||||
UndoOutlined
|
UndoOutlined
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
@@ -20,6 +21,8 @@ type CanvasImageEditorProps = {
|
|||||||
imageSrc: string;
|
imageSrc: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
imguid: string | number;
|
imguid: string | number;
|
||||||
|
maskUpload?: any[];
|
||||||
|
clearUploadMask?: () => void;
|
||||||
onSave: (imageData: { mask: string | null; img: string }) => void;
|
onSave: (imageData: { mask: string | null; img: string }) => void;
|
||||||
onScaleImageSize?: (data: { width: number; height: number }) => void;
|
onScaleImageSize?: (data: { width: number; height: number }) => void;
|
||||||
uploadButton: React.ReactNode;
|
uploadButton: React.ReactNode;
|
||||||
@@ -37,10 +40,12 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
imageSrc,
|
imageSrc,
|
||||||
disabled,
|
disabled,
|
||||||
imageStatus,
|
imageStatus,
|
||||||
|
clearUploadMask,
|
||||||
onSave,
|
onSave,
|
||||||
onScaleImageSize,
|
onScaleImageSize,
|
||||||
imguid,
|
imguid,
|
||||||
uploadButton
|
uploadButton,
|
||||||
|
maskUpload
|
||||||
}) => {
|
}) => {
|
||||||
const MIN_SCALE = 0.5;
|
const MIN_SCALE = 0.5;
|
||||||
const MAX_SCALE = 8;
|
const MAX_SCALE = 8;
|
||||||
@@ -52,20 +57,18 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
const [lineWidth, setLineWidth] = useState<number>(60);
|
const [lineWidth, setLineWidth] = useState<number>(60);
|
||||||
const isDrawing = useRef<boolean>(false);
|
const isDrawing = useRef<boolean>(false);
|
||||||
const currentStroke = useRef<Point[]>([]);
|
const currentStroke = useRef<Point[]>([]);
|
||||||
const resizeObserver = useRef<ResizeObserver | null>(null);
|
|
||||||
const strokesRef = useRef<Stroke[]>([]);
|
const strokesRef = useRef<Stroke[]>([]);
|
||||||
const offscreenCanvasRef = useRef<HTMLCanvasElement | null>(null);
|
const offscreenCanvasRef = useRef<HTMLCanvasElement | null>(null);
|
||||||
const autoScale = useRef<number>(1);
|
const autoScale = useRef<number>(1);
|
||||||
const baseScale = useRef<number>(1);
|
const baseScale = useRef<number>(1);
|
||||||
const cursorRef = useRef<HTMLDivElement>(null);
|
const cursorRef = useRef<HTMLDivElement>(null);
|
||||||
const [imgLoaded, setImgLoaded] = useState(false);
|
|
||||||
const translatePos = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
|
const translatePos = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
|
||||||
const contentPos = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
|
const contentPos = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
|
||||||
const animationFrameIdRef = useRef<number | null>(null);
|
|
||||||
const strokeCache = useRef<any>({});
|
const strokeCache = useRef<any>({});
|
||||||
const preImguid = useRef<string | number>('');
|
const preImguid = useRef<string | number>('');
|
||||||
const [activeScale, setActiveScale] = useState<number>(1);
|
const [activeScale, setActiveScale] = useState<number>(1);
|
||||||
const negativeMaskRef = useRef<boolean>(false);
|
const negativeMaskRef = useRef<boolean>(false);
|
||||||
|
const mouseDownState = useRef<boolean>(false);
|
||||||
|
|
||||||
const getTransformedPoint = useCallback(
|
const getTransformedPoint = useCallback(
|
||||||
(offsetX: number, offsetY: number) => {
|
(offsetX: number, offsetY: number) => {
|
||||||
@@ -110,10 +113,14 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleMouseEnter = (e: React.MouseEvent<HTMLCanvasElement>) => {
|
const handleMouseEnter = (e: React.MouseEvent<HTMLCanvasElement>) => {
|
||||||
|
console.log('mouse enter:', mouseDownState.current);
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
overlayCanvasRef.current!.style.cursor = 'default';
|
overlayCanvasRef.current!.style.cursor = 'default';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// if (mouseDownState.current) {
|
||||||
|
// isDrawing.current = true;
|
||||||
|
// }
|
||||||
overlayCanvasRef.current!.style.cursor = 'none';
|
overlayCanvasRef.current!.style.cursor = 'none';
|
||||||
cursorRef.current!.style.display = 'block';
|
cursorRef.current!.style.display = 'block';
|
||||||
cursorRef.current!.style.top = `${e.clientY - (lineWidth / 2) * autoScale.current}px`;
|
cursorRef.current!.style.top = `${e.clientY - (lineWidth / 2) * autoScale.current}px`;
|
||||||
@@ -134,6 +141,7 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
if (disabled) {
|
if (disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
isDrawing.current = false;
|
||||||
overlayCanvasRef.current!.style.cursor = 'default';
|
overlayCanvasRef.current!.style.cursor = 'default';
|
||||||
cursorRef.current!.style.display = 'none';
|
cursorRef.current!.style.display = 'none';
|
||||||
};
|
};
|
||||||
@@ -335,12 +343,18 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
if (disabled) {
|
if (disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isDrawing.current) return;
|
console.log(
|
||||||
|
'Drawing:',
|
||||||
|
isDrawing.current,
|
||||||
|
currentStroke.current,
|
||||||
|
strokesRef.current
|
||||||
|
);
|
||||||
|
if (!isDrawing.current || !mouseDownState.current) return;
|
||||||
|
|
||||||
const { offsetX, offsetY } = e.nativeEvent;
|
const { offsetX, offsetY } = e.nativeEvent;
|
||||||
const currentX = offsetX;
|
const currentX = offsetX;
|
||||||
const currentY = offsetY;
|
const currentY = offsetY;
|
||||||
|
console.log('currentStroke:', currentStroke.current);
|
||||||
currentStroke.current.push({
|
currentStroke.current.push({
|
||||||
x: currentX,
|
x: currentX,
|
||||||
y: currentY,
|
y: currentY,
|
||||||
@@ -369,6 +383,7 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
if (disabled) {
|
if (disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isDrawing.current = true;
|
isDrawing.current = true;
|
||||||
|
|
||||||
currentStroke.current = [];
|
currentStroke.current = [];
|
||||||
@@ -393,7 +408,6 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const endDrawing = (e: React.MouseEvent<HTMLCanvasElement>) => {
|
const endDrawing = (e: React.MouseEvent<HTMLCanvasElement>) => {
|
||||||
console.log('End Drawing:', e);
|
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -401,6 +415,8 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('End Drawing:', e);
|
||||||
|
|
||||||
isDrawing.current = false;
|
isDrawing.current = false;
|
||||||
|
|
||||||
strokesRef.current.push(_.cloneDeep(currentStroke.current));
|
strokesRef.current.push(_.cloneDeep(currentStroke.current));
|
||||||
@@ -440,9 +456,9 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
|
|
||||||
const onReset = useCallback(() => {
|
const onReset = useCallback(() => {
|
||||||
clearOverlayCanvas();
|
clearOverlayCanvas();
|
||||||
console.log('Resetting strokes');
|
|
||||||
setStrokes([]);
|
setStrokes([]);
|
||||||
currentStroke.current = [];
|
currentStroke.current = [];
|
||||||
|
console.log('Resetting strokes', currentStroke.current);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const redrawStrokes = useCallback(
|
const redrawStrokes = useCallback(
|
||||||
@@ -599,13 +615,11 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setImgLoaded(false);
|
|
||||||
await drawImage();
|
await drawImage();
|
||||||
onScaleImageSize?.({
|
onScaleImageSize?.({
|
||||||
width: canvasRef.current!.width,
|
width: canvasRef.current!.width,
|
||||||
height: canvasRef.current!.height
|
height: canvasRef.current!.height
|
||||||
});
|
});
|
||||||
setImgLoaded(true);
|
|
||||||
|
|
||||||
if (strokeCache.current[imguid]) {
|
if (strokeCache.current[imguid]) {
|
||||||
strokeCache.current[preImguid.current] = strokesRef.current;
|
strokeCache.current[preImguid.current] = strokesRef.current;
|
||||||
@@ -616,12 +630,16 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
resetCanvas();
|
resetCanvas();
|
||||||
}
|
}
|
||||||
preImguid.current = imguid;
|
preImguid.current = imguid;
|
||||||
|
console.log(
|
||||||
if (strokesRef.current.length) {
|
'Image initialized:',
|
||||||
|
strokesRef.current.length,
|
||||||
|
imageStatus.isOriginal
|
||||||
|
);
|
||||||
|
if (strokesRef.current.length && imageStatus.isOriginal) {
|
||||||
redrawStrokes(strokesRef.current);
|
redrawStrokes(strokesRef.current);
|
||||||
|
saveImage();
|
||||||
}
|
}
|
||||||
updateCursorSize();
|
updateCursorSize();
|
||||||
saveImage();
|
|
||||||
}, [drawImage, onReset, redrawStrokes, imguid]);
|
}, [drawImage, onReset, redrawStrokes, imguid]);
|
||||||
|
|
||||||
const updateZoom = (scaleChange: number, mouseX: number, mouseY: number) => {
|
const updateZoom = (scaleChange: number, mouseX: number, mouseY: number) => {
|
||||||
@@ -707,12 +725,24 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleMouseDown = (e: MouseEvent) => {
|
||||||
|
mouseDownState.current = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseUp = (e: MouseEvent) => {
|
||||||
|
mouseDownState.current = false;
|
||||||
|
};
|
||||||
|
|
||||||
window.addEventListener('keydown', handleUndoShortcut);
|
window.addEventListener('keydown', handleUndoShortcut);
|
||||||
|
// mouse down
|
||||||
|
window.addEventListener('mousedown', handleMouseDown);
|
||||||
|
|
||||||
|
// mouse up
|
||||||
|
window.addEventListener('mouseup', handleMouseUp);
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('keydown', handleUndoShortcut);
|
window.removeEventListener('keydown', handleUndoShortcut);
|
||||||
if (animationFrameIdRef.current !== null) {
|
window.removeEventListener('mousedown', handleMouseDown);
|
||||||
cancelAnimationFrame(animationFrameIdRef.current);
|
window.removeEventListener('mouseup', handleMouseUp);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -769,17 +799,17 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
<UndoOutlined className="font-size-14" />
|
<UndoOutlined className="font-size-14" />
|
||||||
</Button>
|
</Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{uploadButton}
|
<Tooltip title={intl.formatMessage({ id: 'common.button.clear' })}>
|
||||||
<Tooltip title={intl.formatMessage({ id: 'common.button.reset' })}>
|
|
||||||
<Button
|
<Button
|
||||||
onClick={onReset}
|
onClick={onReset}
|
||||||
size="middle"
|
size="middle"
|
||||||
type="text"
|
type="text"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
<SyncOutlined className="font-size-14" />
|
<ClearOutlined className="font-size-14" />
|
||||||
</Button>
|
</Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
{uploadButton}
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={intl.formatMessage({ id: 'playground.image.fitview' })}
|
title={intl.formatMessage({ id: 'playground.image.fitview' })}
|
||||||
>
|
>
|
||||||
@@ -794,22 +824,50 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
<div className="tools">
|
<div className="tools">
|
||||||
<Checkbox
|
{maskUpload?.length ? (
|
||||||
onChange={handleOnChangeMask}
|
<span className="flex-center upload-mask">
|
||||||
className="flex-center"
|
<span className="font-size-12">
|
||||||
value={negativeMaskRef.current}
|
{intl.formatMessage({ id: 'playground.image.mask.uploaded' })}
|
||||||
>
|
...
|
||||||
<span className="font-size-12">
|
</span>
|
||||||
{intl.formatMessage({ id: 'playground.image.negativeMask' })}
|
<Button
|
||||||
|
onClick={clearUploadMask}
|
||||||
|
size="small"
|
||||||
|
type="text"
|
||||||
|
icon={<CloseOutlined className="close-btn"></CloseOutlined>}
|
||||||
|
></Button>
|
||||||
</span>
|
</span>
|
||||||
</Checkbox>
|
) : (
|
||||||
<Tooltip
|
<>
|
||||||
title={intl.formatMessage({ id: 'playground.image.saveMask' })}
|
{imageStatus.isOriginal && (
|
||||||
>
|
<>
|
||||||
<Button onClick={downloadMask} size="middle" type="text">
|
<Checkbox
|
||||||
<IconFont className="font-size-14" type="icon-save2"></IconFont>
|
onChange={handleOnChangeMask}
|
||||||
</Button>
|
className="flex-center"
|
||||||
</Tooltip>
|
value={negativeMaskRef.current}
|
||||||
|
>
|
||||||
|
<span className="font-size-12">
|
||||||
|
{intl.formatMessage({
|
||||||
|
id: 'playground.image.negativeMask'
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
</Checkbox>
|
||||||
|
<Tooltip
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'playground.image.saveMask'
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Button onClick={downloadMask} size="middle" type="text">
|
||||||
|
<IconFont
|
||||||
|
className="font-size-14"
|
||||||
|
type="icon-save2"
|
||||||
|
></IconFont>
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={intl.formatMessage({ id: 'playground.image.download' })}
|
title={intl.formatMessage({ id: 'playground.image.download' })}
|
||||||
>
|
>
|
||||||
@@ -834,8 +892,14 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
ref={overlayCanvasRef}
|
ref={overlayCanvasRef}
|
||||||
className="overlay-canvas"
|
className="overlay-canvas"
|
||||||
style={{ position: 'absolute', zIndex: 10, cursor: 'none' }}
|
style={{ position: 'absolute', zIndex: 10, cursor: 'none' }}
|
||||||
onMouseDown={startDrawing}
|
onMouseDown={(event) => {
|
||||||
onMouseUp={endDrawing}
|
mouseDownState.current = true;
|
||||||
|
startDrawing(event);
|
||||||
|
}}
|
||||||
|
onMouseUp={(event) => {
|
||||||
|
mouseDownState.current = false;
|
||||||
|
endDrawing(event);
|
||||||
|
}}
|
||||||
onMouseEnter={handleMouseEnter}
|
onMouseEnter={handleMouseEnter}
|
||||||
onWheel={handleOnWheel}
|
onWheel={handleOnWheel}
|
||||||
onMouseMove={(e) => {
|
onMouseMove={(e) => {
|
||||||
@@ -843,8 +907,8 @@ const CanvasImageEditor: React.FC<CanvasImageEditorProps> = ({
|
|||||||
draw(e);
|
draw(e);
|
||||||
}}
|
}}
|
||||||
onMouseLeave={(e) => {
|
onMouseLeave={(e) => {
|
||||||
handleMouseLeave();
|
|
||||||
endDrawing(e);
|
endDrawing(e);
|
||||||
|
handleMouseLeave();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const LogsViewer: React.FC<LogsViewerProps> = forwardRef((props, ref) => {
|
|||||||
const chunkRequedtRef = useRef<any>(null);
|
const chunkRequedtRef = useRef<any>(null);
|
||||||
const [logs, setLogs] = useState<any[]>([]);
|
const [logs, setLogs] = useState<any[]>([]);
|
||||||
const logParseWorker = useRef<any>(null);
|
const logParseWorker = useRef<any>(null);
|
||||||
const tail = useRef<any>(pageSize - 1);
|
const tail = useRef<any>(defaultTail);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [isAtTop, setIsAtTop] = useState(false);
|
const [isAtTop, setIsAtTop] = useState(false);
|
||||||
const [scrollPos, setScrollPos] = useState<any[]>([]);
|
const [scrollPos, setScrollPos] = useState<any[]>([]);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export default function useBodyScroll() {
|
|||||||
y: 'scroll'
|
y: 'scroll'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 500);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ interface RequestConfig {
|
|||||||
handler: (data: any) => any;
|
handler: (data: any) => any;
|
||||||
beforeReconnect?: () => void;
|
beforeReconnect?: () => void;
|
||||||
params?: object;
|
params?: object;
|
||||||
byLine?: boolean;
|
|
||||||
watch?: boolean;
|
watch?: boolean;
|
||||||
contentType?: 'json' | 'text';
|
contentType?: 'json' | 'text';
|
||||||
}
|
}
|
||||||
@@ -16,8 +15,6 @@ const useSetChunkFetch = () => {
|
|||||||
const axiosToken = useRef<any>(null);
|
const axiosToken = useRef<any>(null);
|
||||||
const requestConfig = useRef<any>({});
|
const requestConfig = useRef<any>({});
|
||||||
const chunkDataRef = useRef<any>([]);
|
const chunkDataRef = useRef<any>([]);
|
||||||
const bufferCacheRef = useRef<any>('');
|
|
||||||
|
|
||||||
const readTextEventStreamData = async (
|
const readTextEventStreamData = async (
|
||||||
reader: ReadableStreamDefaultReader<Uint8Array>,
|
reader: ReadableStreamDefaultReader<Uint8Array>,
|
||||||
decoder: TextDecoder,
|
decoder: TextDecoder,
|
||||||
@@ -74,7 +71,6 @@ const useSetChunkFetch = () => {
|
|||||||
url,
|
url,
|
||||||
handler,
|
handler,
|
||||||
watch,
|
watch,
|
||||||
byLine = false,
|
|
||||||
params = {}
|
params = {}
|
||||||
}: RequestConfig) => {
|
}: RequestConfig) => {
|
||||||
axiosToken.current?.abort?.();
|
axiosToken.current?.abort?.();
|
||||||
|
|||||||
@@ -139,5 +139,7 @@ export default {
|
|||||||
'playground.image.generate': 'Generate',
|
'playground.image.generate': 'Generate',
|
||||||
'playground.image.edit': 'Edit',
|
'playground.image.edit': 'Edit',
|
||||||
'playground.image.fitview': 'Fit View',
|
'playground.image.fitview': 'Fit View',
|
||||||
'playground.chat.aithought': 'CoT'
|
'playground.chat.aithought': 'CoT',
|
||||||
|
'playground.image.mask.uploaded': 'Mask Uploaded',
|
||||||
|
'playground.image.mask.upload': 'Upload Mask'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -134,5 +134,7 @@ export default {
|
|||||||
'playground.image.generate': '生成图片',
|
'playground.image.generate': '生成图片',
|
||||||
'playground.image.edit': '编辑图片',
|
'playground.image.edit': '编辑图片',
|
||||||
'playground.image.fitview': '适应视图',
|
'playground.image.fitview': '适应视图',
|
||||||
'playground.chat.aithought': '思考过程'
|
'playground.chat.aithought': '思考过程',
|
||||||
|
'playground.image.mask.uploaded': '遮罩已上传',
|
||||||
|
'playground.image.mask.upload': '上传遮罩'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -479,7 +479,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
modelId: row.model_id,
|
modelId: row.model_id,
|
||||||
tail: InstanceRealtimeLogStatus.includes(row.state)
|
tail: InstanceRealtimeLogStatus.includes(row.state)
|
||||||
? undefined
|
? undefined
|
||||||
: PageSize
|
: PageSize - 1
|
||||||
});
|
});
|
||||||
setOpenLogModal(true);
|
setOpenLogModal(true);
|
||||||
onViewLogs();
|
onViewLogs();
|
||||||
@@ -840,21 +840,6 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
{intl?.formatMessage?.({ id: 'models.button.deploy' })}
|
{intl?.formatMessage?.({ id: 'models.button.deploy' })}
|
||||||
</Button>
|
</Button>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
<Access accessible={access.canDelete}>
|
|
||||||
<Button
|
|
||||||
icon={<DeleteOutlined />}
|
|
||||||
danger
|
|
||||||
onClick={handleDeleteBatch}
|
|
||||||
disabled={!rowSelection.selectedRowKeys.length}
|
|
||||||
>
|
|
||||||
<span>
|
|
||||||
{intl?.formatMessage?.({ id: 'common.button.delete' })}
|
|
||||||
{rowSelection.selectedRowKeys.length > 0 && (
|
|
||||||
<span>({rowSelection.selectedRowKeys?.length})</span>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
</Button>
|
|
||||||
</Access>
|
|
||||||
<Button
|
<Button
|
||||||
icon={<IconFont type="icon-outline-play"></IconFont>}
|
icon={<IconFont type="icon-outline-play"></IconFont>}
|
||||||
onClick={handleStartBatch}
|
onClick={handleStartBatch}
|
||||||
@@ -879,6 +864,21 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</Button>
|
</Button>
|
||||||
|
<Access accessible={access.canDelete}>
|
||||||
|
<Button
|
||||||
|
icon={<DeleteOutlined />}
|
||||||
|
danger
|
||||||
|
onClick={handleDeleteBatch}
|
||||||
|
disabled={!rowSelection.selectedRowKeys.length}
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
{intl?.formatMessage?.({ id: 'common.button.delete' })}
|
||||||
|
{rowSelection.selectedRowKeys.length > 0 && (
|
||||||
|
<span>({rowSelection.selectedRowKeys?.length})</span>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</Button>
|
||||||
|
</Access>
|
||||||
</Space>
|
</Space>
|
||||||
}
|
}
|
||||||
></PageTools>
|
></PageTools>
|
||||||
|
|||||||
@@ -198,7 +198,8 @@ export const InstanceStatusMap = {
|
|||||||
|
|
||||||
export const InstanceRealtimeLogStatus = [
|
export const InstanceRealtimeLogStatus = [
|
||||||
InstanceStatusMap.Downloading,
|
InstanceStatusMap.Downloading,
|
||||||
InstanceStatusMap.Initializing
|
InstanceStatusMap.Initializing,
|
||||||
|
InstanceStatusMap.Starting
|
||||||
];
|
];
|
||||||
|
|
||||||
export const InstanceStatusMapValue = {
|
export const InstanceStatusMapValue = {
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
const [image, setImage] = useState<string>('');
|
const [image, setImage] = useState<string>('');
|
||||||
const [mask, setMask] = useState<string | null>(null);
|
const [mask, setMask] = useState<string | null>(null);
|
||||||
const [uploadList, setUploadList] = useState<any[]>([]);
|
const [uploadList, setUploadList] = useState<any[]>([]);
|
||||||
|
const [maskUpload, setMaskUpload] = useState<any[]>([]);
|
||||||
const [modelMeta, setModelMeta] = useState<any>({});
|
const [modelMeta, setModelMeta] = useState<any>({});
|
||||||
const [imageStatus, setImageStatus] = useState<{
|
const [imageStatus, setImageStatus] = useState<{
|
||||||
isOriginal: boolean;
|
isOriginal: boolean;
|
||||||
@@ -299,15 +300,14 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
setMessageId();
|
setMessageId();
|
||||||
setTokenResult(null);
|
setTokenResult(null);
|
||||||
setCurrentPrompt(current?.content || '');
|
setCurrentPrompt(current?.content || '');
|
||||||
setUploadList((pre) => {
|
// setUploadList((pre) => {
|
||||||
return pre.map((item) => {
|
// return pre.map((item) => {
|
||||||
return {
|
// return {
|
||||||
...item,
|
// ...item,
|
||||||
uid: activeImgUid,
|
// uid: activeImgUid
|
||||||
dataUrl: image
|
// };
|
||||||
};
|
// });
|
||||||
});
|
// });
|
||||||
});
|
|
||||||
setRouteCache(routeCachekey['/playground/text-to-image'], true);
|
setRouteCache(routeCachekey['/playground/text-to-image'], true);
|
||||||
|
|
||||||
const imgSize = _.split(finalParameters.size, 'x').map((item: string) =>
|
const imgSize = _.split(finalParameters.size, 'x').map((item: string) =>
|
||||||
@@ -659,11 +659,12 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
const handleUpdateImageList = useCallback((base64List: any) => {
|
const handleUpdateImageList = useCallback((base64List: any) => {
|
||||||
const currentImg = _.get(base64List, '[0]', {});
|
const currentImg = _.get(base64List, '[0]', {});
|
||||||
const img = _.get(currentImg, 'dataUrl', '');
|
const img = _.get(currentImg, 'dataUrl', '');
|
||||||
|
handleOnScaleImageSize(currentImg);
|
||||||
setUploadList(base64List);
|
setUploadList(base64List);
|
||||||
setImage(img);
|
setImage(img);
|
||||||
setActiveImgUid(_.get(base64List, '[0].uid', ''));
|
setActiveImgUid(_.get(base64List, '[0].uid', ''));
|
||||||
setImageStatus({
|
setImageStatus({
|
||||||
isOriginal: false,
|
isOriginal: true,
|
||||||
isResetNeeded: true,
|
isResetNeeded: true,
|
||||||
width: _.get(currentImg, 'width', 512),
|
width: _.get(currentImg, 'width', 512),
|
||||||
height: _.get(currentImg, 'height', 512)
|
height: _.get(currentImg, 'height', 512)
|
||||||
@@ -671,6 +672,17 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
setImageList([]);
|
setImageList([]);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleUpdateMaskList = useCallback((base64List: any) => {
|
||||||
|
setMaskUpload(base64List);
|
||||||
|
const mask = _.get(base64List, '[0].dataUrl', '');
|
||||||
|
setMask(mask);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleClearUploadMask = useCallback(() => {
|
||||||
|
setMaskUpload([]);
|
||||||
|
setMask(null);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleOnSave = useCallback(
|
const handleOnSave = useCallback(
|
||||||
(data: { img: string; mask: string | null }) => {
|
(data: { img: string; mask: string | null }) => {
|
||||||
setImageStatus((pre) => {
|
setImageStatus((pre) => {
|
||||||
@@ -680,7 +692,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
setMask(data.mask || null);
|
setMask(data.mask || null);
|
||||||
setImage(data.img);
|
setImage(data.img || maskUpload[0]?.dataUrl || null);
|
||||||
},
|
},
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
@@ -692,17 +704,29 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
imguid={activeImgUid}
|
imguid={activeImgUid}
|
||||||
imageStatus={imageStatus}
|
imageStatus={imageStatus}
|
||||||
imageSrc={image}
|
imageSrc={image}
|
||||||
disabled={loading}
|
disabled={loading || !imageStatus.isOriginal}
|
||||||
onSave={handleOnSave}
|
onSave={handleOnSave}
|
||||||
|
clearUploadMask={handleClearUploadMask}
|
||||||
|
maskUpload={maskUpload}
|
||||||
uploadButton={
|
uploadButton={
|
||||||
<Tooltip title="Upload Image">
|
<>
|
||||||
<UploadImg
|
<UploadImg
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
handleUpdateImgList={handleUpdateImageList}
|
handleUpdateImgList={handleUpdateImageList}
|
||||||
size="middle"
|
size="middle"
|
||||||
accept="image/png"
|
accept="image/*"
|
||||||
></UploadImg>
|
></UploadImg>
|
||||||
</Tooltip>
|
<UploadImg
|
||||||
|
title={intl.formatMessage({
|
||||||
|
id: 'playground.image.mask.upload'
|
||||||
|
})}
|
||||||
|
icon={<IconFont type="icon-mosaic-2"></IconFont>}
|
||||||
|
disabled={loading}
|
||||||
|
handleUpdateImgList={handleUpdateMaskList}
|
||||||
|
size="middle"
|
||||||
|
accept="image/*"
|
||||||
|
></UploadImg>
|
||||||
|
</>
|
||||||
}
|
}
|
||||||
></CanvasImageEditor>
|
></CanvasImageEditor>
|
||||||
);
|
);
|
||||||
@@ -728,7 +752,14 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
</UploadImg>
|
</UploadImg>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}, [image, loading, imageStatus, handleOnSave, handleUpdateImageList]);
|
}, [
|
||||||
|
image,
|
||||||
|
loading,
|
||||||
|
maskUpload,
|
||||||
|
imageStatus,
|
||||||
|
handleOnSave,
|
||||||
|
handleUpdateImageList
|
||||||
|
]);
|
||||||
|
|
||||||
const handleOnImgClick = useCallback((item: any, isOrigin: boolean) => {
|
const handleOnImgClick = useCallback((item: any, isOrigin: boolean) => {
|
||||||
if (item.progress < 100) {
|
if (item.progress < 100) {
|
||||||
@@ -909,7 +940,11 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
overflow: 'hidden'
|
overflow: 'hidden'
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ flex: 1, overflow: 'auto' }} ref={paramsRef}>
|
<div
|
||||||
|
style={{ flex: 1, overflow: 'auto' }}
|
||||||
|
ref={paramsRef}
|
||||||
|
data-overlayscrollbars-initialize
|
||||||
|
>
|
||||||
<div className="box">
|
<div className="box">
|
||||||
<DynamicParams
|
<DynamicParams
|
||||||
ref={form}
|
ref={form}
|
||||||
@@ -961,7 +996,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
|
|||||||
placeholer={intl.formatMessage({
|
placeholer={intl.formatMessage({
|
||||||
id: 'playground.input.prompt.holder'
|
id: 'playground.input.prompt.holder'
|
||||||
})}
|
})}
|
||||||
actions={['clear']}
|
actions={[]}
|
||||||
title={
|
title={
|
||||||
<span className="font-600">
|
<span className="font-600">
|
||||||
{intl.formatMessage({ id: 'playground.image.prompt' })}
|
{intl.formatMessage({ id: 'playground.image.prompt' })}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ interface UploadImgProps {
|
|||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
accept?: string;
|
accept?: string;
|
||||||
|
icon?: React.ReactNode;
|
||||||
|
title?: React.ReactNode;
|
||||||
handleUpdateImgList: (
|
handleUpdateImgList: (
|
||||||
imgList: {
|
imgList: {
|
||||||
dataUrl: string;
|
dataUrl: string;
|
||||||
@@ -30,6 +32,8 @@ const UploadImg: React.FC<UploadImgProps> = ({
|
|||||||
drag = false,
|
drag = false,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
children,
|
children,
|
||||||
|
icon,
|
||||||
|
title,
|
||||||
accept = 'image/*',
|
accept = 'image/*',
|
||||||
size = 'small'
|
size = 'small'
|
||||||
}) => {
|
}) => {
|
||||||
@@ -135,13 +139,15 @@ const UploadImg: React.FC<UploadImgProps> = ({
|
|||||||
>
|
>
|
||||||
{children ?? (
|
{children ?? (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={intl.formatMessage({ id: 'playground.img.upload' })}
|
title={
|
||||||
|
title ?? intl.formatMessage({ id: 'playground.img.upload' })
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
size={size}
|
size={size}
|
||||||
type="text"
|
type="text"
|
||||||
icon={<PictureOutlined />}
|
icon={icon ?? <PictureOutlined />}
|
||||||
></Button>
|
></Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
@@ -158,13 +164,15 @@ const UploadImg: React.FC<UploadImgProps> = ({
|
|||||||
>
|
>
|
||||||
{children ?? (
|
{children ?? (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={intl.formatMessage({ id: 'playground.img.upload' })}
|
title={
|
||||||
|
title ?? intl.formatMessage({ id: 'playground.img.upload' })
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
size={size}
|
size={size}
|
||||||
type="text"
|
type="text"
|
||||||
icon={<PictureOutlined />}
|
icon={icon ?? <PictureOutlined />}
|
||||||
></Button>
|
></Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -166,3 +166,11 @@ export const extractErrorMessage = (result: any) => {
|
|||||||
''
|
''
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const scaleImageSize = (size: { width: number; height: number }) => {
|
||||||
|
const { width, height } = size;
|
||||||
|
const scale = 64;
|
||||||
|
const newWidth = Math.floor(width / scale) * scale;
|
||||||
|
const newHeight = Math.floor(height / scale) * scale;
|
||||||
|
return { width: newWidth, height: newHeight };
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user