Merge branch 'master' of http://192.168.1.22:3000/ClientApps/pqs-9100_client
This commit is contained in:
@@ -20,8 +20,8 @@ VITE_API_URL=/api
|
||||
# 开发环境跨域代理,支持配置多个
|
||||
|
||||
#VITE_PROXY=[["/api","http://127.0.0.1:18092/"]]
|
||||
VITE_PROXY=[["/api","http://192.168.1.124:18092/"]]
|
||||
#VITE_PROXY=[["/api","http://192.168.1.125:18092/"]]
|
||||
#VITE_PROXY=[["/api","http://192.168.1.124:18092/"]]
|
||||
VITE_PROXY=[["/api","http://192.168.1.125:18092/"]]
|
||||
# VITE_PROXY=[["/api","http://192.168.1.138:8080/"]]张文
|
||||
# 开启激活验证
|
||||
VITE_ACTIVATE_OPEN=false
|
||||
VITE_ACTIVATE_OPEN=true
|
||||
@@ -25,4 +25,4 @@ VITE_PWA=true
|
||||
#VITE_API_URL="/api" # 打包时用
|
||||
VITE_API_URL="http://127.0.0.1:18092/"
|
||||
# 开启激活验证
|
||||
VITE_ACTIVATE_OPEN=false
|
||||
VITE_ACTIVATE_OPEN=true
|
||||
@@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<!--element-plus语言国际化,全局修改为中文-->
|
||||
<!-- 测试升级功能 - 2025-10-24 -->
|
||||
<el-config-provider :locale="locale" :size="assemblySize" :button="buttonConfig">
|
||||
<router-view />
|
||||
</el-config-provider>
|
||||
|
||||
@@ -82,8 +82,8 @@ export const reCalculate = (params: {
|
||||
errorSysId: string
|
||||
deviceId: string
|
||||
code: string
|
||||
patternId: string
|
||||
|
||||
patternId: string,
|
||||
chnNum: string
|
||||
}) => {
|
||||
return http.post('/result/reCalculate', params, {loading: true})
|
||||
}
|
||||
@@ -129,7 +129,8 @@ export const changeErrorSystem = (params: {
|
||||
errorSysId: string
|
||||
deviceId: string
|
||||
code: string
|
||||
patternId: string
|
||||
patternId: string,
|
||||
chnNum: string
|
||||
}) => {
|
||||
return http.post('/result/changeErrorSystem', params, {loading: true})
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ export interface CustomAxiosRequestConfig extends InternalAxiosRequestConfig {
|
||||
}
|
||||
|
||||
const config = {
|
||||
// 默认地址请求地址,可在 .env.** 文件中修改
|
||||
// 默认地址请求地址,可在 .env 开头文件中修改
|
||||
baseURL: import.meta.env.VITE_API_URL as string,
|
||||
// 设置超时时间
|
||||
timeout: ResultEnum.TIMEOUT as number,
|
||||
// 设置超时时间(60s)
|
||||
timeout: 60000,
|
||||
// 跨域时候允许携带凭证
|
||||
withCredentials: true,
|
||||
// post请求指定数据类型以及编码
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* WebSocket客户端服务
|
||||
* 提供WebSocket连接管理、心跳机制、消息处理等功能
|
||||
* 集成JWT token解析,支持自动获取用户登录名
|
||||
*
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 2.0
|
||||
*/
|
||||
@@ -66,7 +66,7 @@ namespace WebSocketMessageTypes {
|
||||
progress?: number;
|
||||
errorInfo?: string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 系数校准相关消息
|
||||
*/
|
||||
@@ -77,7 +77,7 @@ namespace WebSocketMessageTypes {
|
||||
current?: string;
|
||||
calibrationResult?: boolean;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 正式检测相关消息
|
||||
*/
|
||||
@@ -87,7 +87,7 @@ namespace WebSocketMessageTypes {
|
||||
testResult?: 'success' | 'failed' | 'processing';
|
||||
testData?: any;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通用响应消息
|
||||
*/
|
||||
@@ -102,14 +102,14 @@ namespace WebSocketMessageTypes {
|
||||
// 导出类型
|
||||
// ============================================================================
|
||||
|
||||
export type {
|
||||
WebSocketMessage,
|
||||
CallbackFunction,
|
||||
SocketConfig,
|
||||
export type {
|
||||
WebSocketMessage,
|
||||
CallbackFunction,
|
||||
SocketConfig,
|
||||
WebSocketMessageTypes
|
||||
};
|
||||
|
||||
export {
|
||||
export {
|
||||
ConnectionStatus
|
||||
};
|
||||
|
||||
@@ -130,7 +130,7 @@ export default class SocketService {
|
||||
* 单例实例
|
||||
*/
|
||||
private static instance: SocketService | null = null;
|
||||
|
||||
|
||||
/**
|
||||
* 获取单例实例
|
||||
* @returns SocketService实例
|
||||
@@ -150,42 +150,42 @@ export default class SocketService {
|
||||
* WebSocket连接实例
|
||||
*/
|
||||
private ws: WebSocket | null = null;
|
||||
|
||||
|
||||
/**
|
||||
* 消息回调函数映射表
|
||||
*/
|
||||
private callBackMapping: Record<string, CallbackFunction<any>> = {};
|
||||
|
||||
|
||||
/**
|
||||
* 当前连接状态
|
||||
*/
|
||||
private connectionStatus: ConnectionStatus = ConnectionStatus.DISCONNECTED;
|
||||
|
||||
|
||||
/**
|
||||
* 发送消息重试计数器
|
||||
*/
|
||||
private sendRetryCount: number = 0;
|
||||
|
||||
|
||||
/**
|
||||
* 连接重试计数器
|
||||
*/
|
||||
private connectRetryCount: number = 0;
|
||||
|
||||
|
||||
/**
|
||||
* 心跳Worker实例
|
||||
*/
|
||||
private heartbeatWorker: Worker | null = null;
|
||||
|
||||
|
||||
/**
|
||||
* Worker脚本的Blob URL
|
||||
*/
|
||||
private workerBlobUrl: string | null = null;
|
||||
|
||||
|
||||
/**
|
||||
* 最后一次收到心跳响应的时间戳
|
||||
*/
|
||||
private lastResponseHeartTime: number = Date.now();
|
||||
|
||||
|
||||
/**
|
||||
* WebSocket连接配置
|
||||
*/
|
||||
@@ -246,18 +246,18 @@ export default class SocketService {
|
||||
public connect(): Promise<void> | void {
|
||||
// 检查浏览器支持
|
||||
if (!window.WebSocket) {
|
||||
// console.log('您的浏览器不支持WebSocket');
|
||||
// console.log('您的浏览器不支持WebSocket');
|
||||
return;
|
||||
}
|
||||
|
||||
// 防止重复连接
|
||||
if (this.connectionStatus === ConnectionStatus.CONNECTING || this.connected) {
|
||||
// console.warn('WebSocket已连接或正在连接中');
|
||||
// console.warn('WebSocket已连接或正在连接中');
|
||||
return;
|
||||
}
|
||||
|
||||
this.connectionStatus = ConnectionStatus.CONNECTING;
|
||||
|
||||
|
||||
try {
|
||||
this.ws = new WebSocket(this.buildWebSocketUrl());
|
||||
this.setupEventHandlersLegacy();
|
||||
@@ -289,7 +289,7 @@ export default class SocketService {
|
||||
}
|
||||
|
||||
this.connectionStatus = ConnectionStatus.CONNECTING;
|
||||
|
||||
|
||||
try {
|
||||
this.ws = new WebSocket(this.buildWebSocketUrl());
|
||||
this.setupEventHandlers(resolve, reject);
|
||||
@@ -311,7 +311,7 @@ export default class SocketService {
|
||||
return;
|
||||
}
|
||||
this.callBackMapping[messageType] = callback;
|
||||
// console.log(`注册消息处理器: ${messageType}`);
|
||||
// console.log(`注册消息处理器: ${messageType}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -349,11 +349,11 @@ export default class SocketService {
|
||||
try {
|
||||
// 重置重试计数
|
||||
this.sendRetryCount = 0;
|
||||
|
||||
|
||||
// 尝试发送JSON数据,失败则发送原始数据
|
||||
const message = typeof data === 'string' ? data : JSON.stringify(data);
|
||||
this.ws.send(message);
|
||||
|
||||
|
||||
//console.log('发送消息:', message);
|
||||
resolve();
|
||||
} catch (error) {
|
||||
@@ -368,21 +368,21 @@ export default class SocketService {
|
||||
*/
|
||||
public closeWs(): void {
|
||||
//console.log('正在关闭WebSocket连接...');
|
||||
|
||||
|
||||
// 清理心跳
|
||||
this.clearHeartbeat();
|
||||
|
||||
|
||||
// 关闭连接
|
||||
if (this.ws) {
|
||||
this.ws.close(1000, '主动关闭连接');
|
||||
this.ws = null;
|
||||
}
|
||||
|
||||
|
||||
// 更新状态
|
||||
this.connectionStatus = ConnectionStatus.DISCONNECTED;
|
||||
this.connectRetryCount = 0;
|
||||
this.sendRetryCount = 0;
|
||||
|
||||
|
||||
//console.log('WebSocket连接已关闭');
|
||||
}
|
||||
|
||||
@@ -422,15 +422,15 @@ export default class SocketService {
|
||||
*/
|
||||
private buildWebSocketUrl(): string {
|
||||
const { url } = this.config;
|
||||
|
||||
|
||||
// 直接从JWT token中获取loginName作为name参数
|
||||
const loginName = jwtUtil.getLoginName();
|
||||
|
||||
|
||||
if (loginName) {
|
||||
const separator = url.includes('?') ? '&' : '?';
|
||||
return `${url}${separator}name=${encodeURIComponent(loginName)}`;
|
||||
}
|
||||
|
||||
|
||||
// 如果无法获取loginName,返回原始URL并输出警告
|
||||
console.warn('无法从JWT token中获取loginName,WebSocket连接可能会失败');
|
||||
return url;
|
||||
@@ -443,11 +443,11 @@ export default class SocketService {
|
||||
*/
|
||||
private setupEventHandlers(resolve: () => void, reject: (error: Error) => void): void {
|
||||
if (!this.ws) return;
|
||||
|
||||
|
||||
// 连接成功事件
|
||||
this.ws.onopen = () => {
|
||||
ElMessage.success("WebSocket连接服务端成功");
|
||||
// console.log('WebSocket连接成功');
|
||||
// console.log('WebSocket连接成功');
|
||||
this.connectionStatus = ConnectionStatus.CONNECTED;
|
||||
this.connectRetryCount = 0;
|
||||
this.startHeartbeat();
|
||||
@@ -459,7 +459,7 @@ export default class SocketService {
|
||||
//console.log('WebSocket连接关闭', event.code, event.reason);
|
||||
this.connectionStatus = ConnectionStatus.DISCONNECTED;
|
||||
this.clearHeartbeat();
|
||||
|
||||
|
||||
// 非正常关闭且未超过最大重连次数,尝试重连
|
||||
if (event.code !== 1000 && this.connectRetryCount < this.config.maxReconnectAttempts!) {
|
||||
this.attemptReconnect();
|
||||
@@ -485,11 +485,11 @@ export default class SocketService {
|
||||
*/
|
||||
private setupEventHandlersLegacy(): void {
|
||||
if (!this.ws) return;
|
||||
|
||||
|
||||
// 连接成功事件
|
||||
this.ws.onopen = () => {
|
||||
ElMessage.success("webSocket连接服务端成功了");
|
||||
// console.log('连接服务端成功了');
|
||||
// console.log('连接服务端成功了');
|
||||
this.connectionStatus = ConnectionStatus.CONNECTED;
|
||||
this.connectRetryCount = 0;
|
||||
this.startHeartbeat();
|
||||
@@ -497,10 +497,10 @@ export default class SocketService {
|
||||
|
||||
// 连接关闭事件
|
||||
this.ws.onclose = (event: CloseEvent) => {
|
||||
// console.log('连接webSocket服务端关闭');
|
||||
// console.log('连接webSocket服务端关闭');
|
||||
this.connectionStatus = ConnectionStatus.DISCONNECTED;
|
||||
this.clearHeartbeat();
|
||||
|
||||
|
||||
// 保持原有的重连逻辑(被注释掉的)
|
||||
// this.connectRetryCount++;
|
||||
/* setTimeout(() => {
|
||||
@@ -527,10 +527,10 @@ export default class SocketService {
|
||||
*/
|
||||
private handleMessage(event: MessageEvent): void {
|
||||
// console.log('Received message:', event.data);
|
||||
|
||||
|
||||
// 心跳响应处理
|
||||
if (event.data === 'over') {
|
||||
// console.log(`${new Date().toLocaleTimeString()} - 收到心跳响应`);
|
||||
// console.log(`${new Date().toLocaleTimeString()} - 收到心跳响应`);
|
||||
this.lastResponseHeartTime = Date.now();
|
||||
return;
|
||||
}
|
||||
@@ -553,16 +553,16 @@ export default class SocketService {
|
||||
}
|
||||
} else {
|
||||
// 非JSON格式的消息,作为普通文本处理
|
||||
// console.log('收到非JSON格式消息:', event.data);
|
||||
// console.log('收到非JSON格式消息:', event.data);
|
||||
// 可以添加文本消息的处理逻辑
|
||||
if (this.callBackMapping['text']) {
|
||||
this.callBackMapping['text']({
|
||||
type: 'text',
|
||||
data: event.data
|
||||
this.callBackMapping['text']({
|
||||
type: 'text',
|
||||
data: event.data
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error('消息解析失败:', event.data, error);
|
||||
console.error('消息类型:', typeof event.data);
|
||||
@@ -584,11 +584,11 @@ export default class SocketService {
|
||||
|
||||
this.connectionStatus = ConnectionStatus.RECONNECTING;
|
||||
this.connectRetryCount++;
|
||||
|
||||
|
||||
const delay = this.config.reconnectDelay! * this.connectRetryCount;
|
||||
|
||||
// console.log(`尝试第${this.connectRetryCount}次重连,${delay}ms后开始...`);
|
||||
|
||||
|
||||
// console.log(`尝试第${this.connectRetryCount}次重连,${delay}ms后开始...`);
|
||||
|
||||
setTimeout(() => {
|
||||
try {
|
||||
const result = this.connect();
|
||||
@@ -627,24 +627,24 @@ export default class SocketService {
|
||||
postMessage('heartbeat');
|
||||
}, ${this.config.heartbeatInterval});
|
||||
`;
|
||||
|
||||
|
||||
this.workerBlobUrl = window.URL.createObjectURL(
|
||||
new Blob([workerScript], { type: 'application/javascript' })
|
||||
);
|
||||
|
||||
|
||||
this.heartbeatWorker = new Worker(this.workerBlobUrl);
|
||||
|
||||
|
||||
// 心跳Worker消息处理
|
||||
this.heartbeatWorker.onmessage = (event: MessageEvent) => {
|
||||
this.handleHeartbeatTick();
|
||||
};
|
||||
|
||||
|
||||
// Worker错误处理
|
||||
this.heartbeatWorker.onerror = (error: ErrorEvent) => {
|
||||
console.error('心跳Worker错误:', error);
|
||||
this.clearHeartbeat();
|
||||
};
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error('创建心跳Worker失败:', error);
|
||||
}
|
||||
@@ -657,7 +657,7 @@ export default class SocketService {
|
||||
private handleHeartbeatTick(): void {
|
||||
// 检查是否超时(距离上次收到心跳响应的时间)
|
||||
const timeSinceLastResponse = Date.now() - this.lastResponseHeartTime;
|
||||
|
||||
|
||||
if (timeSinceLastResponse > this.config.timeout!) {
|
||||
console.error(`WebSocket心跳超时: ${timeSinceLastResponse}ms > ${this.config.timeout}ms`);
|
||||
ElMessage.error("WebSocket连接超时,请检查网络连接!");
|
||||
@@ -665,7 +665,7 @@ export default class SocketService {
|
||||
this.closeWs();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.sendHeartbeat();
|
||||
}
|
||||
|
||||
@@ -674,7 +674,7 @@ export default class SocketService {
|
||||
*/
|
||||
private sendHeartbeat(): void {
|
||||
if (this.connected && this.ws) {
|
||||
// console.log(`${new Date().toLocaleTimeString()} - 发送心跳消息`);
|
||||
// console.log(`${new Date().toLocaleTimeString()} - 发送心跳消息`);
|
||||
this.ws.send('alive');
|
||||
}
|
||||
}
|
||||
@@ -688,7 +688,7 @@ export default class SocketService {
|
||||
this.heartbeatWorker.terminate();
|
||||
this.heartbeatWorker = null;
|
||||
}
|
||||
|
||||
|
||||
if (this.workerBlobUrl) {
|
||||
window.URL.revokeObjectURL(this.workerBlobUrl);
|
||||
this.workerBlobUrl = null;
|
||||
|
||||
@@ -563,7 +563,8 @@ const handleErrorSysChange = async () => {
|
||||
errorSysId: formContent.errorSysId,
|
||||
deviceId: formContent.deviceId,
|
||||
code: checkStore.plan.code + '',
|
||||
patternId: dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id ?? ''
|
||||
patternId: dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id ?? '',
|
||||
chnNum: formContent.chnNum
|
||||
}).then(res => {
|
||||
if (res.code === ResultEnum.SUCCESS) {
|
||||
ElMessage.success('切换误差体系成功')
|
||||
@@ -579,7 +580,8 @@ const handleReCalculate = async () => {
|
||||
errorSysId: formContent.errorSysId,
|
||||
deviceId: formContent.deviceId,
|
||||
code: checkStore.plan.code + '',
|
||||
patternId: dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id ?? ''
|
||||
patternId: dictStore.getDictData('Pattern').find(item => item.name === modeStore.currentMode)?.id ?? '',
|
||||
chnNum: formContent.chnNum
|
||||
}).then(res => {
|
||||
if (res.code === ResultEnum.SUCCESS) {
|
||||
ElMessage.success('重新计算成功!')
|
||||
|
||||
@@ -18,13 +18,15 @@
|
||||
<img :src="item.img" />
|
||||
</div>
|
||||
<div class="test_button">
|
||||
<el-button size="large" type="primary" @click="handelOpen(item)" :disabled="!item.activated">
|
||||
进入检测
|
||||
<el-button size="large" type="primary" @click="handelOpen(item)">
|
||||
{{ item.activated ? '进入检测' : '待激活' }}
|
||||
</el-button>
|
||||
</div>
|
||||
</el-carousel-item>
|
||||
</el-carousel>
|
||||
</div>
|
||||
<!-- versionRegisterDialog -->
|
||||
<VersionDialog ref="versionRegisterRef"></VersionDialog>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { useAuthStore } from '@/stores/modules/auth'
|
||||
@@ -32,6 +34,8 @@ import { useAppSceneStore, useModeStore } from '@/stores/modules/mode' // 引入
|
||||
import { getCurrentScene } from '@/api/user/login'
|
||||
import { initDynamicRouter } from '@/routers/modules/dynamicRouter'
|
||||
import { useTabsStore } from '@/stores/modules/tabs'
|
||||
import VersionDialog from '@/views/system/versionRegister/index.vue'
|
||||
import { ref, onMounted } from 'vue'
|
||||
|
||||
const authStore = useAuthStore()
|
||||
const modeStore = useModeStore() // 使用模式 store
|
||||
@@ -39,6 +43,7 @@ const AppSceneStore = useAppSceneStore()
|
||||
const activateInfo = authStore.activateInfo
|
||||
const isActivateOpen = import.meta.env.VITE_ACTIVATE_OPEN
|
||||
const tabsStore = useTabsStore()
|
||||
const versionRegisterRef = ref<InstanceType<typeof VersionDialog> | null>(null)
|
||||
const modeList = [
|
||||
{
|
||||
name: '模拟式模块',
|
||||
@@ -64,7 +69,8 @@ const modeList = [
|
||||
]
|
||||
const handelOpen = async (item: any) => {
|
||||
if (!item.activated) {
|
||||
ElMessage.warning(`${item.name}未激活`)
|
||||
// 打开版本激活弹窗
|
||||
versionRegisterRef.value?.openDialog()
|
||||
return
|
||||
}
|
||||
modeStore.setCurrentMode(item.code) // 将模式code存入 store
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="checked">
|
||||
<el-form-item prop="checked" v-show="false">
|
||||
<el-checkbox v-model="loginForm.checked">记住我</el-checkbox>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
Reference in New Issue
Block a user