打包后下载模版报错
This commit is contained in:
parent
939c21cf67
commit
051481b631
|
|
@ -11,7 +11,6 @@ const { Column } = Table
|
||||||
const { confirm } = Modal;
|
const { confirm } = Modal;
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
const fs = require('fs').promises;
|
const fs = require('fs').promises;
|
||||||
const setting = JSON.parse(storage.getItem('setting') as string)
|
|
||||||
const User: React.FC = () => {
|
const User: React.FC = () => {
|
||||||
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
|
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
|
||||||
const [isCreateUser, setIsCreateUser] = useState(false);
|
const [isCreateUser, setIsCreateUser] = useState(false);
|
||||||
|
|
@ -79,36 +78,44 @@ const User: React.FC = () => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const fileUpLoad = async (data: { url: string, content: string, fileName: string }): Promise<void> => {
|
const fileUpLoad = async (data: { url: string, content: string, fileName: string }): Promise<void> => {
|
||||||
try {
|
const setting = await JSON.parse(storage.getItem('setting') as string)
|
||||||
const response = await fetch(data.url);
|
if (!setting.isShareSavePath) {
|
||||||
const arrayBuffer = await response.arrayBuffer();
|
window.electron.selectFilePath({
|
||||||
const buffer = Buffer.from(arrayBuffer);
|
fileName: data.fileName,
|
||||||
await fs.writeFile(`${setting.shareFilesPath}\\${data.fileName}`, buffer, {});
|
filePath: data.url
|
||||||
setChangeImportModal(false)
|
|
||||||
confirm({
|
|
||||||
title: '提示',
|
|
||||||
icon: <ExclamationCircleFilled />,
|
|
||||||
content: data.content,
|
|
||||||
centered: true,
|
|
||||||
okText: '打开文件夹',
|
|
||||||
cancelText: '关闭',
|
|
||||||
async onOk() {
|
|
||||||
await fs.access(setting.shareFilesPath, fs.constants.F_OK);
|
|
||||||
if (process.platform === 'win32') {
|
|
||||||
exec(`explorer "${setting.shareFilesPath}"`);
|
|
||||||
} else if (process.platform === 'darwin') {
|
|
||||||
exec(`open "${setting.shareFilesPath}"`);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onCancel() {
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
} catch (error: any) {
|
} else {
|
||||||
if (error.code === 'ENOENT') {
|
try {
|
||||||
message.error('文件夹不存在!')
|
const response = await fetch(data.url);
|
||||||
return
|
const arrayBuffer = await response.arrayBuffer();
|
||||||
} else {
|
const buffer = Buffer.from(arrayBuffer);
|
||||||
message.error(error)
|
await fs.writeFile(`${setting.shareFilesPath}\\${data.fileName}`, buffer, {});
|
||||||
|
setChangeImportModal(false)
|
||||||
|
confirm({
|
||||||
|
title: '提示',
|
||||||
|
icon: <ExclamationCircleFilled />,
|
||||||
|
content: data.content,
|
||||||
|
centered: true,
|
||||||
|
okText: '打开文件夹',
|
||||||
|
cancelText: '关闭',
|
||||||
|
async onOk() {
|
||||||
|
await fs.access(setting.shareFilesPath, fs.constants.F_OK);
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
exec(`explorer "${setting.shareFilesPath}"`);
|
||||||
|
} else if (process.platform === 'darwin') {
|
||||||
|
exec(`open "${setting.shareFilesPath}"`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onCancel() {
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error.code === 'ENOENT') {
|
||||||
|
message.error('文件夹不存在!')
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
message.error(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -453,6 +460,7 @@ const User: React.FC = () => {
|
||||||
<div>
|
<div>
|
||||||
<Button type="primary" className='m-ant-btn' style={{ width: '100%', marginBottom: '10px' }}
|
<Button type="primary" className='m-ant-btn' style={{ width: '100%', marginBottom: '10px' }}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
|
const setting = await JSON.parse(storage.getItem('setting') as string)
|
||||||
await fileUpLoad({
|
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',
|
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}`,
|
content: `下载导入模板成功!文件已保存至:${setting.shareFilesPath}`,
|
||||||
|
|
@ -470,6 +478,7 @@ const User: React.FC = () => {
|
||||||
file.type = "file";
|
file.type = "file";
|
||||||
file.accept = ".xls,.xlsx";
|
file.accept = ".xls,.xlsx";
|
||||||
file.onchange = async () => {
|
file.onchange = async () => {
|
||||||
|
const setting = await JSON.parse(storage.getItem('setting') as string)
|
||||||
const fileInfo = file.files[0];
|
const fileInfo = file.files[0];
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", fileInfo);
|
formData.append("file", fileInfo);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue