diff --git a/.env.example b/.env.example index 4550698..4a4e84e 100644 --- a/.env.example +++ b/.env.example @@ -10,9 +10,10 @@ ADMIN_PORT=3000 SESSION_SECRET=replace-with-a-long-random-value DEFAULT_BRAND_ID=00000000-0000-0000-0000-000000000001 SEED_ADMIN_PASSWORD=change-me-now-123 -OBJECT_STORAGE_ENDPOINT= -OBJECT_STORAGE_BUCKET= -OBJECT_STORAGE_ACCESS_KEY= -OBJECT_STORAGE_SECRET_KEY= +OBJECT_STORAGE_ENDPOINT=http://localhost:9000 +OBJECT_STORAGE_PUBLIC_URL=http://localhost:9000/personal-brand-media +OBJECT_STORAGE_BUCKET=personal-brand-media +OBJECT_STORAGE_ACCESS_KEY=minioadmin +OBJECT_STORAGE_SECRET_KEY=minioadmin WECHAT_APP_ID= WECHAT_APP_SECRET= diff --git a/apps/admin/src/components/ImageUrlField.tsx b/apps/admin/src/components/ImageUrlField.tsx index 52ca740..5831024 100644 --- a/apps/admin/src/components/ImageUrlField.tsx +++ b/apps/admin/src/components/ImageUrlField.tsx @@ -1,14 +1,51 @@ -import { Image, Input, Space, Typography } from "antd"; +import { InboxOutlined } from "@ant-design/icons"; +import { Image, Input, Space, Typography, Upload, message } from "antd"; +import { useState } from "react"; +import { createApiClient } from "../lib/api.js"; interface ImageUrlFieldProps { id?: string; value?: string; onChange?: (value: string) => void; placeholder?: string; + scope?: "brand" | "offering" | "trust"; } -export function ImageUrlField({ id, value, onChange, placeholder }: ImageUrlFieldProps) { +export function ImageUrlField({ id, value, onChange, placeholder, scope }: ImageUrlFieldProps) { const imageUrl = typeof value === "string" ? value.trim() : ""; + const [uploading, setUploading] = useState(false); + const client = createApiClient(); + + async function upload(file: File) { + if (!file.type.startsWith("image/")) { + message.error("仅支持图片文件"); + return; + } + if (file.size > 10 * 1024 * 1024) { + message.error("图片不能超过 10MB"); + return; + } + setUploading(true); + try { + const presign = await client.createPresignedUpload({ + fileName: file.name, + contentType: file.type, + ...(scope ? { scope } : {}), + }); + const response = await fetch(presign.uploadUrl, { + method: "PUT", + headers: { "content-type": file.type }, + body: file, + }); + if (!response.ok) throw new Error(`upload failed: ${response.status}`); + onChange?.(presign.publicUrl); + } catch { + message.error("图片上传失败,请重试"); + } finally { + setUploading(false); + } + } + return ( onChange?.(event.target.value)} placeholder={placeholder ?? "粘贴图片地址"} /> + { + void upload(file); + return false; + }} + > +

+ +

+

{uploading ? "上传中..." : "点击或拖拽上传图片"}

+

JPG、PNG、WebP 或 AVIF,最大 10MB

+
{imageUrl ? ( - + - - + + diff --git a/apps/admin/src/features/services/ServicesPage.tsx b/apps/admin/src/features/services/ServicesPage.tsx index 37bf9a0..caf1ce2 100644 --- a/apps/admin/src/features/services/ServicesPage.tsx +++ b/apps/admin/src/features/services/ServicesPage.tsx @@ -495,9 +495,9 @@ export function ServicesPage() { - + - +