1
This commit is contained in:
@@ -201,7 +201,9 @@
|
||||
"Bash(cnpm install:*)",
|
||||
"Bash(cnpm uninstall:*)",
|
||||
"WebFetch(domain:www.electronjs.org)",
|
||||
"Bash(test:*)"
|
||||
"Bash(test:*)",
|
||||
"Bash(sqlite3:*)",
|
||||
"Bash(npx electron:*)"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": [],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {app, BrowserWindow, ipcMain, Menu, screen, dialog} from 'electron';
|
||||
import { existsSync, createWriteStream, promises as fs, statSync } from 'fs';
|
||||
import {existsSync, createWriteStream, promises as fs} from 'fs';
|
||||
import {join, dirname} from 'path';
|
||||
import {spawn, ChildProcessWithoutNullStreams} from 'child_process';
|
||||
import * as https from 'https';
|
||||
@@ -17,10 +17,19 @@ let downloadedFilePath: string | null = null;
|
||||
function openAppIfNotOpened() {
|
||||
if (appOpened) return;
|
||||
appOpened = true;
|
||||
|
||||
// SpringBoot 启动完成,现在加载前端页面
|
||||
if (mainWindow) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
const rendererPort = process.argv[2] || 8083;
|
||||
mainWindow.loadURL(`http://localhost:${rendererPort}`);
|
||||
} else {
|
||||
mainWindow.loadFile(join(__dirname, '../renderer/index.html'));
|
||||
}
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
}
|
||||
|
||||
if (splashWindow) {
|
||||
splashWindow.close();
|
||||
splashWindow = null;
|
||||
@@ -28,36 +37,24 @@ function openAppIfNotOpened() {
|
||||
}
|
||||
|
||||
function startSpringBoot() {
|
||||
const jarPath = 'C:/Users/ZiJIe/Desktop/wox/RuoYi-Vue/ruoyi-admin/target/ruoyi-admin.jar';
|
||||
|
||||
const jarPath = join(__dirname, '../../public/erp_client_sb-2.4.7.jar');
|
||||
springProcess = spawn('java', ['-jar', jarPath], {
|
||||
cwd: dirname(jarPath),
|
||||
detached: false
|
||||
});
|
||||
|
||||
springProcess.stdout.on('data', (data) => {
|
||||
console.log(`SpringBoot: ${data}`);
|
||||
if (data.toString().includes('Started RuoYiApplication')) {
|
||||
if (data.toString().includes('Started Success')) {
|
||||
openAppIfNotOpened();
|
||||
}
|
||||
});
|
||||
|
||||
springProcess.stderr.on('data', (data) => {
|
||||
console.error(`SpringBoot ERROR: ${data}`);
|
||||
const errorStr = data.toString();
|
||||
if (errorStr.includes('APPLICATION FAILED TO START') ||
|
||||
errorStr.includes('Port') && errorStr.includes('already in use') ||
|
||||
errorStr.includes('Unable to start embedded Tomcat')) {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
springProcess.on('close', (code) => {
|
||||
console.log(`SpringBoot exited with code ${code}`);
|
||||
mainWindow ? mainWindow.close() : app.quit();
|
||||
});
|
||||
}
|
||||
|
||||
startSpringBoot();
|
||||
|
||||
function stopSpringBoot() {
|
||||
if (!springProcess) return;
|
||||
try {
|
||||
@@ -128,7 +125,6 @@ app.whenReady().then(() => {
|
||||
splashWindow.loadFile(splashPath);
|
||||
}
|
||||
|
||||
setTimeout(() => openAppIfNotOpened(), 1000);
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
@@ -251,7 +247,8 @@ ipcMain.handle('download-update', async (event, downloadUrl: string) => {
|
||||
|
||||
const tempPath = join(app.getPath('temp'), 'app.asar.new');
|
||||
if (existsSync(tempPath)) {
|
||||
fs.unlink(tempPath).catch(() => {});
|
||||
fs.unlink(tempPath).catch(() => {
|
||||
});
|
||||
}
|
||||
|
||||
return {success: false, error: error instanceof Error ? error.message : '下载失败'};
|
||||
@@ -388,7 +385,8 @@ async function downloadFile(url: string, filePath: string, onProgress: (progress
|
||||
});
|
||||
|
||||
fileStream.on('error', (error) => {
|
||||
fs.unlink(filePath).catch(() => {});
|
||||
fs.unlink(filePath).catch(() => {
|
||||
});
|
||||
reject(error);
|
||||
});
|
||||
|
||||
|
||||
@@ -2,12 +2,9 @@
|
||||
import {onMounted, ref, computed, defineAsyncComponent, type Component, onUnmounted} from 'vue'
|
||||
import {ElMessage, ElMessageBox} from 'element-plus'
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||
// 图标已移至对应组件
|
||||
import 'element-plus/dist/index.css'
|
||||
import {authApi} from './api/auth'
|
||||
import {deviceApi, type DeviceItem, type DeviceQuota} from './api/device'
|
||||
// 面板按需加载,互不影响且可缓存
|
||||
|
||||
const LoginDialog = defineAsyncComponent(() => import('./components/auth/LoginDialog.vue'))
|
||||
const RegisterDialog = defineAsyncComponent(() => import('./components/auth/RegisterDialog.vue'))
|
||||
const NavigationBar = defineAsyncComponent(() => import('./components/layout/NavigationBar.vue'))
|
||||
@@ -147,9 +144,15 @@ async function handleLoginSuccess(data: { token: string; permissions?: string })
|
||||
|
||||
// 建立SSE连接
|
||||
SSEManager.connect()
|
||||
} catch (e) {
|
||||
// 设备注册失败不影响登录流程,静默处理
|
||||
console.warn('设备注册失败:', e)
|
||||
} catch (e: any) {
|
||||
// 设备注册失败时回滚登录状态
|
||||
isAuthenticated.value = false
|
||||
showAuthDialog.value = true
|
||||
await authApi.deleteTokenCache()
|
||||
ElMessage({
|
||||
message: e?.message || '设备注册失败,请重试',
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,37 +15,37 @@ export interface DeviceItem {
|
||||
lastActiveAt?: string
|
||||
}
|
||||
|
||||
// 统一处理AjaxResult格式
|
||||
function handleAjaxResult(res: any) {
|
||||
if (res?.code !== 200) {
|
||||
throw new Error(res?.msg || '操作失败')
|
||||
}
|
||||
return res.data
|
||||
}
|
||||
|
||||
export const deviceApi = {
|
||||
getQuota(username: string) {
|
||||
return http.get<DeviceQuota | any>(`${base}/quota`, { username }).then((res: any) => {
|
||||
if (res && typeof res.limit !== 'undefined') return res as DeviceQuota
|
||||
if (res && typeof res.code === 'number') return (res.data as DeviceQuota) || { limit: 0, used: 0 }
|
||||
return (res?.data as DeviceQuota) || { limit: 0, used: 0 }
|
||||
})
|
||||
getQuota(username: string): Promise<DeviceQuota> {
|
||||
return http.get(`${base}/quota`, { username }).then(handleAjaxResult)
|
||||
},
|
||||
|
||||
list(username: string) {
|
||||
return http.get<DeviceItem[] | any>(`${base}/list`, { username }).then((res: any) => {
|
||||
if (Array.isArray(res)) return res as DeviceItem[]
|
||||
if (res && typeof res.code === 'number') return (res.data as DeviceItem[]) || []
|
||||
return (res?.data as DeviceItem[]) || []
|
||||
})
|
||||
list(username: string): Promise<DeviceItem[]> {
|
||||
return http.get(`${base}/list`, { username }).then(handleAjaxResult)
|
||||
},
|
||||
|
||||
register(payload: { username: string }) {
|
||||
return http.post(`${base}/register`, payload)
|
||||
return http.post(`${base}/register`, payload).then(handleAjaxResult)
|
||||
},
|
||||
|
||||
remove(payload: { deviceId: string }) {
|
||||
return http.postVoid(`${base}/remove`, payload)
|
||||
return http.post(`${base}/remove`, payload).then(handleAjaxResult)
|
||||
},
|
||||
|
||||
heartbeat(payload: { username: string; deviceId: string; version?: string }) {
|
||||
return http.postVoid(`${base}/heartbeat`, payload)
|
||||
return http.post(`${base}/heartbeat`, payload).then(handleAjaxResult)
|
||||
},
|
||||
|
||||
offline(payload: { deviceId: string }) {
|
||||
return http.postVoid(`${base}/offline`, payload)
|
||||
return http.post(`${base}/offline`, payload).then(handleAjaxResult)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ref, computed } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { User } from '@element-plus/icons-vue'
|
||||
import { authApi } from '../../api/auth'
|
||||
import { deviceApi } from '../../api/device'
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
@@ -30,6 +31,10 @@ async function handleAuth() {
|
||||
|
||||
authLoading.value = true
|
||||
try {
|
||||
// 1. 先检查设备限制
|
||||
await deviceApi.register({ username: authForm.value.username })
|
||||
|
||||
// 2. 设备检查通过,进行登录
|
||||
const data = await authApi.login(authForm.value)
|
||||
emit('loginSuccess', {
|
||||
token: data.token,
|
||||
|
||||
@@ -4,7 +4,6 @@ import 'element-plus/dist/index.css'
|
||||
import ElementPlus from 'element-plus'
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||
import App from './App.vue'
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(ElementPlus, {
|
||||
locale: zhCn,
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
public class ErpClientSbApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 纯 Spring Boot 启动,不再依赖 JavaFX
|
||||
ConfigurableApplicationContext applicationContext = SpringApplication.run(ErpClientSbApplication.class, args);
|
||||
try {
|
||||
ErrorReporter errorReporter = applicationContext.getBean(ErrorReporter.class);
|
||||
@@ -20,12 +19,11 @@ public class ErpClientSbApplication {
|
||||
log.error("捕获到未处理异常: " + ex.getMessage(), ex);
|
||||
errorReporter.reportSystemError("未捕获异常: " + thread.getName(), (Exception) ex);
|
||||
});
|
||||
log.info("全局异常处理器已设置");
|
||||
log.info("Started Success");
|
||||
} catch (Exception e) {
|
||||
log.warn("未设置 ErrorReporter,继续启动: {}", e.getMessage());
|
||||
}
|
||||
|
||||
// 如需预加载资源,可按需保留
|
||||
try {
|
||||
ResourcePreloader.init();
|
||||
ResourcePreloader.preloadErpDashboard();
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.tashow.erp.controller;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import com.tashow.erp.utils.ApiForwarder;
|
||||
import com.tashow.erp.utils.DeviceUtils;
|
||||
import java.util.Map;
|
||||
@@ -16,12 +14,6 @@ import java.util.HashMap;
|
||||
@RestController
|
||||
public class DeviceProxyController {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@Value("${api.server.base-url}")
|
||||
private String serverBaseUrl;
|
||||
|
||||
/**
|
||||
* 注册设备
|
||||
*/
|
||||
@@ -34,9 +26,6 @@ public class DeviceProxyController {
|
||||
deviceData.put("deviceId", DeviceUtils.generateDeviceId());
|
||||
return apiForwarder.post("/monitor/device/register", deviceData, auth);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/api/device/remove")
|
||||
public ResponseEntity<?> deviceRemove(@RequestBody Map<String, Object> body, @RequestHeader(value = "Authorization", required = false) String auth) {
|
||||
return apiForwarder.post("/monitor/device/remove", body, auth);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.ruoyi;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user