feat: 还原示例图片并优化媒体选择交互
This commit is contained in:
1 parent
03f947e9b8
commit
567921e726
20 files changed
+212
-44
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { CloudUploadOutlined, InboxOutlined } from "@ant-design/icons";
|
||||
import { Alert, Button, Image, Input, Space, Typography, Upload, message } from "antd";
|
||||
import { CloudUploadOutlined, DeleteOutlined, PictureOutlined } from "@ant-design/icons";
|
||||
import { Alert, Button, Image, Popconfirm, Space, Spin, Upload, message } from "antd";
|
||||
import { useEffect, useState } from "react";
|
||||
import { createApiClient } from "../lib/api.js";
|
||||
|
||||
@@ -66,13 +66,7 @@ export function ImageUrlField({ id, value, onChange, placeholder, scope }: Image
|
||||
}
|
||||
|
||||
return (
|
||||
<Space direction="vertical" size={8} style={{ width: "100%" }}>
|
||||
<Input
|
||||
{...(id ? { id } : {})}
|
||||
value={value}
|
||||
onChange={(event) => onChange?.(event.target.value)}
|
||||
placeholder={placeholder ?? "粘贴图片地址"}
|
||||
/>
|
||||
<Space direction="vertical" size={4} style={{ width: "100%" }}>
|
||||
{storageStatus !== "ok" ? (
|
||||
<Alert
|
||||
type={storageStatus === "loading" ? "info" : "warning"}
|
||||
@@ -86,22 +80,54 @@ export function ImageUrlField({ id, value, onChange, placeholder, scope }: Image
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
<Upload.Dragger
|
||||
accept="image/*"
|
||||
multiple={false}
|
||||
showUploadList={false}
|
||||
disabled={uploading || storageStatus !== "ok"}
|
||||
beforeUpload={(file) => {
|
||||
if (storageStatus === "ok") void upload(file);
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<p className="ant-upload-drag-icon">
|
||||
<InboxOutlined />
|
||||
</p>
|
||||
<p className="ant-upload-text">{uploading ? "上传中..." : "点击或拖拽上传图片"}</p>
|
||||
<p className="ant-upload-hint">JPG、PNG、WebP 或 AVIF,最大 10MB</p>
|
||||
</Upload.Dragger>
|
||||
{imageUrl ? (
|
||||
<div
|
||||
style={{
|
||||
position: "relative",
|
||||
width: "100%",
|
||||
minHeight: 140,
|
||||
borderRadius: 8,
|
||||
overflow: "hidden",
|
||||
border: "1px solid #d9d9d9",
|
||||
background: "#f5f5f5",
|
||||
}}
|
||||
>
|
||||
<Image
|
||||
src={imageUrl}
|
||||
alt={placeholder ?? "图片预览"}
|
||||
width="100%"
|
||||
height={180}
|
||||
preview
|
||||
style={{ objectFit: "cover" }}
|
||||
fallback="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="
|
||||
/>
|
||||
<Popconfirm title="移除这张图片?" onConfirm={() => onChange?.("")}>
|
||||
<Button
|
||||
danger
|
||||
size="small"
|
||||
icon={<DeleteOutlined />}
|
||||
style={{ position: "absolute", top: 8, right: 8 }}
|
||||
>
|
||||
移除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
) : (
|
||||
<Upload.Dragger
|
||||
accept="image/*"
|
||||
multiple={false}
|
||||
showUploadList={false}
|
||||
disabled={uploading || storageStatus !== "ok"}
|
||||
beforeUpload={(file) => {
|
||||
if (storageStatus === "ok") void upload(file);
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<p className="ant-upload-drag-icon">{uploading ? <Spin /> : <PictureOutlined />}</p>
|
||||
<p className="ant-upload-text">{uploading ? "上传中..." : "点击或拖拽上传图片"}</p>
|
||||
<p className="ant-upload-hint">JPG、PNG、WebP 或 AVIF,最大 10MB</p>
|
||||
</Upload.Dragger>
|
||||
)}
|
||||
{storageStatus === "unavailable" ? (
|
||||
<Button
|
||||
icon={<CloudUploadOutlined />}
|
||||
@@ -118,19 +144,7 @@ export function ImageUrlField({ id, value, onChange, placeholder, scope }: Image
|
||||
重新检查存储
|
||||
</Button>
|
||||
) : null}
|
||||
{imageUrl ? (
|
||||
<Space align="start">
|
||||
<Image
|
||||
src={imageUrl}
|
||||
width={96}
|
||||
height={64}
|
||||
preview
|
||||
fallback="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs="
|
||||
style={{ objectFit: "cover", borderRadius: 8, background: "#f5f5f5" }}
|
||||
/>
|
||||
<Typography.Text type="secondary">预览图</Typography.Text>
|
||||
</Space>
|
||||
) : null}
|
||||
<input {...(id ? { id } : {})} type="hidden" value={imageUrl} />
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user