react基于Ant Desgin Upload實現(xiàn)導(dǎo)入導(dǎo)出
更新時間:2024年01月07日 15:55:37 作者:夏林夕
本文主要介紹了react基于Ant Desgin Upload實現(xiàn)導(dǎo)入導(dǎo)出,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
效果圖:
導(dǎo)入:

導(dǎo)出:

導(dǎo)入代碼:
const propsConfig = {
name: 'file',
action: importDataExcelApi, //后端接口
headers: {
authorization: 'authorization-text',
loginUserId: sessionStorage.getItem('userLogin')
? JSON.parse(sessionStorage.getItem('userLogin')).userId : null
},
onChange(info) {
if (info.file.status !== 'uploading') {
console.log("++++++", info.file, "-------------" + info.fileList);
console.log(info.file.response.success);
}
if (info.file.status === 'done') {
message.success(`${info.file.name} 文件上傳成功!`).then(r => {
});
importDataRef.current(); // 調(diào)用 importData 方法
console.warn(sessionStorage.getItem('userLogin'))
} else if (info.file.status === 'error') {
// 不再觸發(fā) importDataExcelApi,因為文件格式有誤
message.error('文件格式有誤,導(dǎo)入失??!').then(r => {
});
}
},
};
const isUpload = () => {
Modal.warn({
title: '重新導(dǎo)入',
content: (
<div style={{width: '500px'}}>
<div style={{marginBottom: '20px'}}>
點擊上傳 會重新導(dǎo)入文件數(shù)據(jù)
</div>
<Upload
{...propsConfig}
direction="vertical" maxCount={1}
showUploadList={false}
>
<Button
onClick={againImport}
icon={<UploadOutlined/>}>
上傳
</Button>
</Upload>
</div>
),
onOk() {
// 在彈窗點擊確認(rèn)后執(zhí)行的操作
},
okText: '確定', // 修改確定按鈕的文字
// style: {width: '1000px', height: '500px'}, // 設(shè)置寬度和高度
});
};
<Button type="primary" onClick={isUpload} icon={<UploadOutlined/>}
>
重新導(dǎo)入
</Button>導(dǎo)出代碼
const config2 = {
title: '導(dǎo)出配置人員信息',
content: (
<>
<ReachableContext.Consumer>{() => `是否要導(dǎo)出配置人員信息`}</ReachableContext.Consumer>
</>
),
}
const exportData = () => {
exportDataExcel(screeningDate).then((res) => {
if (res.data === 'false') {
message.error("導(dǎo)出失敗").then(r => {})
return;
}
console.log('Export response:', res);
//設(shè)置下載文件類型為xlsx 不同的類型type也不一樣,創(chuàng)建URL對象
let url = window.URL.createObjectURL(new Blob([res],
{type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'}))
// 創(chuàng)建A標(biāo)簽
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
// 設(shè)置的下載文件文件名
const fileName = "配置人員信息";
// 觸發(fā)點擊方法
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
message.success("導(dǎo)出成功").then(r => {
});
});
}
<Button type="primary" style={{marginBottom: '30px'}}
onClick={async () => {
const confirmed = await modal.confirm(config2);
if (confirmed) {
// 調(diào)用另一個方法
exportData();
}
}}
>
導(dǎo)出
</Button>到此這篇關(guān)于react基于Ant Desgin Upload實現(xiàn)導(dǎo)入導(dǎo)出的文章就介紹到這了,更多相關(guān)react 導(dǎo)入導(dǎo)出內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
React+TS+IntersectionObserver實現(xiàn)視頻懶加載和自動播放功能
通過本文的介紹,我們學(xué)習(xí)了如何使用 React + TypeScript 和 IntersectionObserver API 來實現(xiàn)一個視頻播放控制組件,該組件具有懶加載功能,只有在用戶滾動頁面且視頻進(jìn)入視口時才開始下載視頻資源,需要的朋友可以參考下2023-04-04
React模仿網(wǎng)易云音樂實現(xiàn)一個音樂項目詳解流程
這篇文章主要介紹了React模仿網(wǎng)易云音樂實現(xiàn)一個音樂項目的詳細(xì)流程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
解決React報錯Functions are not valid as 
這篇文章主要為大家介紹了React報錯Functions are not valid as a React child解決詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12

