更改了气泡确认框

main
ybc 2 months ago
parent da71562c11
commit 74aebe57c6

@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import { Upload, List, Modal } from "antd";
import { Upload, List, Popconfirm } from "antd";
import { UploadOutlined } from "@ant-design/icons";
import { Image } from "antd";
import { fetchJSON } from "@/utils/request";
@ -108,30 +109,18 @@ export const ImageUploader = props => {
}, [key]);
//
const handleDelete = file => {
Modal.confirm({
title: '确认删除',
content: '确定要删除这张图片吗?',
okText: '确认',
cancelText: '取消',
onOk: async () => {
const success = await deleteImage(file.encrypt_key);
if (success) {
const newImages = fileList.filter(item => item.encrypt_key !== file.encrypt_key);
if (props.onChange) {
props.onChange(newImages);
}
setFileList(newImages);
console.log("删除成功");
} else {
console.error("删除失败");
}
},
onCancel: () => {
// fileListUpload
setFileList([...fileList]);
},
});
const handleDelete = async file => {
const success = await deleteImage(file.encrypt_key);
if (success) {
const newImages = fileList.filter(item => item.encrypt_key !== file.encrypt_key);
if (props.onChange) {
props.onChange(newImages);
}
setFileList(newImages);
//console.log("");
} else {
//console.error("");
}
};
//
@ -176,9 +165,29 @@ export const ImageUploader = props => {
setPreviewOpen(true);
};
const handleRemove = file => {
// false Popconfirm
return false;
};
const itemRender = (originNode, file, fileList, actions) => {
return (
<Popconfirm
title="Confirm deletion"
description="Confirm deletion of this file?"
onConfirm={() => handleDelete(file)}
onCancel={() => setFileList([...fileList])}
okText="Yes"
cancelText="No"
>
{originNode}
</Popconfirm>
);
};
return (
<>
<Upload customRequest={handleUploadFile} multiple={true} onRemove={handleDelete} listType="picture-card" fileList={fileList} onPreview={handlePreview} onChange={handleChange}>
<Upload customRequest={handleUploadFile} multiple={true} onRemove={handleRemove} listType="picture-card" fileList={fileList} onPreview={handlePreview} onChange={handleChange} itemRender={itemRender}>
<div>
<UploadOutlined />
<div style={{ marginTop: 8 }}>上传图片</div>
@ -245,4 +254,4 @@ export const ImageViewer = props => {
);
};
export default ImageUploader;
export default ImageUploader;
Loading…
Cancel
Save