二级修改
This commit is contained in:
@@ -11,4 +11,4 @@ ENV = 'staging'
|
||||
# 若依管理系统/测试环境
|
||||
VUE_APP_BASE_API = '/stage-api'
|
||||
|
||||
VUE_APP_SERVICE_BASE_API = 'http://140.143.206.120:8081'
|
||||
VUE_APP_SERVICE_BASE_API = 'http://140.143.206.120:18081'
|
||||
|
||||
@@ -58,3 +58,15 @@ export function getTrackMatPosition() {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取生产计划队列
|
||||
* 使用现有的计划列表接口
|
||||
*/
|
||||
export function getPlanQueue(data = {}) {
|
||||
return l2Request({
|
||||
method: 'post',
|
||||
url: '/api/pdi/list',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
137
apps/l2/src/utils/websocketManager.js
Normal file
137
apps/l2/src/utils/websocketManager.js
Normal file
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* WebSocket 管理器
|
||||
* 用于管理多个 WebSocket 连接
|
||||
*/
|
||||
|
||||
class WebSocketManager {
|
||||
constructor() {
|
||||
this.connections = new Map()
|
||||
this.baseUrl = 'ws://140.143.206.120:18081/websocket'
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 WebSocket 连接
|
||||
* @param {String} type - WebSocket 类型 (track_measure, track_position, track_signal, track_matmap, calc_setup_result)
|
||||
* @param {Function} onMessage - 接收消息的回调函数
|
||||
* @param {Function} onOpen - 连接打开的回调函数
|
||||
* @param {Function} onError - 错误回调函数
|
||||
* @param {Function} onClose - 关闭回调函数
|
||||
*/
|
||||
connect(type, { onMessage, onOpen, onError, onClose } = {}) {
|
||||
// 如果已存在连接,先断开
|
||||
if (this.connections.has(type)) {
|
||||
this.disconnect(type)
|
||||
}
|
||||
|
||||
const url = `${this.baseUrl}?type=${type}`
|
||||
console.log(`[WebSocket] 正在连接: ${type}`)
|
||||
|
||||
try {
|
||||
const socket = new WebSocket(url)
|
||||
|
||||
socket.onopen = (event) => {
|
||||
console.log(`[WebSocket] 连接成功: ${type}`)
|
||||
if (onOpen) onOpen(event)
|
||||
}
|
||||
|
||||
socket.onmessage = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data)
|
||||
if (onMessage) onMessage(data)
|
||||
} catch (error) {
|
||||
console.error(`[WebSocket] 数据解析失败 (${type}):`, error)
|
||||
// 如果不是 JSON,直接传递原始数据
|
||||
if (onMessage) onMessage(event.data)
|
||||
}
|
||||
}
|
||||
|
||||
socket.onerror = (error) => {
|
||||
console.error(`[WebSocket] 连接错误 (${type}):`, error)
|
||||
if (onError) onError(error)
|
||||
}
|
||||
|
||||
socket.onclose = (event) => {
|
||||
console.log(`[WebSocket] 连接关闭 (${type}):`, event.code, event.reason)
|
||||
this.connections.delete(type)
|
||||
|
||||
if (onClose) {
|
||||
onClose(event)
|
||||
} else if (event.code !== 1000) {
|
||||
// 非正常关闭,3秒后自动重连
|
||||
console.log(`[WebSocket] 3秒后尝试重连: ${type}`)
|
||||
setTimeout(() => {
|
||||
this.connect(type, { onMessage, onOpen, onError, onClose })
|
||||
}, 3000)
|
||||
}
|
||||
}
|
||||
|
||||
this.connections.set(type, socket)
|
||||
return socket
|
||||
} catch (error) {
|
||||
console.error(`[WebSocket] 创建连接失败 (${type}):`, error)
|
||||
// 失败后3秒重试
|
||||
setTimeout(() => {
|
||||
this.connect(type, { onMessage, onOpen, onError, onClose })
|
||||
}, 3000)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 断开指定类型的连接
|
||||
*/
|
||||
disconnect(type) {
|
||||
const socket = this.connections.get(type)
|
||||
if (socket) {
|
||||
console.log(`[WebSocket] 主动断开: ${type}`)
|
||||
socket.close(1000, '主动关闭')
|
||||
this.connections.delete(type)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 断开所有连接
|
||||
*/
|
||||
disconnectAll() {
|
||||
console.log('[WebSocket] 断开所有连接')
|
||||
this.connections.forEach((socket, type) => {
|
||||
this.disconnect(type)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定类型的连接状态
|
||||
*/
|
||||
isConnected(type) {
|
||||
const socket = this.connections.get(type)
|
||||
return socket && socket.readyState === WebSocket.OPEN
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有连接状态
|
||||
*/
|
||||
getAllStatus() {
|
||||
const status = {}
|
||||
this.connections.forEach((socket, type) => {
|
||||
status[type] = socket.readyState === WebSocket.OPEN
|
||||
})
|
||||
return status
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息(如果需要)
|
||||
*/
|
||||
send(type, message) {
|
||||
const socket = this.connections.get(type)
|
||||
if (socket && socket.readyState === WebSocket.OPEN) {
|
||||
const data = typeof message === 'string' ? message : JSON.stringify(message)
|
||||
socket.send(data)
|
||||
return true
|
||||
}
|
||||
console.warn(`[WebSocket] 无法发送消息,连接未打开: ${type}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 导出单例
|
||||
export default new WebSocketManager()
|
||||
|
||||
@@ -469,7 +469,7 @@ export default {
|
||||
seqid: null,
|
||||
coilid: "",
|
||||
unitCode: "",
|
||||
status: 0,
|
||||
status: "NEW", // 新增计划默认状态为 NEW
|
||||
planid: "",
|
||||
planType: "",
|
||||
originCoilid: "",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user