增加导入文件重复判定
This commit is contained in:
parent
f82332fd1f
commit
90245dbb80
|
|
@ -12,10 +12,12 @@
|
|||
"output": "release"
|
||||
},
|
||||
"win": {
|
||||
"target": "dir"
|
||||
"target": "portable",
|
||||
"sign": null,
|
||||
"forceCodeSigning": false
|
||||
},
|
||||
"npmRebuild": false,
|
||||
"asar": false,
|
||||
"asar": true,
|
||||
"extraMetadata": {
|
||||
"main": "main.js"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,9 @@
|
|||
"react-start": "react-scripts start",
|
||||
"react-build": "react-scripts build",
|
||||
"rebuild": "electron-rebuild",
|
||||
"build": "electron-builder --publish never",
|
||||
"build": "electron-builder --config electron-builder-config.json --publish never",
|
||||
"package": "npm run react-build && npm run rebuild && npm run build",
|
||||
"package-portable": "npm run react-build && electron-packager . DataTools --platform=win32 --arch=x64 --out=release --overwrite --asar",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
|
|
|
|||
35
src/App.js
35
src/App.js
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useState, useEffect } from 'react';
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { ConfigProvider, theme, Switch, Space, Modal, Progress, message } from 'antd';
|
||||
import zhCN from 'antd/locale/zh_CN';
|
||||
import dayjs from 'dayjs';
|
||||
|
|
@ -26,6 +26,7 @@ function App() {
|
|||
const [currentProject, setCurrentProject] = useState(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [isDarkMode] = useState(true); // 固定使用深色主题
|
||||
const [lastImportedFilePath, setLastImportedFilePath] = useState(null); // 记录最后导入的文件路径
|
||||
|
||||
// 初始化数据
|
||||
useEffect(() => {
|
||||
|
|
@ -203,6 +204,34 @@ function App() {
|
|||
const filePath = await window.electronAPI.selectExcelFile();
|
||||
|
||||
if (filePath) {
|
||||
// 检查是否重复导入同一个文件
|
||||
if (lastImportedFilePath === filePath) {
|
||||
// 显示确认对话框
|
||||
Modal.confirm({
|
||||
title: '文件已导入',
|
||||
content: '该文件已经导入过,重新导入会覆盖之前的记录。确定要继续吗?',
|
||||
okText: '确定',
|
||||
cancelText: '取消',
|
||||
onOk: () => {
|
||||
// 用户确认后继续导入
|
||||
importFile(filePath);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 直接导入文件
|
||||
importFile(filePath);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('导入Excel文件失败:', error);
|
||||
message.error(`导入失败: ${error.message}`);
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 导入文件的实际逻辑
|
||||
const importFile = async (filePath) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
// 创建进度对话框
|
||||
|
|
@ -265,7 +294,9 @@ function App() {
|
|||
message.error(`导入失败: ${result.error}`);
|
||||
console.error('导入Excel文件失败:', result.error);
|
||||
setLoading(false);
|
||||
}
|
||||
} else {
|
||||
// 导入成功,更新最后导入的文件路径
|
||||
setLastImportedFilePath(filePath);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('导入Excel文件失败:', error);
|
||||
|
|
|
|||
|
|
@ -148,15 +148,7 @@ class ExcelService {
|
|||
// 将数据保存到数据库
|
||||
saveDataToDatabase(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 清空现有数据
|
||||
this.db.run('DELETE FROM projects', (err) => {
|
||||
if (err) {
|
||||
console.error('清空项目数据失败:', err);
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// 插入新数据
|
||||
// 不再清空现有数据,直接插入新数据
|
||||
const stmt = this.db.prepare(`
|
||||
INSERT INTO projects (
|
||||
unit,
|
||||
|
|
@ -303,7 +295,6 @@ class ExcelService {
|
|||
// 完成后关闭准备好的语句
|
||||
stmt.finalize();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 构建树状结构
|
||||
|
|
|
|||
Loading…
Reference in New Issue