优化
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, { useState, useRef, useEffect, useCallback, useMemo } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { LabelTemplate, TemplateElement } from '../types';
|
||||
import { mmToPx, MM_TO_PX, shouldRenderElement } from '../utils';
|
||||
import { mmToPx, MM_TO_PX, shouldRenderElement, centerElementOnLabel } from '../utils';
|
||||
import type { ElementClipboardActions } from '../hooks/useElementClipboard';
|
||||
import {
|
||||
createDefaultTableElement,
|
||||
@@ -327,8 +327,7 @@ export const LabelDesigner: React.FC<LabelDesignerProps> = ({
|
||||
id,
|
||||
type: 'image',
|
||||
name: `图片 ${n}`,
|
||||
x: 5,
|
||||
y: 5,
|
||||
...centerElementOnLabel(template.width, template.height, 30, 30),
|
||||
width: 30,
|
||||
height: 30,
|
||||
content: src,
|
||||
@@ -421,6 +420,14 @@ export const LabelDesigner: React.FC<LabelDesignerProps> = ({
|
||||
};
|
||||
}
|
||||
|
||||
const centered = centerElementOnLabel(
|
||||
template.width,
|
||||
template.height,
|
||||
newElement.width,
|
||||
newElement.height
|
||||
);
|
||||
newElement = { ...newElement, ...centered };
|
||||
|
||||
onChange({
|
||||
...template,
|
||||
elements: [...template.elements, newElement],
|
||||
|
||||
Reference in New Issue
Block a user