From e1699c4851f6ca397cd0ad1ff63f32c737654836 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Wed, 02 Apr 2025 19:14:54 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/utils/websocket/drone-ws-control.js |  118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 118 insertions(+), 0 deletions(-)

diff --git a/src/utils/websocket/drone-ws-control.js b/src/utils/websocket/drone-ws-control.js
new file mode 100644
index 0000000..9e5be0f
--- /dev/null
+++ b/src/utils/websocket/drone-ws-control.js
@@ -0,0 +1,118 @@
+// import { EventBus } from '@/eventBus/event-bus';
+import { EBizCode, EBizCodeMessage } from '@/utils/staticData/enums'
+import { ControlSource } from '@/utils/staticData/device'
+
+export default {
+	data() {
+		return {
+			droneControlSource: '',
+			payloadControlSource: '',
+			ControlSource: ControlSource,
+		}
+	},
+	methods: {
+		useDroneControlWsEvent(sn, payloadSn, funcs) {
+			const _this = this
+			this.droneControlSource = this.ControlSource.A
+			this.payloadControlSource = this.ControlSource.B
+
+			function onControlSourceChange(data) {
+				if (data.type === 1 && data.sn === sn) {
+					_this.droneControlSource = data.control_source
+					_this.$store.commit('SET_DRONE_CONTROL_SOURCE', _this.droneControlSource)
+					// _this.$message.info(`飞行控制改为 ${_this.droneControlSource}`)
+					// _this._showMessage.info(`飞行控制改为 ${_this.droneControlSource}`)
+					return
+				}
+				if (data.type === 2 && data.sn === payloadSn) {
+					_this.payloadControlSource = data.control_source
+					// _this.$message.info(`负载控制改为 ${_this.payloadControlSource}.`)
+					// _this._showMessage.info(`负载控制改为 ${_this.payloadControlSource}.`)
+				}
+			}
+
+			function handleProgress(key, message, error) {
+				if (error !== 0) {
+					// _this.$notify.closeAll()
+					// _this.$notify.error({
+					//     title: key + '错误码:' + error,
+					//     message: message,
+					//     duration: 30
+					// })
+					// _this._showMessage.warning(key + '错误码:' + error)
+					_this._showMessage.warning(key)
+				} else {
+					// _this.$notify.closeAll()
+					// _this.$notify.info({
+					//     title: key,
+					//     message: message,
+					//     duration: 30
+					// })
+					_this._showMessage.info(message)
+				}
+			}
+
+			function handleDroneControlWsEvent(payload) {
+				if (!payload) {
+					return
+				}
+				switch (payload.biz_code) {
+					case EBizCode.ControlSourceChange: {
+						onControlSourceChange(payload.data)
+						break
+					}
+					case EBizCode.FlyToPointProgress: {
+						const { sn: deviceSn, result, message: msg } = payload.data
+						if (deviceSn !== sn) return
+						handleProgress(
+							EBizCodeMessage[EBizCode.FlyToPointProgress],
+							`设备(编码: ${deviceSn}) ${msg}`,
+							result
+						)
+						break
+					}
+					case EBizCode.TakeoffToPointProgress: {
+						const { sn: deviceSn, result, message: msg } = payload.data
+						if (deviceSn !== sn) return
+						handleProgress(
+							EBizCodeMessage[EBizCode.TakeoffToPointProgress],
+							`设备(编码: ${deviceSn}) ${msg}`,
+							result
+						)
+						break
+					}
+					case EBizCode.JoystickInvalidNotify: {
+						const { sn: deviceSn, result, message: msg } = payload.data
+						if (deviceSn !== sn) return
+						handleProgress(
+							EBizCodeMessage[EBizCode.JoystickInvalidNotify],
+							`设备(编码: ${deviceSn}) ${msg}`,
+							result
+						)
+						break
+					}
+					case EBizCode.DrcStatusNotify: {
+						const { sn: deviceSn, result, message: msg } = payload.data
+						break
+					}
+				}
+			}
+
+			return {
+				handleDroneControlWsEvent,
+			}
+		},
+	},
+	mounted() {
+		this.$EventBus.$on(
+			'droneControlWs',
+			this.useDroneControlWsEvent(this.sn, this.payloadSelectInfo.value).handleDroneControlWsEvent
+		)
+	},
+	beforeDestroy() {
+		this.$EventBus.$off(
+			'droneControlWs',
+			this.useDroneControlWsEvent(this.sn, this.payloadSelectInfo.value).handleDroneControlWsEvent
+		)
+	},
+}

--
Gitblit v1.9.3