feat(devops): 实现流水线状态实时推送功能

- 新增 WebSocket 实时推送流水线状态功能
- 优化流水线数据获取方式,改为实时推送
- 重构 WebSocket 相关代码,提高稳定性和可维护性
- 新增前端 WebSocket 客户端,用于接收实时推送数据
- 修改前端流水线页面,支持实时数据更新
This commit is contained in:
2025-07-23 23:09:59 +08:00
parent 902173a9e9
commit e23711e340
16 changed files with 224 additions and 106 deletions
+12 -13
View File
@@ -1,25 +1,22 @@
import store from '@/store'
import Vue from 'vue'
/**
* WebSocket客户端
*/
export default function() {
const user = store.getters && store.getters.user
const webSocketApi = store.getters && store.getters.websocketApi
this.context = Vue.prototype
this.wsUri = webSocketApi.replace('{sid}', user.username)
function CsWsClient(sid) {
this.wsUri = store.getters && store.getters.websocketApi.replace('{sid}', sid)
this.client = null
/**
* 初始化WebSocket连接
* @param handleError -> function (e) { e是异常本身 }
* @param handleMessage -> function (e) { e.data是message }
*/
this.connect = function(handleError, handleMessage) {
this.wsClient = new WebSocket(this.wsUri)
this.client = new WebSocket(this.wsUri)
// 连接发生错误
this.wsClient.onerror = handleError
this.client.onerror = handleError
// 收到消息
this.wsClient.onmessage = handleMessage
this.client.onmessage = handleMessage
return this
}
/**
@@ -27,16 +24,18 @@ export default function() {
* @param data 客户端数据
*/
this.sendData = function(data) {
this.wsClient.send(JSON.stringify(data))
this.client.send(JSON.stringify(data))
}
/**
* 用于关闭ws连接
*/
this.close = function() {
console.log('关闭连接')
if (this.wsClient.readyState === 1) {
console.info('关闭连接')
if (this.client.readyState === 1) {
this.sendData([{}])
this.wsClient.close()
this.client.close()
}
}
}
export default CsWsClient