// 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,
|
);
|
},
|
};
|