feat: 完善电商记录详情页,支持触摸手势交互、对话式需求面板与画布节点拖拽

本次修改全面打磨电商图片工作台的记录详情体验,主要包含以下变更:

一、记录详情对话面板(EcommercePage.tsx):
- 将记录详情中的"需求"区域重构为聊天对话式布局:
  · 历史需求消息:展示原始需求文本、参数元信息(平台/语种/比例/设置)、已上传素材缩略图
  · 新增跟进需求消息(is-followup):若当前素材与历史记录不同,自动展示新上传素材及当前参数配置
  · AI 回复消息保持原有状态展示
- 记录详情中素材上传数量上限从 7 张提升至 20 张(maxCloneProductImages)
- 上传按钮重构:移至素材列表左侧,显示当前数量/上限,满额时禁用并提示"已满"

二、触摸与手势交互:
- 新增 PreviewTouchGesture 完整手势系统:
  · 单指平移(pan):支持触摸拖拽预览画布
  · 双指缩放(pinch):以双指中心为锚点进行缩放,范围 0.25x-2x
  · 自动排除交互元素(按钮/输入框/链接等)避免冲突
  · 智能切换:单指/双指模式无缝切换
- 画布节点触摸拖拽(canvas node drag):
  · 支持触摸拖拽移动生成结果节点
  · 考虑当前缩放级别计算位移
  · 与预览画布手势互不干扰

三、记录详情页视觉升级(ecommerce-standalone.css):
- 整体背景采用径向渐变+线性渐变,营造专业 SaaS 质感
- 对话面板与历史面板统一采用毛玻璃卡片风格
- 聊天消息气泡:圆角 18px、柔和投影、用户消息左侧缩进 18px
- 历史面板宽度固定 292px
- CSS 自定义属性体系(record-detail-*)统一管理颜色和阴影
- 面板头部加高加粗标题,优化可读性

四、其他细节优化:
- 历史刷新按钮图标从文本符号改为 ReloadOutlined 组件
- 素材缩略图移除 hover 放大镜效果(.ecom-command-asset-zoom)
- 刷新按钮禁用样式完善

