This commit is contained in:
iqudoo
2026-06-14 10:25:15 +08:00
parent ccb5b119de
commit 846061ab48
6 changed files with 56 additions and 11 deletions

View File

@@ -229,6 +229,13 @@ export const LabelDesigner: React.FC<LabelDesignerProps> = ({
[template.variableDefaults]
);
const showReferencePreview = useMemo(
() =>
!!template.previewReferenceBackground &&
template.enablePreviewReferenceBackground !== false,
[template.previewReferenceBackground, template.enablePreviewReferenceBackground]
);
const localElementsRef = useRef<TemplateElement[] | null>(null);
/** 交互开始时的元素快照:拖动底图分层、缩放节流重绘 */
const [interactionSnapshot, setInteractionSnapshot] = useState<TemplateElement[] | null>(
@@ -1654,10 +1661,10 @@ export const LabelDesigner: React.FC<LabelDesignerProps> = ({
<div
ref={canvasRef}
className={`absolute inset-0 shadow-[0_2px_20px_rgba(0,0,0,0.5)] select-none overflow-hidden ${
template.previewReferenceBackground ? '' : 'bg-white'
showReferencePreview ? '' : 'bg-white'
}`}
>
{template.previewReferenceBackground && (
{showReferencePreview && (
<img
src={template.previewReferenceBackground}
alt=""
@@ -1681,7 +1688,7 @@ export const LabelDesigner: React.FC<LabelDesignerProps> = ({
rowData={null}
rowIndex={0}
showBorder={false}
transparentBackground={!!template.previewReferenceBackground}
transparentBackground={showReferencePreview}
variableDefaults={previewDefaults}
renderScale={canvasRenderScale}
/>

View File

@@ -858,7 +858,7 @@ export const PropSidebar: React.FC<PropSidebarProps> = ({
</h5>
<p className="text-[9px] text-[#777] leading-relaxed">
便
/
</p>
<label className="ps-btn text-[10px] cursor-pointer inline-flex">
<Upload className="w-3.5 h-3.5" />
@@ -879,6 +879,7 @@ export const PropSidebar: React.FC<PropSidebarProps> = ({
template.previewReferenceBackgroundOpacity ?? 100,
previewReferenceBackgroundFit:
template.previewReferenceBackgroundFit ?? 'cover',
enablePreviewReferenceBackground: true,
});
reader.readAsDataURL(file);
e.target.value = '';
@@ -930,6 +931,25 @@ export const PropSidebar: React.FC<PropSidebarProps> = ({
className="w-full accent-[#31a8ff]"
/>
</div>
<label className="flex items-start gap-2">
<input
type="checkbox"
checked={template.enablePreviewReferenceBackground !== false}
onChange={(e) =>
onChangeTemplate({
...template,
enablePreviewReferenceBackground: e.target.checked ? true : false,
})
}
className="ps-checkbox mt-0.5"
/>
<span className="text-xs text-[#ccc] leading-normal">
<span className="block text-[9px] text-[#777] mt-0.5">
</span>
</span>
</label>
<label className="flex items-start gap-2">
<input
type="checkbox"
@@ -957,6 +977,7 @@ export const PropSidebar: React.FC<PropSidebarProps> = ({
previewReferenceBackground: undefined,
previewReferenceBackgroundOpacity: undefined,
previewReferenceBackgroundFit: undefined,
enablePreviewReferenceBackground: undefined,
includeReferenceBackgroundInOutput: undefined,
})
}

View File

@@ -1,4 +1,5 @@
import React, { useEffect, useState } from 'react';
import { createPortal } from 'react-dom';
import { X } from 'lucide-react';
import { VisibilityRule } from '../types';
import { visibilityOperatorNeedsValue } from '../utils';
@@ -65,7 +66,7 @@ export const VisibilityRuleDialog: React.FC<VisibilityRuleDialogProps> = ({
return () => window.removeEventListener('keydown', onKeyDown);
}, [open, onClose]);
if (!open) return null;
if (!open || typeof document === 'undefined') return null;
const target = draft.target ?? 'variable';
const canConfirm = target === 'content' || draft.variable.trim().length > 0;
@@ -86,7 +87,7 @@ export const VisibilityRuleDialog: React.FC<VisibilityRuleDialogProps> = ({
onClose();
};
return (
return createPortal(
<div className="ps-modal-overlay" onClick={onClose} role="presentation">
<div
className="ps-modal"
@@ -131,6 +132,7 @@ export const VisibilityRuleDialog: React.FC<VisibilityRuleDialogProps> = ({
</div>
</form>
</div>
</div>
</div>,
document.body
);
};