refactor(auth):重构认证服务并移除冗余代码

- 移除了 AuthServiceImpl 中的登录、注册、token 验证等方法,仅保留错误上报和客户端信息功能
- 删除了设备注册和离线通知相关逻辑
- 移除了 IAuthService 接口中的登录、注册、验证 token 等方法定义
- 清理了 AccountManager.vue 中的无关注释文字-优化了阿里巴巴1688 服务中的图片上传处理逻辑- 移除了 AmazonScrapingServiceImpl 中未使用的日志导入和空行
- 统一了 Vue 组件中的同步导入方式,替换异步组件定义
- 更新了应用配置文件中的服务器地址和懒加载设置
- 新增缓存管理服务用于统一清理各类缓存数据
- 优化了设备 IP 地址获取逻辑并在注册时传递给后端- 调整了构建配置以减小安装包体积并支持多语言
- 修改了主进程窗口加载逻辑以适配开发与生产环境- 添加了全局样式限制图片预览器尺寸
- 移除了设备 ID 测试类和部分无用的正则表达式导入
This commit is contained in:
2025-10-20 18:01:40 +08:00
parent 0c85aa5677
commit 17f03c3ade
27 changed files with 517 additions and 535 deletions

View File

@@ -23,23 +23,27 @@ function openAppIfNotOpened() {
if (appOpened) return;
appOpened = true;
if (mainWindow && !mainWindow.isDestroyed()) {
isDev
? mainWindow.loadURL(`http://localhost:${process.argv[2] || 8083}`)
: mainWindow.loadFile(join(__dirname, '../renderer/index.html'));
mainWindow.webContents.once('did-finish-load', () => {
setTimeout(() => {
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.show();
mainWindow.focus();
const config = loadConfig();
const shouldMinimize = config.launchMinimized || false;
if (!shouldMinimize) {
mainWindow.show();
mainWindow.focus();
}
if (isDev) mainWindow.webContents.openDevTools();
}
if (splashWindow && !splashWindow.isDestroyed()) {
splashWindow.close();
splashWindow = null;
}
}, 1000);
}, 500);
});
isDev
? mainWindow.loadURL(`http://localhost:${process.argv[2] || 8083}`)
: mainWindow.loadFile(join(__dirname, '../renderer/index.html'));
}
}
@@ -78,11 +82,17 @@ function getDataDirectoryPath(): string {
return dataDir;
}
interface AppConfig {
closeAction?: 'quit' | 'minimize' | 'tray';
autoLaunch?: boolean;
launchMinimized?: boolean;
}
function getConfigPath(): string {
return join(app.getPath('userData'), 'config.json');
}
function loadConfig(): { closeAction?: 'quit' | 'minimize' | 'tray' } {
function loadConfig(): AppConfig {
try {
const configPath = getConfigPath();
if (existsSync(configPath)) {
@@ -94,7 +104,7 @@ function loadConfig(): { closeAction?: 'quit' | 'minimize' | 'tray' } {
return {};
}
function saveConfig(config: any) {
function saveConfig(config: AppConfig) {
try {
const configPath = getConfigPath();
require('fs').writeFileSync(configPath, JSON.stringify(config, null, 2));
@@ -138,7 +148,6 @@ function startSpringBoot() {
}
try {
// Spring Boot启动参数配置
const springArgs = [
'-jar', jarPath,
`--spring.datasource.url=jdbc:sqlite:${dataDir}/erp-cache.db`,
@@ -146,32 +155,20 @@ function startSpringBoot() {
`--logging.config=file:${logbackConfigPath}`
];
// 工作目录设为数据目录这样Spring Boot会在数据目录下创建临时文件
springProcess = spawn(javaPath, springArgs, {
cwd: dataDir,
detached: false
detached: false,
stdio: ['ignore', 'pipe', 'pipe']
});
let startupCompleted = false;
springProcess.stdout?.on('data', (data) => {
const output = data.toString();
console.log('[Spring Boot]', output.trim());
if (!startupCompleted && (output.includes('Started Success') || output.includes('Started ErpClientSbApplication'))) {
startupCompleted = true;
openAppIfNotOpened();
}
console.log('[Spring Boot]', data.toString().trim());
});
springProcess.stderr?.on('data', (data) => {
const output = data.toString();
console.log('[Spring Boot]', output.trim());
if (!startupCompleted && (output.includes('Started Success') || output.includes('Started ErpClientSbApplication'))) {
startupCompleted = true;
openAppIfNotOpened();
}
console.log('[Spring Boot]', data.toString().trim());
});
springProcess.on('close', (code) => {
@@ -187,8 +184,25 @@ function startSpringBoot() {
app.quit();
});
const checkHealth = () => {
if (startupCompleted) return;
http.get('http://127.0.0.1:8081', (res) => {
if (!startupCompleted) {
startupCompleted = true;
console.log('[Spring Boot] 服务已就绪');
openAppIfNotOpened();
}
}).on('error', () => {
setTimeout(checkHealth, 200);
});
};
setTimeout(checkHealth, 1000);
setTimeout(() => {
if (!startupCompleted) {
console.log('[Spring Boot] 启动超时,强制打开窗口');
openAppIfNotOpened();
}
}, 15000);
@@ -199,7 +213,7 @@ function startSpringBoot() {
}
}
startSpringBoot();
// startSpringBoot();
function stopSpringBoot() {
if (!springProcess) return;
@@ -225,9 +239,10 @@ function createWindow() {
mainWindow = new BrowserWindow({
width: 1280,
height: 800,
show: false,
show: false, //
autoHideMenuBar: true,
icon: getIconPath(),
backgroundColor: '#f5f5f5',
webPreferences: {
preload: join(__dirname, 'preload.js'),
nodeIntegration: false,
@@ -266,38 +281,52 @@ function createWindow() {
}
app.whenReady().then(() => {
// 应用开机自启动配置
const config = loadConfig();
const shouldMinimize = config.launchMinimized || false;
if (config.autoLaunch !== undefined) {
app.setLoginItemSettings({
openAtLogin: config.autoLaunch,
openAsHidden: shouldMinimize
});
}
createWindow();
createTray(mainWindow);
splashWindow = new BrowserWindow({
width: 1200,
height: 675,
frame: false,
transparent: false,
resizable: false,
alwaysOnTop: false,
show: true,
center: true,
icon: getIconPath(),
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
// 只有在不需要最小化启动时才显示 splash 窗口
if (!shouldMinimize) {
splashWindow = new BrowserWindow({
width: 1200,
height: 675,
frame: false,
transparent: false,
resizable: false,
alwaysOnTop: false,
show: true,
center: true,
icon: getIconPath(),
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
}
});
// 监听启动窗口关闭事件
splashWindow.on('closed', () => {
splashWindow = null;
});
const splashPath = getSplashPath();
if (existsSync(splashPath)) {
splashWindow.loadFile(splashPath);
}
});
// 监听启动窗口关闭事件
splashWindow.on('closed', () => {
splashWindow = null;
});
const splashPath = getSplashPath();
if (existsSync(splashPath)) {
splashWindow.loadFile(splashPath);
}
// setTimeout(() => {
// openAppIfNotOpened();
// }, 2000);
setTimeout(() => {
openAppIfNotOpened();
}, 2000);
app.on('activate', () => {
if (mainWindow && !mainWindow.isDestroyed()) {
@@ -709,6 +738,46 @@ ipcMain.handle('set-close-action', (event, action: 'quit' | 'minimize' | 'tray')
return { success: true };
});
// 清理缓存
ipcMain.handle('clear-cache', async () => {
try {
const response = await fetch('http://127.0.0.1:8081/api/system/cache/clear', {
method: 'POST'
});
const data = await response.json();
return data;
} catch (error: any) {
console.error('清理缓存失败:', error);
return { success: false, error: error.message };
}
});
// 获取启动配置
ipcMain.handle('get-launch-config', () => {
const config = loadConfig();
const loginSettings = app.getLoginItemSettings();
return {
autoLaunch: config.autoLaunch !== undefined ? config.autoLaunch : loginSettings.openAtLogin,
launchMinimized: config.launchMinimized || false
};
});
// 设置启动配置
ipcMain.handle('set-launch-config', (event, launchConfig: { autoLaunch: boolean; launchMinimized: boolean }) => {
const config = loadConfig();
config.autoLaunch = launchConfig.autoLaunch;
config.launchMinimized = launchConfig.launchMinimized;
saveConfig(config);
// 立即应用开机自启动设置
app.setLoginItemSettings({
openAtLogin: launchConfig.autoLaunch,
openAsHidden: launchConfig.launchMinimized
});
return { success: true };
});
async function getFileSize(url: string): Promise<number> {
return new Promise((resolve) => {