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