From c26ebdde1b7bda17f0021a465ea3657cfbc3f756 Mon Sep 17 00:00:00 2001 From: developer_liu Date: Thu, 3 Sep 2026 16:04:10 +0800 Subject: [PATCH] =?UTF-8?q?v4.0.15=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8E=8B=E7=BC=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin-web/src/components/OssUpload.tsx | 47 +++++++- apps/admin-web/src/lib/upload.ts | 2 + .../src/pages/ActivityPostersPage.tsx | 3 +- docs/杜康好客-v4-现状对照.md | 4 +- docs/杜康好客-v4.0.15-开发文档.md | 35 ++++++ .../shared-types/src/activity-poster.test.ts | 25 +++++ packages/shared-types/src/activity-poster.ts | 33 ++++++ .../image/activity-poster-upload.util.ts | 101 ++++++++++++++++++ .../src/modules/common/resource.service.ts | 71 ++++++++++-- 9 files changed, 308 insertions(+), 13 deletions(-) create mode 100644 server/dukang-api/src/common/image/activity-poster-upload.util.ts diff --git a/apps/admin-web/src/components/OssUpload.tsx b/apps/admin-web/src/components/OssUpload.tsx index 12f1634..314edf2 100644 --- a/apps/admin-web/src/components/OssUpload.tsx +++ b/apps/admin-web/src/components/OssUpload.tsx @@ -1,5 +1,5 @@ -import { useState } from 'react'; -import { Button, Image, Input, Modal, Space, Upload, message } from 'antd'; +import { useState, type ReactNode } from 'react'; +import { Button, Image, Input, Modal, Space, Typography, Upload, message } from 'antd'; import { EyeOutlined, FilePdfOutlined, UploadOutlined } from '@ant-design/icons'; import type { UploadProps } from 'antd'; import { uploadFileToOss, type OssMediaType, type UploadFileResult } from '../lib/upload'; @@ -13,6 +13,7 @@ type OssUploadProps = { accept?: string; maxSizeMb?: number; placeholder?: string; + uploadHint?: ReactNode; }; function isImageUrl(url: string) { @@ -23,6 +24,32 @@ function isPdfUrl(url: string) { return /\.pdf(\?|#|$)/i.test(url); } +function formatUploadImageMessage(result: UploadFileResult): string { + const img = result.image; + if (!img) return '上传成功'; + const sizeLabel = `${img.width}×${img.height}`; + if (img.compressed && img.originalWidth && img.originalHeight) { + const original = `${img.originalWidth}×${img.originalHeight}`; + if (original !== sizeLabel) { + return `上传成功(${sizeLabel},已由 ${original} 自动压缩)`; + } + } + return `上传成功(${sizeLabel})`; +} + +function formatUploadImageHint(result: UploadFileResult): string | null { + const img = result.image; + if (!img) return null; + const sizeLabel = `${img.width}×${img.height}`; + if (img.compressed && img.originalWidth && img.originalHeight) { + const original = `${img.originalWidth}×${img.originalHeight}`; + if (original !== sizeLabel) { + return `${sizeLabel}(已由 ${original} 自动压缩)`; + } + } + return sizeLabel; +} + export default function OssUpload({ value, onChange, @@ -31,9 +58,11 @@ export default function OssUpload({ mediaType = 'IMAGE', accept, placeholder = '上传后自动填入,或手动粘贴 URL', + uploadHint, }: OssUploadProps) { const [uploading, setUploading] = useState(false); const [pdfPreviewOpen, setPdfPreviewOpen] = useState(false); + const [imageMetaHint, setImageMetaHint] = useState(null); const resolvedAccept = accept ?? (mediaType === 'VIDEO' ? 'video/*' : mediaType === 'FILE' ? undefined : 'image/*'); @@ -45,7 +74,9 @@ export default function OssUpload({ const result = await uploadFileToOss(raw, { bizType, mediaType }); onChange?.(result.url); onUploaded?.(result); - message.success('上传成功'); + const successMessage = formatUploadImageMessage(result); + setImageMetaHint(formatUploadImageHint(result)); + message.success(successMessage); onSuccess?.(result); } catch (e) { const err = e instanceof Error ? e : new Error('上传失败'); @@ -116,6 +147,16 @@ export default function OssUpload({