添加下载全部文件功能

This commit is contained in:
xixi 2024-10-29 09:37:55 +08:00
parent 29064fc5e5
commit 9e7f0a2b7e

View File

@ -33,9 +33,10 @@ import DisplayOrderShow from '../../route/proj/edit/ProjConfigMenuListShow.tsx'
export default function CardProj(props: any) {
const height = window.innerHeight - 250;
// 下载等待弹窗
const [downModal,setDownModal] = useState(false)
const [downModal, setDownModal] = useState(false)
// 是否已经点击下载按钮
const [hasDown,setHasDown] = useState(false)
const [hasDown, setHasDown] = useState(false)
// 是否可以关闭等待下载弹窗
// // 选项数组
// const [tagArray, setTagArray] = useState([])
// // 获取标签
@ -77,31 +78,26 @@ export default function CardProj(props: any) {
// },
// onSuccess(data: any) {
// console.log(data)
// },
// onFinally() {
// }
// })
// }
const downAll = async (projId: string,name:string) => {
const downAll = async (projId: string, name: string) => {
setHasDown(true)
if(!hasDown){
if (!hasDown) {
try {
setDownModal(true)
setHasDown(true)
// 发送请求
const response = await Axios.get(
`${Axios.defaults?.baseURL}/route/proj/download/all/${projId}`,
{
responseType: 'blob', // 设置响应类型为 blob
headers: {
'Content-Type': 'application/octet-stream',
},
}
{ responseType: 'blob' } // 指定响应类型为 blob
);
// 检查状态码
if (response.status === 200) {
setDownModal(false)
@ -117,24 +113,24 @@ export default function CardProj(props: any) {
link.click(); // 触发下载
document.body.removeChild(link); // 下载完成后移除 <a> 元素
// 释放 URL 对象
window.URL.revokeObjectURL(url);
// window.URL.revokeObjectURL(url);
} else {
console.error('下载失败');
// 你可以在这里处理错误情况,例如显示错误消息
}
} catch (error) {
console.error('请求失败', error);
// 你可以在这里处理错误情况,例如显示错误消息
}finally {
} finally {
// 无论请求成功与否,下载完成后都重置 hasDown 状态
setHasDown(false);
setDownModal(false); // 关闭模态框
setDownModal(false); // 关闭模态框
}
}else{
} else {
setDownModal(true);
}
};
// 更新标签状态
const upTag = (dataId: string, projId: string) => {
@ -539,7 +535,7 @@ export default function CardProj(props: any) {
</div>
<Button size="small" type="text" onClick={() => {
// window.open(`${Axios.defaults?.baseURL}/route/proj/download/all/${data.projId}`)
downAll(data.projId,data.projName)
downAll(data.projId, data.projName)
}}><DownloadOutlined /> </Button>
</div>
) : <></>
@ -888,23 +884,23 @@ export default function CardProj(props: any) {
height: `${height}px`,
}}
destroyOnClose={true}
open={downModal}
open={downModal}
footer={
<Button
type="primary"
onClick={() => setDownModal(false)}
// style={{
// backgroundColor: '#ff4d4f', // 自定义背景颜色
// borderColor: '#ff4d4f', // 自定义边框颜色
// color: '#fff', // 自定义文字颜色
// }}
<Button
type="primary"
onClick={() => setDownModal(false)}
// style={{
// backgroundColor: '#ff4d4f', // 自定义背景颜色
// borderColor: '#ff4d4f', // 自定义边框颜色
// color: '#fff', // 自定义文字颜色
// }}
>
</Button>
}
onCancel={() => { setDownModal(false) }} width={500} >
<div style={{width:500}}>
<span style={{marginLeft:10}}><LoadingOutlined /></span>
onCancel={() => { setDownModal(false) }} width={500} >
<div style={{ width: 500 }}>
<span style={{ marginLeft: 10 }}><LoadingOutlined /></span>
</div>
</Modal>
</>