复制文件地址
This commit is contained in:
@@ -30,13 +30,10 @@ export default ({ dir, open, onCancel, onSuccess }: UploadFileProps) => {
|
|||||||
headers: {
|
headers: {
|
||||||
"Authorization": `Bearer ${store.token}`
|
"Authorization": `Bearer ${store.token}`
|
||||||
},
|
},
|
||||||
fileList, // 设置文件列表
|
showUploadList: false, // 不显示文件列表
|
||||||
onChange(info) {
|
async onChange(info) {
|
||||||
const { status } = info.file;
|
const { status } = info.file;
|
||||||
|
|
||||||
// 更新文件列表状态
|
|
||||||
setFileList(info.fileList);
|
|
||||||
|
|
||||||
let res;
|
let res;
|
||||||
if (status !== 'uploading') {
|
if (status !== 'uploading') {
|
||||||
res = info?.file?.response;
|
res = info?.file?.response;
|
||||||
@@ -44,8 +41,16 @@ export default ({ dir, open, onCancel, onSuccess }: UploadFileProps) => {
|
|||||||
if (res?.code === 400) return message.error(res.message);
|
if (res?.code === 400) return message.error(res.message);
|
||||||
}
|
}
|
||||||
if (status === 'done') {
|
if (status === 'done') {
|
||||||
message.success(`文件上传成功`);
|
// 上传时候先去重,避免重复url
|
||||||
|
const urls = [...new Set([...fileList, res.data])]
|
||||||
|
setFileList(urls)
|
||||||
|
|
||||||
|
// 复制文件链接到剪贴板
|
||||||
|
await navigator.clipboard.writeText(urls.join("\n"));
|
||||||
|
|
||||||
|
message.success(`文件上传成功,URL链接已复制到剪贴板`);
|
||||||
onSuccess();
|
onSuccess();
|
||||||
|
onCloseModel()
|
||||||
} else if (status === 'error') {
|
} else if (status === 'error') {
|
||||||
message.error(`文件上传失败:${res?.message}`);
|
message.error(`文件上传失败:${res?.message}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import { DeleteOutlined, DownloadOutlined, RotateLeftOutlined, RotateRightOutlin
|
|||||||
import "./index.scss"
|
import "./index.scss"
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
const [active, setActive] = useState("")
|
const [active, setActive] = useState("")
|
||||||
const [loading, setLoading] = useState(false)
|
|
||||||
const [dirName, setDirName] = useState("")
|
const [dirName, setDirName] = useState("")
|
||||||
const [dirList, setDirList] = useState<string[]>([])
|
const [dirList, setDirList] = useState<string[]>([])
|
||||||
const [fileList, setFileList] = useState<File[]>([])
|
const [fileList, setFileList] = useState<File[]>([])
|
||||||
@@ -147,7 +147,12 @@ export default () => {
|
|||||||
</Spin>
|
</Spin>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<FileUpload dir={dirName} open={isModalOpen} onSuccess={() => getFileList(dirName)} onCancel={() => setIsModalOpen(false)} />
|
<FileUpload
|
||||||
|
dir={dirName}
|
||||||
|
open={isModalOpen}
|
||||||
|
onSuccess={() => getFileList(dirName)}
|
||||||
|
onCancel={() => setIsModalOpen(false)}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user