This commit is contained in:
iqudoo
2026-06-14 18:02:18 +08:00
parent b4c2cf07d0
commit 8c9b53b1b6
7 changed files with 229 additions and 35 deletions

View File

@@ -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],