feat(client): 实现用户数据隔离与设备绑定优化- 添加用户会话ID构建逻辑,确保数据按用户隔离- 优化设备绑定流程,支持设备状态更新和绑定时间同步- 实现用户缓存清理功能,仅清除当前用户的数据- 增强客户端账号删除逻辑,级联删除相关数据

- 调整设备在线查询逻辑,确保只返回活跃绑定的设备
- 优化试用期逻辑,精确计算过期时间和类型- 添加账号管理弹窗和相关状态注入
-修复跟卖精灵按钮加载状态显示问题
- 增强文件上传区域UI,显示选中文件名
- 调整分页组件样式,优化界面展示效果- 优化反馈日志存储路径逻辑,默认使用用户目录
- 移除冗余代码和无用导入,提升代码整洁度
This commit is contained in:
2025-10-24 13:43:46 +08:00
parent e2a438c84e
commit 3a76aaa3c0
50 changed files with 860 additions and 590 deletions

View File

@@ -82,6 +82,18 @@ function getDataDirectoryPath(): string {
return dataDir;
}
function getUpdateDirectoryPath(): string {
const updateDir = join(app.getPath('userData'), 'updates');
if (!existsSync(updateDir)) mkdirSync(updateDir, {recursive: true});
return updateDir;
}
function getLogDirectoryPath(): string {
const logDir = join(app.getPath('userData'), 'logs');
if (!existsSync(logDir)) mkdirSync(logDir, {recursive: true});
return logDir;
}
interface AppConfig {
closeAction?: 'quit' | 'minimize' | 'tray';
autoLaunch?: boolean;
@@ -135,12 +147,11 @@ function migrateDataFromPublic(): void {
function startSpringBoot() {
migrateDataFromPublic();
const jarPath = getJarFilePath();
const javaPath = getJavaExecutablePath();
const dataDir = getDataDirectoryPath();
const logDir = getLogDirectoryPath();
const logbackConfigPath = getLogbackConfigPath();
if (!existsSync(jarPath)) {
dialog.showErrorBox('启动失败', `JAR 文件不存在:\n${jarPath}`);
app.quit();
@@ -152,7 +163,8 @@ function startSpringBoot() {
'-jar', jarPath,
`--spring.datasource.url=jdbc:sqlite:${dataDir}/erp-cache.db`,
`--server.port=8081`,
`--logging.config=file:${logbackConfigPath}`
`--logging.config=file:${logbackConfigPath}`,
`--logging.file.path=${logDir}`
];
springProcess = spawn(javaPath, springArgs, {
@@ -212,9 +224,7 @@ function startSpringBoot() {
app.quit();
}
}
startSpringBoot();
function stopSpringBoot() {
if (!springProcess) return;
try {
@@ -390,49 +400,30 @@ ipcMain.handle('get-jar-version', () => {
function checkPendingUpdate() {
try {
const asarUpdatePath = join(process.resourcesPath, 'app.asar.update');
const appAsarPath = join(process.resourcesPath, 'app.asar');
const updateDir = getUpdateDirectoryPath();
const asarUpdatePath = join(updateDir, 'app.asar.update');
const jarUpdatePath = readdirSync(updateDir).find(f => f.startsWith('erp_client_sb-') && f.endsWith('.jar.update'));
// 查找jar更新文件
let jarUpdatePath = '';
if (process.resourcesPath && existsSync(process.resourcesPath)) {
const files = readdirSync(process.resourcesPath);
const jarUpdateFile = files.find(f => f.startsWith('erp_client_sb-') && f.endsWith('.jar.update'));
if (jarUpdateFile) {
jarUpdatePath = join(process.resourcesPath, jarUpdateFile);
}
}
// 如果没有任何更新文件,直接返回
if (!existsSync(asarUpdatePath) && !jarUpdatePath) return;
const appDir = dirname(process.execPath);
const helperPath = join(appDir, 'update-helper.bat');
if (!existsSync(helperPath)) return;
if (!existsSync(helperPath)) {
console.error('[UPDATE] 更新助手不存在:', helperPath);
return;
}
const appAsarPath = join(process.resourcesPath, 'app.asar');
const vbsPath = join(app.getPath('temp'), 'update-silent.vbs');
const vbsContent = `Set WshShell = CreateObject("WScript.Shell")
WshShell.Run Chr(34) & "${helperPath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${appAsarPath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${asarUpdatePath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${jarUpdatePath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${process.execPath.replace(/\\/g, '\\\\')}" & Chr(34), 0, False`;
WshShell.Run Chr(34) & "${helperPath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${appAsarPath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${asarUpdatePath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${jarUpdatePath ? join(updateDir, jarUpdatePath).replace(/\\/g, '\\\\') : ''}" & Chr(34) & " " & Chr(34) & "${process.execPath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${updateDir.replace(/\\/g, '\\\\')}" & Chr(34), 0, False`;
writeFileSync(vbsPath, vbsContent);
spawn('wscript.exe', [vbsPath], {
detached: true,
stdio: 'ignore',
shell: false
});
spawn('wscript.exe', [vbsPath], {detached: true, stdio: 'ignore', shell: false});
setTimeout(() => app.quit(), 1000);
} catch (error: unknown) {
console.error('[UPDATE] 更新失败:', error);
}
}
ipcMain.handle('download-update', async (event, downloadUrls: {asarUrl?: string, jarUrl?: string}) => {
ipcMain.handle('download-update', async (event, downloadUrls: {asarUrl?: string, jarUrl?: string, latestVersion?: string}) => {
if (isDownloading) return {success: false, error: '正在下载中'};
if (downloadedFilePath === 'completed') return {success: true, filePath: 'already-completed'};
@@ -454,8 +445,9 @@ ipcMain.handle('download-update', async (event, downloadUrls: {asarUrl?: string,
combinedTotalSize = asarSize + jarSize;
if (downloadUrls.asarUrl && !currentDownloadAbortController.signal.aborted) {
const tempAsarPath = join(app.getPath('temp'), 'app.asar.new');
await downloadFile(downloadUrls.asarUrl, tempAsarPath, (progress) => {
const updateDir = getUpdateDirectoryPath();
const asarUpdatePath = join(updateDir, 'app.asar.update');
await downloadFile(downloadUrls.asarUrl, asarUpdatePath, (progress) => {
const combinedProgress = {
percentage: combinedTotalSize > 0 ? Math.round(((totalDownloaded + progress.downloaded) / combinedTotalSize) * 100) : 0,
current: `${((totalDownloaded + progress.downloaded) / 1024 / 1024).toFixed(1)} MB`,
@@ -468,30 +460,17 @@ ipcMain.handle('download-update', async (event, downloadUrls: {asarUrl?: string,
});
if (currentDownloadAbortController.signal.aborted) throw new Error('下载已取消');
const asarUpdatePath = join(process.resourcesPath, 'app.asar.update');
await fs.copyFile(tempAsarPath, asarUpdatePath);
await fs.unlink(tempAsarPath);
downloadedAsarPath = asarUpdatePath;
totalDownloaded = asarSize;
}
if (downloadUrls.jarUrl && !currentDownloadAbortController.signal.aborted) {
let jarFileName = basename(downloadUrls.jarUrl);
if (!jarFileName.match(/^erp_client_sb-[\d.]+\.jar$/)) {
const currentJar = getJarFilePath();
const versionMatch = currentJar ? basename(currentJar).match(/erp_client_sb-([\d.]+)\.jar/) : null;
if (versionMatch && versionMatch[1]) {
const versionParts = versionMatch[1].split('.');
versionParts[2] = String(Number(versionParts[2]) + 1);
jarFileName = `erp_client_sb-${versionParts.join('.')}.jar`;
} else {
jarFileName = 'erp_client_sb-2.4.7.jar';
}
}
const tempJarPath = join(app.getPath('temp'), jarFileName);
await downloadFile(downloadUrls.jarUrl, tempJarPath, (progress) => {
const jarFileName = downloadUrls.latestVersion
? `erp_client_sb-${downloadUrls.latestVersion}.jar`
: basename(downloadUrls.jarUrl);
const updateDir = getUpdateDirectoryPath();
const jarUpdatePath = join(updateDir, jarFileName + '.update');
await downloadFile(downloadUrls.jarUrl, jarUpdatePath, (progress) => {
const combinedProgress = {
percentage: combinedTotalSize > 0 ? Math.round(((totalDownloaded + progress.downloaded) / combinedTotalSize) * 100) : 0,
current: `${((totalDownloaded + progress.downloaded) / 1024 / 1024).toFixed(1)} MB`,
@@ -504,10 +483,6 @@ ipcMain.handle('download-update', async (event, downloadUrls: {asarUrl?: string,
});
if (currentDownloadAbortController.signal.aborted) throw new Error('下载已取消');
const jarUpdatePath = join(process.resourcesPath, jarFileName + '.update');
await fs.copyFile(tempJarPath, jarUpdatePath);
await fs.unlink(tempJarPath);
downloadedJarPath = jarUpdatePath;
}
@@ -533,43 +508,28 @@ ipcMain.handle('get-download-progress', () => {
ipcMain.handle('install-update', async () => {
try {
const asarUpdatePath = join(process.resourcesPath, 'app.asar.update');
const hasAsarUpdate = existsSync(asarUpdatePath);
// 查找jar更新文件
let jarUpdatePath = '';
if (process.resourcesPath && existsSync(process.resourcesPath)) {
const files = readdirSync(process.resourcesPath);
const jarUpdateFile = files.find(f => f.startsWith('erp_client_sb-') && f.endsWith('.jar.update'));
if (jarUpdateFile) {
jarUpdatePath = join(process.resourcesPath, jarUpdateFile);
}
}
const updateDir = getUpdateDirectoryPath();
const asarUpdatePath = join(updateDir, 'app.asar.update');
const jarUpdateFile = readdirSync(updateDir).find(f => f.startsWith('erp_client_sb-') && f.endsWith('.jar.update'));
const jarUpdatePath = jarUpdateFile ? join(updateDir, jarUpdateFile) : '';
if (!hasAsarUpdate && !jarUpdatePath) {
if (!existsSync(asarUpdatePath) && !jarUpdatePath) {
return {success: false, error: '更新文件不存在'};
}
const appDir = dirname(process.execPath);
const helperPath = join(appDir, 'update-helper.bat');
if (!existsSync(helperPath)) {
return {success: false, error: '更新助手不存在'};
}
const appAsarPath = join(process.resourcesPath, 'app.asar');
const vbsPath = join(app.getPath('temp'), 'update-install.vbs');
const vbsContent = `Set WshShell = CreateObject("WScript.Shell")
WshShell.Run Chr(34) & "${helperPath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${appAsarPath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${asarUpdatePath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${jarUpdatePath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${process.execPath.replace(/\\/g, '\\\\')}" & Chr(34), 0, False`;
WshShell.Run Chr(34) & "${helperPath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${appAsarPath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${asarUpdatePath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${jarUpdatePath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${process.execPath.replace(/\\/g, '\\\\')}" & Chr(34) & " " & Chr(34) & "${updateDir.replace(/\\/g, '\\\\')}" & Chr(34), 0, False`;
writeFileSync(vbsPath, vbsContent);
spawn('wscript.exe', [vbsPath], {
detached: true,
stdio: 'ignore',
shell: false
});
spawn('wscript.exe', [vbsPath], {detached: true, stdio: 'ignore', shell: false});
setTimeout(() => {
downloadedFilePath = null;
@@ -608,31 +568,18 @@ ipcMain.handle('get-update-status', () => {
ipcMain.handle('check-pending-update', () => {
try {
const asarUpdatePath = join(process.resourcesPath, 'app.asar.update');
const hasAsarUpdate = existsSync(asarUpdatePath);
// 查找jar更新文件
let jarUpdatePath = '';
if (process.resourcesPath && existsSync(process.resourcesPath)) {
const files = readdirSync(process.resourcesPath);
const jarUpdateFile = files.find(f => f.startsWith('erp_client_sb-') && f.endsWith('.jar.update'));
if (jarUpdateFile) {
jarUpdatePath = join(process.resourcesPath, jarUpdateFile);
}
}
const updateDir = getUpdateDirectoryPath();
const asarUpdatePath = join(updateDir, 'app.asar.update');
const jarUpdateFile = readdirSync(updateDir).find(f => f.startsWith('erp_client_sb-') && f.endsWith('.jar.update'));
const jarUpdatePath = jarUpdateFile ? join(updateDir, jarUpdateFile) : '';
return {
hasPendingUpdate: hasAsarUpdate || !!jarUpdatePath,
asarUpdatePath: hasAsarUpdate ? asarUpdatePath : null,
hasPendingUpdate: existsSync(asarUpdatePath) || !!jarUpdatePath,
asarUpdatePath: existsSync(asarUpdatePath) ? asarUpdatePath : null,
jarUpdatePath: jarUpdatePath || null
};
} catch (error) {
console.error('检查待安装更新失败:', error);
return {
hasPendingUpdate: false,
asarUpdatePath: null,
jarUpdatePath: null
};
return {hasPendingUpdate: false, asarUpdatePath: null, jarUpdatePath: null};
}
});
@@ -655,24 +602,10 @@ ipcMain.handle('clear-update-files', async () => {
async function cleanupDownloadFiles() {
try {
const tempAsarPath = join(app.getPath('temp'), 'app.asar.new');
if (existsSync(tempAsarPath)) await fs.unlink(tempAsarPath).catch(() => {});
const asarUpdatePath = join(process.resourcesPath, 'app.asar.update');
if (existsSync(asarUpdatePath)) await fs.unlink(asarUpdatePath).catch(() => {});
if (process.resourcesPath && existsSync(process.resourcesPath)) {
const files = readdirSync(process.resourcesPath);
const jarUpdateFiles = files.filter(f => f.startsWith('erp_client_sb-') && f.endsWith('.jar.update'));
for (const file of jarUpdateFiles) {
await fs.unlink(join(process.resourcesPath, file)).catch(() => {});
}
const tempJarFiles = files.filter(f => f.startsWith('erp_client_sb-') && f.endsWith('.jar') && !f.includes('update'));
for (const file of tempJarFiles) {
const tempJarPath = join(app.getPath('temp'), file);
if (existsSync(tempJarPath)) await fs.unlink(tempJarPath).catch(() => {});
}
const updateDir = getUpdateDirectoryPath();
const files = readdirSync(updateDir);
for (const file of files) {
await fs.unlink(join(updateDir, file)).catch(() => {});
}
} catch (error) {}
}
@@ -696,34 +629,23 @@ ipcMain.handle('write-file', async (event, filePath: string, data: Uint8Array) =
// 获取日志日期列表
ipcMain.handle('get-log-dates', async () => {
try {
const logDir = 'C:/ProgramData/erp-logs';
if (!existsSync(logDir)) {
return { dates: [] };
}
const logDir = getLogDirectoryPath();
const files = await fs.readdir(logDir);
const dates: string[] = [];
// 获取今天的日期YYYY-MM-DD格式
const today = new Date().toISOString().split('T')[0];
files.forEach(file => {
if (file === 'spring-boot.log') {
// 当天的日志文件,使用今天的日期
dates.push(today);
} else if (file.startsWith('spring-boot-') && file.endsWith('.log')) {
// 历史日志文件,提取日期
const date = file.replace('spring-boot-', '').replace('.log', '');
dates.push(date);
}
});
// 排序,最新的在前面
dates.sort().reverse();
return { dates };
} catch (error) {
console.error('获取日志日期列表失败:', error);
return { dates: [] };
}
});
@@ -731,12 +653,10 @@ ipcMain.handle('get-log-dates', async () => {
// 读取指定日期的日志文件
ipcMain.handle('read-log-file', async (event, logDate: string) => {
try {
const logDir = 'C:/ProgramData/erp-logs';
const logDir = getLogDirectoryPath();
const today = new Date().toISOString().split('T')[0];
// 如果是今天的日期,读取 spring-boot.log否则读取带日期的文件
const fileName = logDate === today ? 'spring-boot.log' : `spring-boot-${logDate}.log`;
const logFilePath = `${logDir}/${fileName}`;
const logFilePath = join(logDir, fileName);
if (!existsSync(logFilePath)) {
return { success: false, error: '日志文件不存在' };
@@ -745,7 +665,6 @@ ipcMain.handle('read-log-file', async (event, logDate: string) => {
const content = await fs.readFile(logFilePath, 'utf-8');
return { success: true, content };
} catch (error) {
console.error('读取日志文件失败:', error);
return { success: false, error: error instanceof Error ? error.message : '读取失败' };
}
});