素材库优化

This commit is contained in:
none
2023-03-06 10:14:04 +08:00
parent feda1feb95
commit a20c1c6090
7 changed files with 6 additions and 4 deletions

View File

@@ -0,0 +1,79 @@
import { Button, message, Modal } from "antd";
import Dragger from "antd/es/upload/Dragger";
import { useState } from "react";
import config from "../../../js/config";
import { getToken } from "../../../utils";
import { InboxOutlined } from "@ant-design/icons";
interface PropsInterface {
categoryId: number;
onUpdate: () => void;
}
export const UploadImageSub = (props: PropsInterface) => {
const [showModal, setShowModal] = useState(false);
const uploadProps = {
name: "file",
multiple: true,
action:
config.app_url +
"/backend/v1/upload/image?category_id=" +
props.categoryId,
headers: {
authorization: "Bearer " + getToken(),
},
onChange(info: any) {
const { status } = info.file;
if (status !== "uploading") {
console.log(info.file, info.fileList);
}
if (status === "done") {
message.success(`${info.file.name} 上传成功`);
} else if (status === "error") {
message.error(`${info.file.name} 上传失败`);
}
},
showUploadList: {
showRemoveIcon: false,
showDownloadIcon: false,
},
};
return (
<>
<Button
type="primary"
onClick={() => {
setShowModal(true);
}}
>
</Button>
{showModal && (
<Modal
open={true}
closable={false}
onCancel={() => {
setShowModal(false);
}}
onOk={() => {
props.onUpdate();
setShowModal(false);
}}
>
<Dragger {...uploadProps}>
<p className="ant-upload-drag-icon">
<InboxOutlined />
</p>
<p className="ant-upload-text"></p>
<p className="ant-upload-hint">
/ png,jpg,jpeg,gif
</p>
</Dragger>
</Modal>
)}
</>
);
};