sean.zhou
2 years ago
20 changed files with 978 additions and 63 deletions
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
import request, { IWorkspaceResponse } from '/@/api/http/request' |
||||
import { ELocalStorageKey } from '/@/types' |
||||
import { NightLightsStateEnum, DistanceLimitStatus, ObstacleAvoidance } from '/@/types/device-setting' |
||||
|
||||
const MNG_API_PREFIX = '/manage/api/v1' |
||||
const workspaceId: string = localStorage.getItem(ELocalStorageKey.WorkspaceId) || '' |
||||
|
||||
export interface PutDevicePropsBody { |
||||
night_lights_state?: NightLightsStateEnum;// 夜航灯开关
|
||||
height_limit?: number;// 限高设置
|
||||
distance_limit_status?: DistanceLimitStatus;// 限远开关
|
||||
obstacle_avoidance?: ObstacleAvoidance;// 飞行器避障开关设置
|
||||
} |
||||
|
||||
/** |
||||
* 设置设备属性 |
||||
* @param params |
||||
* @returns |
||||
*/ |
||||
// /manage/api/v1/devices/{{workspace_id}}/devices/{{device_sn}}/property
|
||||
export async function putDeviceProps (deviceSn: string, body: PutDevicePropsBody): Promise<IWorkspaceResponse<{}>> { |
||||
const resp = await request.put(`${MNG_API_PREFIX}/devices/${workspaceId}/devices/${deviceSn}/property`, body) |
||||
return resp.data |
||||
} |
@ -0,0 +1,242 @@
@@ -0,0 +1,242 @@
|
||||
<template> |
||||
<div class="device-setting-wrapper"> |
||||
<div class="device-setting-header">设备属性设置</div> |
||||
<div class="device-setting-box"> |
||||
<!-- 飞行器夜航灯 --> |
||||
<div class="control-setting-item"> |
||||
<div class="control-setting-item-left"> |
||||
<div class="item-label">{{ deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].label }}</div> |
||||
<div class="item-status">{{ deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].value }}</div> |
||||
</div> |
||||
<div class="control-setting-item-right"> |
||||
<DeviceSettingPopover |
||||
:visible="deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].popConfirm.visible" |
||||
:loading="deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].popConfirm.loading" |
||||
@confirm="onConfirm(deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].settingKey)" |
||||
@cancel="onCancel(deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].settingKey)" |
||||
> |
||||
<template #formContent> |
||||
<div class="form-content"> |
||||
<span class="form-label">{{ deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].label }}:</span> |
||||
<a-switch checked-children="开" un-checked-children="关" v-model:checked="deviceSettingFormModel.nightLightsState" /> |
||||
</div> |
||||
</template> |
||||
<a @click="onShowPopConfirm(deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].settingKey)">Edit</a> |
||||
</DeviceSettingPopover> |
||||
</div> |
||||
</div> |
||||
<!-- 限高 --> |
||||
<div class="control-setting-item"> |
||||
<div class="control-setting-item-left"> |
||||
<div class="item-label">{{ deviceSetting[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].label }}</div> |
||||
<div class="item-status">{{ deviceSetting[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].value }}</div> |
||||
</div> |
||||
<div class="control-setting-item-right"> |
||||
<DeviceSettingPopover |
||||
:visible="deviceSetting[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].popConfirm.visible" |
||||
:loading="deviceSetting[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].popConfirm.loading" |
||||
@confirm="onConfirm(deviceSetting[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].settingKey)" |
||||
@cancel="onCancel(deviceSetting[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].settingKey)" |
||||
> |
||||
<template #formContent> |
||||
<div class="form-content"> |
||||
<span class="form-label">{{ deviceSetting[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].label }}:</span> |
||||
<a-input-number v-model:value="deviceSettingFormModel.heightLimit" :min="20" :max="1500" /> |
||||
m |
||||
</div> |
||||
</template> |
||||
<a @click="onShowPopConfirm(deviceSetting[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].settingKey)">Edit</a> |
||||
</DeviceSettingPopover> |
||||
</div> |
||||
</div> |
||||
<!-- 限远 --> |
||||
<div class="control-setting-item"> |
||||
<div class="control-setting-item-left"> |
||||
<div class="item-label">{{ deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].label }}</div> |
||||
<div class="item-status">{{ deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].value }}</div> |
||||
</div> |
||||
<div class="control-setting-item-right"> |
||||
<DeviceSettingPopover |
||||
:visible="deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].popConfirm.visible" |
||||
:loading="deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].popConfirm.loading" |
||||
@confirm="onConfirm(deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].settingKey)" |
||||
@cancel="onCancel(deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].settingKey)" |
||||
> |
||||
<template #formContent> |
||||
<div class="form-content"> |
||||
<span class="form-label">{{ deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].label }}:</span> |
||||
<a-switch style="margin-right: 10px;" checked-children="开" un-checked-children="关" v-model:checked="deviceSettingFormModel.distanceLimitStatus.state" /> |
||||
<a-input-number v-model:value="deviceSettingFormModel.distanceLimitStatus.distanceLimit" :min="15" :max="8000" /> |
||||
m |
||||
</div> |
||||
</template> |
||||
<a @click="onShowPopConfirm(deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].settingKey)">Edit</a> |
||||
</DeviceSettingPopover> |
||||
</div> |
||||
</div> |
||||
<!-- 水平避障 --> |
||||
<div class="control-setting-item"> |
||||
<div class="control-setting-item-left"> |
||||
<div class="item-label">{{ deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].label }}</div> |
||||
<div class="item-status">{{ deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].value }}</div> |
||||
</div> |
||||
<div class="control-setting-item-right"> |
||||
<DeviceSettingPopover |
||||
:visible="deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].popConfirm.visible" |
||||
:loading="deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].popConfirm.loading" |
||||
@confirm="onConfirm(deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].settingKey)" |
||||
@cancel="onCancel(deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].settingKey)" |
||||
> |
||||
<template #formContent> |
||||
<div class="form-content"> |
||||
<span class="form-label">{{ deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].label }}:</span> |
||||
<a-switch checked-children="开" un-checked-children="关" v-model:checked="deviceSettingFormModel.obstacleAvoidanceHorizon" /> |
||||
</div> |
||||
</template> |
||||
<a @click="onShowPopConfirm(deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].settingKey)">Edit</a> |
||||
</DeviceSettingPopover> |
||||
</div> |
||||
</div> |
||||
<!-- 上视避障 --> |
||||
<div class="control-setting-item"> |
||||
<div class="control-setting-item-left"> |
||||
<div class="item-label">{{ deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].label }}</div> |
||||
<div class="item-status">{{ deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].value }}</div> |
||||
</div> |
||||
<div class="control-setting-item-right"> |
||||
<DeviceSettingPopover |
||||
:visible="deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].popConfirm.visible" |
||||
:loading="deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].popConfirm.loading" |
||||
@confirm="onConfirm(deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].settingKey)" |
||||
@cancel="onCancel(deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].settingKey)" |
||||
> |
||||
<template #formContent> |
||||
<div class="form-content"> |
||||
<span class="form-label">{{ deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].label }}:</span> |
||||
<a-switch checked-children="开" un-checked-children="关" v-model:checked="deviceSettingFormModel.obstacleAvoidanceUpside" /> |
||||
</div> |
||||
</template> |
||||
<a @click="onShowPopConfirm(deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].settingKey)">Edit</a> |
||||
</DeviceSettingPopover> |
||||
</div> |
||||
</div> |
||||
<!-- 下视避障 --> |
||||
<div class="control-setting-item"> |
||||
<div class="control-setting-item-left"> |
||||
<div class="item-label">{{ deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].label }}</div> |
||||
<div class="item-status">{{ deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].value }}</div> |
||||
</div> |
||||
<div class="control-setting-item-right"> |
||||
<DeviceSettingPopover |
||||
:visible="deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].popConfirm.visible" |
||||
:loading="deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].popConfirm.loading" |
||||
@confirm="onConfirm(deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].settingKey)" |
||||
@cancel="onCancel(deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].settingKey)" |
||||
> |
||||
<template #formContent> |
||||
<div class="form-content"> |
||||
<span class="form-label">{{ deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].label }}:</span> |
||||
<a-switch checked-children="开" un-checked-children="关" v-model:checked="deviceSettingFormModel.obstacleAvoidanceDownside" /> |
||||
</div> |
||||
</template> |
||||
<a @click="onShowPopConfirm(deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].settingKey)">Edit</a> |
||||
</DeviceSettingPopover> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</template> |
||||
|
||||
<script setup lang="ts"> |
||||
import { defineProps, ref, watch } from 'vue' |
||||
import { DeviceInfoType } from '/@/types/device' |
||||
import { useMyStore } from '/@/store' |
||||
import { cloneDeep } from 'lodash' |
||||
import { initDeviceSetting, initDeviceSettingFormModel, DeviceSettingKeyEnum } from '/@/types/device-setting' |
||||
import { updateDeviceSettingInfoByOsd, updateDeviceSettingFormModelByOsd } from '/@/utils/device-setting' |
||||
import { useDeviceSetting } from './useDeviceSetting' |
||||
import DeviceSettingPopover from './DeviceSettingPopover.vue' |
||||
|
||||
const props = defineProps<{ |
||||
sn: string, |
||||
deviceInfo: DeviceInfoType, |
||||
}>() |
||||
|
||||
const store = useMyStore() |
||||
const deviceSetting = ref(cloneDeep(initDeviceSetting)) |
||||
const deviceSettingFormModelFromOsd = ref(cloneDeep(initDeviceSettingFormModel)) |
||||
const deviceSettingFormModel = ref(cloneDeep(initDeviceSettingFormModel)) // 真实使用的formModel |
||||
|
||||
// 根据设备osd信息更新信息 |
||||
watch(() => props.deviceInfo, (value) => { |
||||
updateDeviceSettingInfoByOsd(deviceSetting.value, value) |
||||
updateDeviceSettingFormModelByOsd(deviceSettingFormModelFromOsd.value, value) |
||||
// console.log('deviceInfo', value) |
||||
}, { |
||||
immediate: true, |
||||
deep: true |
||||
}) |
||||
|
||||
function onShowPopConfirm (settingKey: DeviceSettingKeyEnum) { |
||||
deviceSetting.value[settingKey].popConfirm.visible = true |
||||
deviceSettingFormModel.value = cloneDeep(deviceSettingFormModelFromOsd.value) |
||||
} |
||||
|
||||
function onCancel (settingKey: DeviceSettingKeyEnum) { |
||||
deviceSetting.value[settingKey].popConfirm.visible = false |
||||
} |
||||
|
||||
async function onConfirm (settingKey: DeviceSettingKeyEnum) { |
||||
deviceSetting.value[settingKey].popConfirm.loading = true |
||||
const body = genDevicePropsBySettingKey(settingKey, deviceSettingFormModel.value) |
||||
await setDeviceProps(props.sn, body) |
||||
deviceSetting.value[settingKey].popConfirm.loading = false |
||||
deviceSetting.value[settingKey].popConfirm.visible = false |
||||
} |
||||
|
||||
// 更新设备属性 |
||||
const { |
||||
genDevicePropsBySettingKey, |
||||
setDeviceProps, |
||||
} = useDeviceSetting() |
||||
|
||||
</script> |
||||
|
||||
<style lang='scss' scoped> |
||||
.device-setting-wrapper{ |
||||
border-bottom: 1px solid #515151; |
||||
|
||||
.device-setting-header{ |
||||
font-size: 14px; |
||||
font-weight: 600; |
||||
padding: 10px 10px 0px; |
||||
} |
||||
|
||||
.device-setting-box{ |
||||
display: flex; |
||||
flex-wrap: wrap; |
||||
justify-content: space-between; |
||||
padding: 4px 10px; |
||||
|
||||
.control-setting-item{ |
||||
width: 220px; |
||||
height: 58px; |
||||
display: flex; |
||||
align-items: center; |
||||
justify-content: space-between; |
||||
border: 1px solid #666; |
||||
margin: 4px 0; |
||||
padding: 0 8px; |
||||
|
||||
.control-setting-item-left{ |
||||
display: flex; |
||||
flex-direction: column; |
||||
|
||||
.item-label{ |
||||
font-weight: 700; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
</style> |
@ -0,0 +1,106 @@
@@ -0,0 +1,106 @@
|
||||
<template> |
||||
<a-popover :visible="state.sVisible" |
||||
trigger="click" |
||||
v-bind="$attrs" |
||||
:overlay-class-name="overlayClassName" |
||||
placement="bottom" |
||||
@visibleChange=";" |
||||
v-on="$attrs"> |
||||
<template #content> |
||||
<div class="title-content"> |
||||
</div> |
||||
<slot name="formContent" /> |
||||
<div class="uranus-popconfirm-btns"> |
||||
<a-button size="sm" |
||||
@click="onCancel"> |
||||
{{ cancelText || '取消'}} |
||||
</a-button> |
||||
<a-button size="sm" |
||||
:loading="loading" |
||||
type="primary" |
||||
class="confirm-btn" |
||||
@click="onConfirm"> |
||||
{{ okText || '确定' }} |
||||
</a-button> |
||||
</div> |
||||
</template> |
||||
<template v-if="$slots.default"> |
||||
<slot></slot> |
||||
</template> |
||||
</a-popover> |
||||
</template> |
||||
|
||||
<script lang="ts" setup> |
||||
import { defineProps, defineEmits, reactive, watch, computed } from 'vue' |
||||
|
||||
const props = defineProps<{ |
||||
visible?: boolean, |
||||
loading?: Boolean, |
||||
disabled?: Boolean, |
||||
title?: String, |
||||
okText?: String, |
||||
cancelText?: String, |
||||
width?: Number, |
||||
}>() |
||||
|
||||
const emit = defineEmits(['cancel', 'confirm']) |
||||
|
||||
const state = reactive({ |
||||
sVisible: false, |
||||
loading: false, |
||||
}) |
||||
|
||||
watch(() => props.visible, (val) => { |
||||
state.sVisible = val || false |
||||
}) |
||||
|
||||
const loading = computed(() => { |
||||
return props.loading |
||||
}) |
||||
const okLabel = computed(() => { |
||||
return props.loading ? '' : '确定' |
||||
}) |
||||
|
||||
const overlayClassName = computed(() => { |
||||
const classList = ['device-setting-popconfirm'] |
||||
return classList.join(' ') |
||||
}) |
||||
|
||||
function onConfirm (e: Event) { |
||||
if (props.disabled) { |
||||
return |
||||
} |
||||
emit('confirm', e) |
||||
} |
||||
|
||||
function onCancel (e: Event) { |
||||
state.sVisible = false |
||||
emit('cancel', e) |
||||
} |
||||
|
||||
</script> |
||||
|
||||
<style lang="scss"> |
||||
.device-setting-popconfirm { |
||||
min-width: 300px; |
||||
|
||||
.uranus-popconfirm-btns{ |
||||
display: flex; |
||||
padding: 10px 0px; |
||||
justify-content: flex-end; |
||||
|
||||
.confirm-btn{ |
||||
margin-left: 10px; |
||||
} |
||||
} |
||||
|
||||
.form-content{ |
||||
display: inline-flex; |
||||
align-items: center; |
||||
|
||||
.form-label{ |
||||
padding-right: 10px; |
||||
} |
||||
} |
||||
} |
||||
</style> |
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
import { message } from 'ant-design-vue' |
||||
import { putDeviceProps, PutDevicePropsBody } from '/@/api/device-setting' |
||||
import { DeviceSettingKeyEnum, DeviceSettingFormModel, ObstacleAvoidanceStatusEnum, NightLightsStateEnum, DistanceLimitStatusEnum } from '/@/types/device-setting' |
||||
|
||||
export function useDeviceSetting () { |
||||
// 生成参数
|
||||
function genDevicePropsBySettingKey (key: DeviceSettingKeyEnum, fromModel: DeviceSettingFormModel) { |
||||
const body = {} as PutDevicePropsBody |
||||
if (key === DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET) { |
||||
body.night_lights_state = fromModel.nightLightsState ? NightLightsStateEnum.OPEN : NightLightsStateEnum.CLOSE |
||||
} else if (key === DeviceSettingKeyEnum.HEIGHT_LIMIT_SET) { |
||||
body.height_limit = fromModel.heightLimit |
||||
} else if (key === DeviceSettingKeyEnum.DISTANCE_LIMIT_SET) { |
||||
body.distance_limit_status = {} |
||||
if (fromModel.distanceLimitStatus.state) { |
||||
body.distance_limit_status.state = DistanceLimitStatusEnum.SET |
||||
body.distance_limit_status.distance_limit = fromModel.distanceLimitStatus.distanceLimit |
||||
} else { |
||||
body.distance_limit_status.state = DistanceLimitStatusEnum.UNSET |
||||
} |
||||
} else if (key === DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON) { |
||||
body.obstacle_avoidance = { |
||||
horizon: fromModel.obstacleAvoidanceHorizon ? ObstacleAvoidanceStatusEnum.OPEN : ObstacleAvoidanceStatusEnum.CLOSE |
||||
} |
||||
} else if (key === DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE) { |
||||
body.obstacle_avoidance = { |
||||
upside: fromModel.obstacleAvoidanceUpside ? ObstacleAvoidanceStatusEnum.OPEN : ObstacleAvoidanceStatusEnum.CLOSE |
||||
} |
||||
} else if (key === DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE) { |
||||
body.obstacle_avoidance = { |
||||
downside: fromModel.obstacleAvoidanceDownside ? ObstacleAvoidanceStatusEnum.OPEN : ObstacleAvoidanceStatusEnum.CLOSE |
||||
} |
||||
} |
||||
return body |
||||
} |
||||
|
||||
// 设置设备属性
|
||||
async function setDeviceProps (sn: string, body: PutDevicePropsBody) { |
||||
try { |
||||
const { code, message: msg } = await putDeviceProps(sn, body) |
||||
if (code === 0) { |
||||
// message.success('指令发送成功')
|
||||
return true |
||||
} |
||||
throw (msg) |
||||
} catch (e) { |
||||
message.error('设备属性设置失败') |
||||
return false |
||||
} |
||||
} |
||||
|
||||
return { |
||||
genDevicePropsBySettingKey, |
||||
setDeviceProps |
||||
} |
||||
} |
@ -0,0 +1,148 @@
@@ -0,0 +1,148 @@
|
||||
// 夜航灯开关
|
||||
export enum NightLightsStateEnum { |
||||
CLOSE = 0, // 0-关闭
|
||||
OPEN = 1, // 1-打开
|
||||
} |
||||
|
||||
// 限远开关
|
||||
export enum DistanceLimitStatusEnum { |
||||
UNSET = 0, // 0-未设置
|
||||
SET = 1, // 1-已设置
|
||||
} |
||||
|
||||
export interface DistanceLimitStatus { |
||||
state?: DistanceLimitStatusEnum; |
||||
distance_limit?: number; // 限远
|
||||
} |
||||
|
||||
// 避障
|
||||
export enum ObstacleAvoidanceStatusEnum { |
||||
CLOSE = 0, // 0-关闭
|
||||
OPEN = 1, // 1-开启
|
||||
} |
||||
|
||||
export interface ObstacleAvoidance { |
||||
horizon?: ObstacleAvoidanceStatusEnum;// 水平避障开关
|
||||
upside?: ObstacleAvoidanceStatusEnum;// 上行方向避障开关
|
||||
downside?: ObstacleAvoidanceStatusEnum;// 下行方向避障开关
|
||||
} |
||||
|
||||
// 设备管理设置key
|
||||
export enum DeviceSettingKeyEnum { |
||||
NIGHT_LIGHTS_MODE_SET = 'night_lights_state', // 夜航灯开关
|
||||
HEIGHT_LIMIT_SET = 'height_limit', // 限高设置
|
||||
DISTANCE_LIMIT_SET = 'distance_limit_status', // 限远开关
|
||||
OBSTACLE_AVOIDANCE_HORIZON = 'obstacle_avoidance_horizon', // 水平避障状态
|
||||
OBSTACLE_AVOIDANCE_UPSIDE = 'obstacle_avoidance_upside', // 上视避障状态
|
||||
OBSTACLE_AVOIDANCE_DOWNSIDE = 'obstacle_avoidance_downside', // 下视避障状态
|
||||
} |
||||
|
||||
export type DeviceSettingType = Record<DeviceSettingKeyEnum, any> |
||||
|
||||
export const initDeviceSetting = { |
||||
[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET]: |
||||
{ |
||||
label: '飞行器夜航灯', |
||||
value: '', |
||||
trueValue: NightLightsStateEnum.CLOSE, |
||||
editable: false, |
||||
popConfirm: { |
||||
visible: false, |
||||
loading: false, |
||||
// content: '为保证飞行器的作业安全,建议打开夜航灯',
|
||||
label: '飞行器夜航灯', |
||||
}, |
||||
settingKey: DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET, |
||||
}, |
||||
[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET]: |
||||
{ |
||||
label: '限高', |
||||
value: '', |
||||
trueValue: 120, |
||||
editable: false, |
||||
popConfirm: { |
||||
visible: false, |
||||
loading: false, |
||||
// content: '限高:20 - 1500m',
|
||||
// info: '修改限高会影响当前机场的所有作业任务,建议确认作业情况后再进行修改',
|
||||
label: '限高', |
||||
}, |
||||
settingKey: DeviceSettingKeyEnum.HEIGHT_LIMIT_SET, |
||||
}, |
||||
[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET]: |
||||
{ |
||||
label: '限远', |
||||
value: '', |
||||
trueValue: DistanceLimitStatusEnum.UNSET, |
||||
// info: '限远(15 - 8000m)是约束飞行器相对机场的最大作业距离',
|
||||
editable: false, |
||||
popConfirm: { |
||||
visible: false, |
||||
loading: false, |
||||
// content: '限远 (15- 8000m) 是约束飞行器相对机场的最大作业距离',
|
||||
// info: '修改限远会影响当前机场的所有作业任务,建议确认作业情况后再进行修改',
|
||||
label: '限远', |
||||
|
||||
}, |
||||
settingKey: DeviceSettingKeyEnum.DISTANCE_LIMIT_SET, |
||||
}, |
||||
[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON]: |
||||
{ |
||||
label: '水平避障', |
||||
value: '', |
||||
trueValue: ObstacleAvoidanceStatusEnum.CLOSE, |
||||
// info: '飞行器的避障工作状态显示,可以快速开启/关闭飞行器避障,如需进一步设置请在设备运维页面设置',
|
||||
editable: false, |
||||
popConfirm: { |
||||
visible: false, |
||||
loading: false, |
||||
// content: '飞行器避障是保障飞行作业安全的基础功能,建议保持飞行器避障开启',
|
||||
label: '水平避障', |
||||
|
||||
}, |
||||
settingKey: DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON, |
||||
}, |
||||
[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE]: |
||||
{ |
||||
label: '上视避障', |
||||
value: '', |
||||
trueValue: ObstacleAvoidanceStatusEnum.CLOSE, |
||||
// info: '飞行器的避障工作状态显示,可以快速开启/关闭飞行器避障,如需进一步设置请在设备运维页面设置',
|
||||
editable: false, |
||||
popConfirm: { |
||||
visible: false, |
||||
loading: false, |
||||
// content: '飞行器避障是保障飞行作业安全的基础功能,建议保持飞行器避障开启',
|
||||
label: '上视避障', |
||||
|
||||
}, |
||||
settingKey: DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE, |
||||
}, |
||||
[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE]: |
||||
{ |
||||
label: '下视避障', |
||||
value: '', |
||||
trueValue: ObstacleAvoidanceStatusEnum.CLOSE, |
||||
// info: '飞行器的避障工作状态显示,可以快速开启/关闭飞行器避障,如需进一步设置请在设备运维页面设置',
|
||||
editable: false, |
||||
popConfirm: { |
||||
visible: false, |
||||
loading: false, |
||||
// content: '飞行器避障是保障飞行作业安全的基础功能,建议保持飞行器避障开启',
|
||||
label: '下视避障', |
||||
|
||||
}, |
||||
settingKey: DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE, |
||||
}, |
||||
} as DeviceSettingType |
||||
|
||||
export const initDeviceSettingFormModel = { |
||||
nightLightsState: false, // 夜航灯开关
|
||||
heightLimit: 20, // 限高设置
|
||||
distanceLimitStatus: { state: false, distanceLimit: 15 }, // 限远开关
|
||||
obstacleAvoidanceHorizon: false, // 飞行器避障-水平开关设置
|
||||
obstacleAvoidanceUpside: false, // 飞行器避障-上视开关设置
|
||||
obstacleAvoidanceDownside: false, // 飞行器避障-下视开关设置
|
||||
} |
||||
|
||||
export type DeviceSettingFormModel = typeof initDeviceSettingFormModel |
@ -0,0 +1,193 @@
@@ -0,0 +1,193 @@
|
||||
import { DeviceInfoType } from '/@/types/device' |
||||
import { DeviceSettingType, DeviceSettingKeyEnum, DistanceLimitStatusEnum, ObstacleAvoidanceStatusEnum, DeviceSettingFormModel, NightLightsStateEnum } from '/@/types/device-setting' |
||||
import { DEFAULT_PLACEHOLDER } from './constants' |
||||
import { isNil } from 'lodash' |
||||
|
||||
const Unit_M = ' m' |
||||
|
||||
/** |
||||
* 根据osd 更新信息 |
||||
* @param deviceSetting |
||||
* @param deviceInfo |
||||
* @returns |
||||
*/ |
||||
export function updateDeviceSettingInfoByOsd (deviceSetting: DeviceSettingType, deviceInfo: DeviceInfoType) { |
||||
const { device, dock, gateway } = deviceInfo || {} |
||||
if (!deviceSetting) { |
||||
return |
||||
} |
||||
// 夜航灯
|
||||
let nightLightsState = '' as any |
||||
if (isNil(device?.night_lights_state)) { |
||||
deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].editable = false |
||||
deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].value = DEFAULT_PLACEHOLDER |
||||
nightLightsState = DEFAULT_PLACEHOLDER |
||||
} else { |
||||
deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].editable = true |
||||
nightLightsState = device?.night_lights_state |
||||
if (nightLightsState === NightLightsStateEnum.CLOSE) { |
||||
deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].value = '关闭' |
||||
} else if (nightLightsState === NightLightsStateEnum.OPEN) { |
||||
deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].value = '开启' |
||||
} else { |
||||
deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].value = DEFAULT_PLACEHOLDER |
||||
} |
||||
} |
||||
deviceSetting[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].trueValue = nightLightsState |
||||
|
||||
// 限高
|
||||
let heightLimit = device?.height_limit as any |
||||
if (isNil(heightLimit) || heightLimit === 0) { |
||||
heightLimit = DEFAULT_PLACEHOLDER |
||||
deviceSetting[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].editable = false |
||||
} else { |
||||
deviceSetting[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].editable = true |
||||
} |
||||
deviceSetting[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].trueValue = heightLimit |
||||
deviceSetting[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].value = heightLimit + Unit_M |
||||
|
||||
// 限远
|
||||
let distanceLimitStatus = '' as any |
||||
if (isNil(device?.distance_limit_status?.state)) { |
||||
distanceLimitStatus = DEFAULT_PLACEHOLDER |
||||
deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].editable = false |
||||
deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].value = DEFAULT_PLACEHOLDER |
||||
} else { |
||||
deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].editable = true |
||||
distanceLimitStatus = device?.distance_limit_status?.state |
||||
if (distanceLimitStatus === DistanceLimitStatusEnum.UNSET) { |
||||
deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].value = '关闭' |
||||
} else if (distanceLimitStatus === DistanceLimitStatusEnum.SET) { |
||||
const distanceLimit = device?.distance_limit_status?.distance_limit |
||||
if (distanceLimit) { |
||||
deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].value = distanceLimit + Unit_M |
||||
} else { |
||||
deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].value = DEFAULT_PLACEHOLDER |
||||
} |
||||
} else { |
||||
deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].value = DEFAULT_PLACEHOLDER |
||||
} |
||||
} |
||||
deviceSetting[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].trueValue = distanceLimitStatus |
||||
|
||||
// 避障
|
||||
if (isNil(device?.obstacle_avoidance)) { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].editable = false |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].value = DEFAULT_PLACEHOLDER |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].trueValue = DEFAULT_PLACEHOLDER |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].editable = false |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].value = DEFAULT_PLACEHOLDER |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].trueValue = DEFAULT_PLACEHOLDER |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].editable = false |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].value = DEFAULT_PLACEHOLDER |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].trueValue = DEFAULT_PLACEHOLDER |
||||
} else { |
||||
const { horizon, upside, downside } = device.obstacle_avoidance || {} |
||||
if (isNil(horizon)) { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].editable = false |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].value = DEFAULT_PLACEHOLDER |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].trueValue = DEFAULT_PLACEHOLDER |
||||
} else { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].editable = false |
||||
if (horizon === ObstacleAvoidanceStatusEnum.CLOSE) { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].value = '关闭' |
||||
} else if (horizon === ObstacleAvoidanceStatusEnum.OPEN) { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].value = '开启' |
||||
} else { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].value = DEFAULT_PLACEHOLDER |
||||
} |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].trueValue = horizon |
||||
} |
||||
|
||||
if (isNil(upside)) { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].editable = false |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].value = DEFAULT_PLACEHOLDER |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].trueValue = DEFAULT_PLACEHOLDER |
||||
} else { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].editable = false |
||||
if (upside === ObstacleAvoidanceStatusEnum.CLOSE) { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].value = '关闭' |
||||
} else if (upside === ObstacleAvoidanceStatusEnum.OPEN) { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].value = '开启' |
||||
} else { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].value = DEFAULT_PLACEHOLDER |
||||
} |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].trueValue = upside |
||||
} |
||||
|
||||
if (isNil(downside)) { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].editable = false |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].value = DEFAULT_PLACEHOLDER |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].trueValue = DEFAULT_PLACEHOLDER |
||||
} else { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].editable = false |
||||
if (downside === ObstacleAvoidanceStatusEnum.CLOSE) { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].value = '关闭' |
||||
} else if (downside === ObstacleAvoidanceStatusEnum.OPEN) { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].value = '开启' |
||||
} else { |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].value = DEFAULT_PLACEHOLDER |
||||
} |
||||
deviceSetting[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].trueValue = downside |
||||
} |
||||
} |
||||
return deviceSetting |
||||
} |
||||
|
||||
// 更新formModel
|
||||
export function updateDeviceSettingFormModelByOsd (deviceSettingFormModelFromOsd: DeviceSettingFormModel, deviceInfo: DeviceInfoType) { |
||||
const { device, dock, gateway } = deviceInfo || {} |
||||
if (!deviceSettingFormModelFromOsd) { |
||||
return |
||||
} |
||||
// 夜航灯
|
||||
const nightLightsState = device?.night_lights_state as any |
||||
if (!isNil(nightLightsState) && nightLightsState === NightLightsStateEnum.OPEN) { |
||||
deviceSettingFormModelFromOsd.nightLightsState = true |
||||
} else { |
||||
deviceSettingFormModelFromOsd.nightLightsState = false |
||||
} |
||||
|
||||
// 限高
|
||||
const heightLimit = device?.height_limit as any |
||||
if (isNil(heightLimit) || heightLimit === 0) { |
||||
deviceSettingFormModelFromOsd.heightLimit = 20 |
||||
} else { |
||||
deviceSettingFormModelFromOsd.heightLimit = heightLimit |
||||
} |
||||
|
||||
// 限远
|
||||
const distanceLimitStatus = device?.distance_limit_status?.state as any |
||||
if (!isNil(distanceLimitStatus) && distanceLimitStatus === DistanceLimitStatusEnum.SET) { |
||||
deviceSettingFormModelFromOsd.distanceLimitStatus.state = true |
||||
deviceSettingFormModelFromOsd.distanceLimitStatus.distanceLimit = device?.distance_limit_status?.distance_limit || 15 |
||||
} else { |
||||
deviceSettingFormModelFromOsd.distanceLimitStatus.state = false |
||||
deviceSettingFormModelFromOsd.distanceLimitStatus.distanceLimit = 15 |
||||
} |
||||
|
||||
// 避障
|
||||
if (isNil(device?.obstacle_avoidance)) { |
||||
deviceSettingFormModelFromOsd.obstacleAvoidanceHorizon = false |
||||
deviceSettingFormModelFromOsd.obstacleAvoidanceUpside = false |
||||
deviceSettingFormModelFromOsd.obstacleAvoidanceDownside = false |
||||
} else { |
||||
const { horizon, upside, downside } = device.obstacle_avoidance || {} |
||||
if (!isNil(horizon) && horizon === ObstacleAvoidanceStatusEnum.OPEN) { |
||||
deviceSettingFormModelFromOsd.obstacleAvoidanceHorizon = true |
||||
} else { |
||||
deviceSettingFormModelFromOsd.obstacleAvoidanceHorizon = false |
||||
} |
||||
if (!isNil(upside) && upside === ObstacleAvoidanceStatusEnum.OPEN) { |
||||
deviceSettingFormModelFromOsd.obstacleAvoidanceUpside = true |
||||
} else { |
||||
deviceSettingFormModelFromOsd.obstacleAvoidanceUpside = false |
||||
} |
||||
if (!isNil(downside) && downside === ObstacleAvoidanceStatusEnum.OPEN) { |
||||
deviceSettingFormModelFromOsd.obstacleAvoidanceDownside = true |
||||
} else { |
||||
deviceSettingFormModelFromOsd.obstacleAvoidanceDownside = false |
||||
} |
||||
} |
||||
return deviceSettingFormModelFromOsd |
||||
} |
Loading…
Reference in new issue