forked from drone/command-center-dashboard

chenyao
2025-04-02 ec3c634630d4fc44c01bf4e5902c7f9fee67adab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// 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,
        );
    },
};