打包后下载模版报错

This commit is contained in:
yj 2024-09-09 11:34:21 +08:00
parent 939c21cf67
commit 051481b631
1 changed files with 39 additions and 30 deletions

View File

@ -11,7 +11,6 @@ const { Column } = Table
const { confirm } = Modal;
const { exec } = require('child_process');
const fs = require('fs').promises;
const setting = JSON.parse(storage.getItem('setting') as string)
const User: React.FC = () => {
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
const [isCreateUser, setIsCreateUser] = useState(false);
@ -79,6 +78,13 @@ const User: React.FC = () => {
})
}
const fileUpLoad = async (data: { url: string, content: string, fileName: string }): Promise<void> => {
const setting = await JSON.parse(storage.getItem('setting') as string)
if (!setting.isShareSavePath) {
window.electron.selectFilePath({
fileName: data.fileName,
filePath: data.url
})
} else {
try {
const response = await fetch(data.url);
const arrayBuffer = await response.arrayBuffer();
@ -112,6 +118,7 @@ const User: React.FC = () => {
}
}
}
}
return (
<>
@ -453,6 +460,7 @@ const User: React.FC = () => {
<div>
<Button type="primary" className='m-ant-btn' style={{ width: '100%', marginBottom: '10px' }}
onClick={async () => {
const setting = await JSON.parse(storage.getItem('setting') as string)
await fileUpLoad({
url: 'https://wgshare.oss-cn-chengdu.aliyuncs.com/%E7%94%A8%E6%88%B7%E6%89%B9%E9%87%8F%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF%E8%A1%A8.xlsx',
content: `下载导入模板成功!文件已保存至:${setting.shareFilesPath}`,
@ -470,6 +478,7 @@ const User: React.FC = () => {
file.type = "file";
file.accept = ".xls,.xlsx";
file.onchange = async () => {
const setting = await JSON.parse(storage.getItem('setting') as string)
const fileInfo = file.files[0];
const formData = new FormData();
formData.append("file", fileInfo);