变更文件:
- src/features/ecommerce/EcommercePage.tsx (+246/-11)
- src/styles/ecommerce-standalone.css (+1369)
This commit is contained in:
2026-06-15 16:20:55 +08:00
parent 5b316a2399
commit e3b48e2614
2 changed files with 1604 additions and 11 deletions
+235 -11
View File
@@ -314,6 +314,21 @@ interface CanvasNode {
y: number; y: number;
} }
interface PreviewTouchPoint {
id: number;
x: number;
y: number;
}
interface PreviewTouchGesture {
mode: "none" | "pan" | "pinch";
points: PreviewTouchPoint[];
startOffset: { x: number; y: number };
startZoom: number;
startDistance: number;
startCenter: { x: number; y: number };
}
interface CloneSavedSetting { interface CloneSavedSetting {
id: string; id: string;
name: string; name: string;
@@ -1007,7 +1022,7 @@ const defaultCloneSetCounts: Record<CloneSetCountKey, number> = {
}; };
const minCloneSetTotal = 1; const minCloneSetTotal = 1;
const maxCloneSetTotal = 16; const maxCloneSetTotal = 16;
const maxCloneProductImages = 7; const maxCloneProductImages = 20;
const maxCloneReferenceImages = 20; const maxCloneReferenceImages = 20;
const cloneVideoDurationMin = 5; const cloneVideoDurationMin = 5;
const cloneVideoDurationMax = 45; const cloneVideoDurationMax = 45;
@@ -1494,6 +1509,14 @@ function ProductClonePage(_props: ProductClonePageProps = {}) {
offsetX: 0, offsetX: 0,
offsetY: 0, offsetY: 0,
}); });
const previewTouchGestureRef = useRef<PreviewTouchGesture>({
mode: "none",
points: [],
startOffset: { x: 0, y: 0 },
startZoom: 1,
startDistance: 0,
startCenter: { x: 0, y: 0 },
});
const nodeDragRef = useRef<{ active: boolean; nodeId: string; startX: number; startY: number; originX: number; originY: number }>({ const nodeDragRef = useRef<{ active: boolean; nodeId: string; startX: number; startY: number; originX: number; originY: number }>({
active: false, active: false,
nodeId: "", nodeId: "",
@@ -1535,6 +1558,114 @@ function ProductClonePage(_props: ProductClonePageProps = {}) {
[previewOffset.x, previewOffset.y, previewZoom], [previewOffset.x, previewOffset.y, previewZoom],
); );
const updatePreviewTransform = (nextZoom: number, nextOffset: { x: number; y: number }) => {
previewZoomRef.current = nextZoom;
previewOffsetRef.current = nextOffset;
setPreviewZoom(nextZoom);
setPreviewOffset(nextOffset);
};
const getPreviewGestureDistance = (points: PreviewTouchPoint[]) => {
if (points.length < 2) return 0;
return Math.hypot(points[0]!.x - points[1]!.x, points[0]!.y - points[1]!.y);
};
const getPreviewGestureCenter = (points: PreviewTouchPoint[]) => {
if (points.length < 2) return points[0] ? { x: points[0].x, y: points[0].y } : { x: 0, y: 0 };
return {
x: (points[0]!.x + points[1]!.x) / 2,
y: (points[0]!.y + points[1]!.y) / 2,
};
};
const isPreviewTouchInteractiveTarget = (target: HTMLElement | null) =>
Boolean(target?.closest(".ecom-command-composer-wrap, .clone-ai-preview-header, .clone-ai-source-corner-action, input, textarea, select, a, button"));
const startPreviewTouchGesture = (event: ReactPointerEvent<HTMLElement>) => {
if (event.pointerType === "mouse" || isPreviewTouchInteractiveTarget(event.target as HTMLElement | null)) return;
event.preventDefault();
event.currentTarget.setPointerCapture(event.pointerId);
const points = [
...previewTouchGestureRef.current.points.filter((point) => point.id !== event.pointerId),
{ id: event.pointerId, x: event.clientX, y: event.clientY },
].slice(-2);
const mode = points.length >= 2 ? "pinch" : "pan";
previewTouchGestureRef.current = {
mode,
points,
startOffset: previewOffsetRef.current,
startZoom: previewZoomRef.current,
startDistance: getPreviewGestureDistance(points),
startCenter: getPreviewGestureCenter(points),
};
event.currentTarget.classList.add("is-touch-panning");
};
const movePreviewTouchGesture = (event: ReactPointerEvent<HTMLElement>) => {
const gesture = previewTouchGestureRef.current;
if (gesture.mode === "none" || event.pointerType === "mouse") return;
event.preventDefault();
const points = gesture.points.map((point) => point.id === event.pointerId ? { ...point, x: event.clientX, y: event.clientY } : point);
if (!points.some((point) => point.id === event.pointerId)) return;
if (gesture.mode === "pinch" && points.length >= 2 && gesture.startDistance > 0) {
const rect = event.currentTarget.getBoundingClientRect();
const center = getPreviewGestureCenter(points);
const zoomRatio = getPreviewGestureDistance(points) / gesture.startDistance;
const nextZoom = Math.min(2, Math.max(0.25, gesture.startZoom * zoomRatio));
const startCenterX = gesture.startCenter.x - rect.left;
const startCenterY = gesture.startCenter.y - rect.top;
const currentCenterX = center.x - rect.left;
const currentCenterY = center.y - rect.top;
const contentX = (startCenterX - gesture.startOffset.x) / gesture.startZoom;
const contentY = (startCenterY - gesture.startOffset.y) / gesture.startZoom;
updatePreviewTransform(nextZoom, {
x: currentCenterX - contentX * nextZoom,
y: currentCenterY - contentY * nextZoom,
});
} else {
const point = points[0]!;
const startPoint = gesture.points[0]!;
updatePreviewTransform(gesture.startZoom, {
x: gesture.startOffset.x + point.x - startPoint.x,
y: gesture.startOffset.y + point.y - startPoint.y,
});
}
previewTouchGestureRef.current = { ...gesture, points };
};
const stopPreviewTouchGesture = (event: ReactPointerEvent<HTMLElement>) => {
const gesture = previewTouchGestureRef.current;
if (event.pointerType === "mouse" || gesture.mode === "none") return;
const points = gesture.points.filter((point) => point.id !== event.pointerId);
if (points.length) {
previewTouchGestureRef.current = {
mode: "pan",
points,
startOffset: previewOffsetRef.current,
startZoom: previewZoomRef.current,
startDistance: 0,
startCenter: getPreviewGestureCenter(points),
};
} else {
previewTouchGestureRef.current = {
mode: "none",
points: [],
startOffset: previewOffsetRef.current,
startZoom: previewZoomRef.current,
startDistance: 0,
startCenter: { x: 0, y: 0 },
};
event.currentTarget.classList.remove("is-touch-panning");
}
try {
event.currentTarget.releasePointerCapture(event.pointerId);
} catch {
// Pointer capture can already be released by the browser after cancel.
}
};
useEffect(() => { useEffect(() => {
const container = previewSurfaceRef.current; const container = previewSurfaceRef.current;
if (!container) return undefined; if (!container) return undefined;
@@ -1644,8 +1775,43 @@ function ProductClonePage(_props: ProductClonePageProps = {}) {
onAuxClick: (event: ReactMouseEvent<HTMLElement>) => { onAuxClick: (event: ReactMouseEvent<HTMLElement>) => {
if (event.button === 1) event.preventDefault(); if (event.button === 1) event.preventDefault();
}, },
onPointerDown: startPreviewTouchGesture,
onPointerMove: movePreviewTouchGesture,
onPointerUp: stopPreviewTouchGesture,
onPointerCancel: stopPreviewTouchGesture,
}); });
const startCanvasNodeDrag = (event: ReactPointerEvent<HTMLElement>, node: CanvasNode) => {
if (event.button !== 0 || event.pointerType === "mouse") return;
if ((event.target as HTMLElement | null)?.closest("button, a, input, textarea, select")) return;
event.preventDefault();
event.stopPropagation();
event.currentTarget.setPointerCapture(event.pointerId);
nodeDragRef.current = { active: true, nodeId: node.id, startX: event.clientX, startY: event.clientY, originX: node.x, originY: node.y };
};
const moveCanvasNodeDrag = (event: ReactPointerEvent<HTMLElement>, nodeId: string) => {
const drag = nodeDragRef.current;
if (!drag.active || drag.nodeId !== nodeId || event.pointerType === "mouse") return;
event.preventDefault();
event.stopPropagation();
const zoom = previewZoomRef.current;
const dx = (event.clientX - drag.startX) / zoom;
const dy = (event.clientY - drag.startY) / zoom;
setCanvasNodes((prev) => prev.map((node) => node.id === nodeId ? { ...node, x: drag.originX + dx, y: drag.originY + dy } : node));
};
const stopCanvasNodeDrag = (event: ReactPointerEvent<HTMLElement>, nodeId: string) => {
if (nodeDragRef.current.nodeId !== nodeId || event.pointerType === "mouse") return;
nodeDragRef.current = { ...nodeDragRef.current, active: false };
event.stopPropagation();
try {
event.currentTarget.releasePointerCapture(event.pointerId);
} catch {
// Pointer capture can already be released by the browser after cancel.
}
};
const handlePreviewWheel = (event: React.WheelEvent<HTMLElement>) => { const handlePreviewWheel = (event: React.WheelEvent<HTMLElement>) => {
if (!event.currentTarget) return; if (!event.currentTarget) return;
const container = event.currentTarget as HTMLElement; const container = event.currentTarget as HTMLElement;
@@ -5102,6 +5268,10 @@ function ProductClonePage(_props: ProductClonePageProps = {}) {
data-mode={node.mode} data-mode={node.mode}
data-node-id={node.id} data-node-id={node.id}
style={{ transform: `translate(${node.x}px, ${node.y}px)` }} style={{ transform: `translate(${node.x}px, ${node.y}px)` }}
onPointerDown={(event) => startCanvasNodeDrag(event, node)}
onPointerMove={(event) => moveCanvasNodeDrag(event, node.id)}
onPointerUp={(event) => stopCanvasNodeDrag(event, node.id)}
onPointerCancel={(event) => stopCanvasNodeDrag(event, node.id)}
> >
<div <div
className="clone-ai-node-drag-handle" className="clone-ai-node-drag-handle"
@@ -5242,19 +5412,26 @@ function ProductClonePage(_props: ProductClonePageProps = {}) {
</div> </div>
<div className="clone-ai-input-wrapper ecom-command-composer"> <div className="clone-ai-input-wrapper ecom-command-composer">
{productImages.length ? ( {productImages.length ? (
<div className="ecom-command-asset-popover" aria-label="已上传素材"> <div className="ecom-command-asset-popover" aria-label={`已上传素材,${productImages.length}/${maxCloneProductImages}`}>
<button
type="button"
className="ecom-command-asset-add"
onClick={() => productImages.length < maxCloneProductImages && productInputRef.current?.click()}
disabled={productImages.length >= maxCloneProductImages}
aria-label={productImages.length >= maxCloneProductImages ? `最多上传${maxCloneProductImages}张素材` : "继续上传素材"}
title={productImages.length >= maxCloneProductImages ? `最多上传 ${maxCloneProductImages} 张素材` : `继续上传素材 ${productImages.length}/${maxCloneProductImages}`}
>
<span aria-hidden="true">+</span>
<small>{productImages.length >= maxCloneProductImages ? "已满" : "上传"}</small>
</button>
{productImages.map((image) => ( {productImages.map((image) => (
<figure key={image.id} className="ecom-command-asset-thumb"> <figure key={image.id} className="ecom-command-asset-thumb">
<img src={image.src} alt={image.name || "上传图片"} /> <img src={image.src} alt={image.name || "上传图片"} />
<span className="ecom-command-asset-zoom" aria-hidden="true">
<img src={image.src} alt="" />
</span>
<button type="button" onClick={() => removeProductImage(image.id)} aria-label="删除图片"> <button type="button" onClick={() => removeProductImage(image.id)} aria-label="删除图片">
<DeleteOutlined /> <DeleteOutlined />
</button> </button>
</figure> </figure>
))} ))}
<button type="button" className="ecom-command-asset-add" onClick={() => productInputRef.current?.click()} aria-label="继续上传">+</button>
</div> </div>
) : null} ) : null}
<div className="ecom-command-option-row ecom-command-option-row--settings"> <div className="ecom-command-option-row ecom-command-option-row--settings">
@@ -6666,6 +6843,25 @@ function ProductClonePage(_props: ProductClonePageProps = {}) {
const currentResultCount = canvasNodes.reduce((count, node) => count + node.results.length, 0); const currentResultCount = canvasNodes.reduce((count, node) => count + node.results.length, 0);
const activeHistoryRecord = activeHistoryRecordId ? ecommerceHistoryRecords.find((record) => record.id === activeHistoryRecordId) : null; const activeHistoryRecord = activeHistoryRecordId ? ecommerceHistoryRecords.find((record) => record.id === activeHistoryRecordId) : null;
const currentResultThumbs = canvasNodes.flatMap((node) => node.results).slice(0, 6); const currentResultThumbs = canvasNodes.flatMap((node) => node.results).slice(0, 6);
const activeHistoryImageIds = new Set((activeHistoryRecord?.productImages ?? []).map((image) => image.id));
const historyConversationImages = activeHistoryRecord?.productImages?.length ? activeHistoryRecord.productImages : productImages;
const newConversationImages = activeHistoryRecord ? productImages.filter((image) => !activeHistoryImageIds.has(image.id)) : [];
const historyRequirementText = activeHistoryRecord?.requirement?.trim() || requirement.trim();
const newRequirementText = requirement.trim() && requirement.trim() !== historyRequirementText
? requirement.trim()
: "继续上传素材,准备下一轮生成。";
const historyRequirementMeta = [
{ label: "平台", value: activeHistoryRecord?.platform || platform },
{ label: "语种", value: activeHistoryRecord?.language || language },
{ label: "比例", value: formatRatioDisplayValue(activeHistoryRecord?.ratio || ratio) },
{ label: "设置", value: composerSettingLabel },
];
const currentRequirementMeta = [
{ label: "平台", value: platform },
{ label: "语种", value: language },
{ label: "比例", value: formatRatioDisplayValue(ratio) },
{ label: "设置", value: composerSettingLabel },
];
return ( return (
<section <section
@@ -6727,16 +6923,44 @@ function ProductClonePage(_props: ProductClonePageProps = {}) {
<div className="clone-ai-conversation-body"> <div className="clone-ai-conversation-body">
<section className="clone-ai-chat-message clone-ai-chat-message--user"> <section className="clone-ai-chat-message clone-ai-chat-message--user">
<span></span> <span></span>
<p>{requirement.trim() || "上传商品素材,描述你想生成的商品图、详情图、模特图或短视频。"}</p> <p>{historyRequirementText || "上传商品素材,描述你想生成的商品图、详情图、模特图或短视频。"}</p>
{productImages.length ? ( <div className="clone-ai-chat-meta" aria-label="需求参数">
{historyRequirementMeta.map((item) => (
<em key={item.label}>
<span>{item.label}</span>
<strong>{item.value}</strong>
</em>
))}
</div>
{historyConversationImages.length ? (
<div className="clone-ai-chat-assets" aria-label="已上传素材"> <div className="clone-ai-chat-assets" aria-label="已上传素材">
{productImages.slice(0, 4).map((image) => ( {historyConversationImages.slice(0, 4).map((image) => (
<img key={image.id} src={image.src} alt={image.name || "商品素材"} /> <img key={image.id} src={image.src} alt={image.name || "商品素材"} />
))} ))}
{productImages.length > 4 ? <em>+{productImages.length - 4}</em> : null} {historyConversationImages.length > 4 ? <em>+{historyConversationImages.length - 4}</em> : null}
</div> </div>
) : null} ) : null}
</section> </section>
{newConversationImages.length ? (
<section className="clone-ai-chat-message clone-ai-chat-message--user clone-ai-chat-message--followup">
<span></span>
<p>{newRequirementText}</p>
<div className="clone-ai-chat-meta" aria-label="新需求参数">
{currentRequirementMeta.map((item) => (
<em key={item.label}>
<span>{item.label}</span>
<strong>{item.value}</strong>
</em>
))}
</div>
<div className="clone-ai-chat-assets" aria-label="新增素材">
{newConversationImages.slice(0, 4).map((image) => (
<img key={image.id} src={image.src} alt={image.name || "新增商品素材"} />
))}
{newConversationImages.length > 4 ? <em>+{newConversationImages.length - 4}</em> : null}
</div>
</section>
) : null}
<section className={`clone-ai-chat-message clone-ai-chat-message--assistant is-${status}`}> <section className={`clone-ai-chat-message clone-ai-chat-message--assistant is-${status}`}>
<span></span> <span></span>
<p> <p>
@@ -6815,7 +7039,7 @@ function ProductClonePage(_props: ProductClonePageProps = {}) {
onClick={refreshEcommerceHistory} onClick={refreshEcommerceHistory}
disabled={isHistoryRefreshing} disabled={isHistoryRefreshing}
> >
<ReloadOutlined />
</button> </button>
</div> </div>
<div className="ecom-command-history__heading"> <div className="ecom-command-history__heading">
File diff suppressed because it is too large Load Diff