如果不是图片显示下载链接

main
Ycc 1 month ago
parent 89b841bbbd
commit 1937cf48a1

@ -1,7 +1,6 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { Upload, List, Popconfirm } from "antd"; import { Upload, List, Button, Space } from "antd";
import { UploadOutlined, FileTextOutlined } from "@ant-design/icons";
import { UploadOutlined, DeleteOutlined } from "@ant-design/icons";
import { Image } from "antd"; import { Image } from "antd";
import { fetchJSON } from "@/utils/request"; import { fetchJSON } from "@/utils/request";
import { HT3_HOST } from "@/config"; import { HT3_HOST } from "@/config";
@ -109,7 +108,6 @@ export const ImageUploader = props => {
}, [key]); }, [key]);
// //
const handleDelete = async file => { const handleDelete = async file => {
const success = await deleteImage(file.encrypt_key); const success = await deleteImage(file.encrypt_key);
if (success) { if (success) {
@ -118,9 +116,9 @@ export const ImageUploader = props => {
props.onChange(newImages); props.onChange(newImages);
} }
setFileList(newImages); setFileList(newImages);
//console.log(""); console.log("删除成功");
} else { } else {
//console.error(""); console.error("删除失败");
} }
}; };
@ -166,42 +164,12 @@ export const ImageUploader = props => {
setPreviewOpen(true); setPreviewOpen(true);
}; };
const handleRemove = () => {
return false;
};
return ( return (
<> <>
<Upload <Upload customRequest={handleUploadFile} multiple={true} onRemove={handleDelete} listType="picture-card" fileList={fileList} onPreview={handlePreview} onChange={handleChange}>
customRequest={handleUploadFile}
multiple={true}
onRemove={handleRemove}
listType="picture-card"
fileList={fileList}
onPreview={handlePreview}
onChange={handleChange}
showUploadList={{
showDownloadIcon: true,
showRemoveIcon: true,
removeIcon: file => {
return (
<Popconfirm
title="删除"
description="是否要删除文件?"
onConfirm={() => {
handleDelete(file);
}}
onCancel={() => setFileList([...fileList])}
okText="是"
cancelText="否">
<DeleteOutlined />
</Popconfirm>
);
},
}}>
<div> <div>
<UploadOutlined /> <UploadOutlined />
<div style={{ marginTop: 8 }}>上传图片</div> <div style={{ marginTop: 8 }}>Upload</div>
</div> </div>
</Upload> </Upload>
<List loading={isLoading} dataSource={fileList} /> <List loading={isLoading} dataSource={fileList} />
@ -242,22 +210,22 @@ export const ImageViewer = props => {
return ( return (
<> <>
<List <Image.PreviewGroup>
grid={{ <Space>
gutter: 16, {fileList &&
sm: 2, fileList.map(item => {
md: 8, return item.key.match(/\.(jpg|jpeg|png|gif|bmp|webp)$/i) ? (
lg: 8, <Image key={item.encrypt_key} width={200} src={item.url} />
}} ) : (
dataSource={fileList} <a key={item.encrypt_key} href={item.url} download>
renderItem={item => { <Button type="primary" icon={<FileTextOutlined />} size="large">
return ( Download File
<List.Item> </Button>
<Image key={item.encrypt_key} width={200} src={item.url} /> </a>
</List.Item> );
); })}
}} </Space>
/> </Image.PreviewGroup>
</> </>
); );
}; };

Loading…
Cancel
Save