import {
|
DeviceSettingKeyEnum,
|
DistanceLimitStatusEnum,
|
ObstacleAvoidanceStatusEnum,
|
NightLightsStateEnum
|
} from "@/types/device-setting"
|
import { DEFAULT_PLACEHOLDER } from "./constants"
|
import { isNil } from "lodash"
|
|
const Unit_M = " m"
|
|
/**
|
* 根据osd 更新信息
|
* @param deviceSetting.value
|
* @param deviceInfo
|
* @returns
|
*/
|
export function updateDeviceSettingInfoByOsd(deviceSetting, deviceInfo) {
|
// const { device, dock, gateway } = deviceInfo.value || {}
|
let device = deviceInfo?? {}
|
if (!deviceSetting.value) {
|
return
|
}
|
// 夜航灯
|
let nightLightsState = ""
|
if (isNil(device?.night_lights_state)) {
|
deviceSetting.value[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].editable = false
|
deviceSetting.value[
|
DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET
|
].value = DEFAULT_PLACEHOLDER
|
nightLightsState = DEFAULT_PLACEHOLDER
|
} else {
|
deviceSetting.value[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].editable = true
|
nightLightsState = device?.night_lights_state
|
if (nightLightsState === NightLightsStateEnum.CLOSE) {
|
deviceSetting.value[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].value = "关闭"
|
} else if (nightLightsState === NightLightsStateEnum.OPEN) {
|
deviceSetting.value[DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET].value = "开启"
|
} else {
|
deviceSetting.value[
|
DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET
|
].value = DEFAULT_PLACEHOLDER
|
}
|
}
|
deviceSetting.value[
|
DeviceSettingKeyEnum.NIGHT_LIGHTS_MODE_SET
|
].trueValue = nightLightsState
|
|
// 限高
|
let heightLimit = device?.height_limit
|
if (isNil(heightLimit) || heightLimit === 0) {
|
heightLimit = DEFAULT_PLACEHOLDER
|
deviceSetting.value[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].editable = false
|
} else {
|
deviceSetting.value[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].editable = true
|
}
|
deviceSetting.value[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].trueValue = heightLimit
|
deviceSetting.value[DeviceSettingKeyEnum.HEIGHT_LIMIT_SET].value =
|
heightLimit + Unit_M
|
|
// 限远
|
let distanceLimitStatus = ""
|
if (isNil(device?.distance_limit_status?.state)) {
|
distanceLimitStatus = DEFAULT_PLACEHOLDER
|
deviceSetting.value[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].editable = false
|
deviceSetting.value[
|
DeviceSettingKeyEnum.DISTANCE_LIMIT_SET
|
].value = DEFAULT_PLACEHOLDER
|
} else {
|
deviceSetting.value[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].editable = true
|
distanceLimitStatus = device?.distance_limit_status?.state
|
if (distanceLimitStatus === DistanceLimitStatusEnum.UNSET) {
|
deviceSetting.value[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].value = "关闭"
|
} else if (distanceLimitStatus === DistanceLimitStatusEnum.SET) {
|
const distanceLimit = device?.distance_limit_status?.distance_limit
|
if (distanceLimit) {
|
deviceSetting.value[DeviceSettingKeyEnum.DISTANCE_LIMIT_SET].value =
|
distanceLimit + Unit_M
|
} else {
|
deviceSetting.value[
|
DeviceSettingKeyEnum.DISTANCE_LIMIT_SET
|
].value = DEFAULT_PLACEHOLDER
|
}
|
} else {
|
deviceSetting.value[
|
DeviceSettingKeyEnum.DISTANCE_LIMIT_SET
|
].value = DEFAULT_PLACEHOLDER
|
}
|
}
|
deviceSetting.value[
|
DeviceSettingKeyEnum.DISTANCE_LIMIT_SET
|
].trueValue = distanceLimitStatus
|
|
// 避障
|
if (isNil(device?.obstacle_avoidance)) {
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON
|
].editable = false
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON
|
].value = DEFAULT_PLACEHOLDER
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON
|
].trueValue = DEFAULT_PLACEHOLDER
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE
|
].editable = false
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE
|
].value = DEFAULT_PLACEHOLDER
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE
|
].trueValue = DEFAULT_PLACEHOLDER
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE
|
].editable = false
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE
|
].value = DEFAULT_PLACEHOLDER
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE
|
].trueValue = DEFAULT_PLACEHOLDER
|
} else {
|
const { horizon, upside, downside } = device.obstacle_avoidance || {}
|
if (isNil(horizon)) {
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON
|
].editable = false
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON
|
].value = DEFAULT_PLACEHOLDER
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON
|
].trueValue = DEFAULT_PLACEHOLDER
|
} else {
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON
|
].editable = false
|
if (horizon === ObstacleAvoidanceStatusEnum.CLOSE) {
|
deviceSetting.value[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].value =
|
"关闭"
|
} else if (horizon === ObstacleAvoidanceStatusEnum.OPEN) {
|
deviceSetting.value[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON].value =
|
"开启"
|
} else {
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON
|
].value = DEFAULT_PLACEHOLDER
|
}
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_HORIZON
|
].trueValue = horizon
|
}
|
|
if (isNil(upside)) {
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE
|
].editable = false
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE
|
].value = DEFAULT_PLACEHOLDER
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE
|
].trueValue = DEFAULT_PLACEHOLDER
|
} else {
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE
|
].editable = false
|
if (upside === ObstacleAvoidanceStatusEnum.CLOSE) {
|
deviceSetting.value[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].value =
|
"关闭"
|
} else if (upside === ObstacleAvoidanceStatusEnum.OPEN) {
|
deviceSetting.value[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE].value =
|
"开启"
|
} else {
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE
|
].value = DEFAULT_PLACEHOLDER
|
}
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_UPSIDE
|
].trueValue = upside
|
}
|
|
if (isNil(downside)) {
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE
|
].editable = false
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE
|
].value = DEFAULT_PLACEHOLDER
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE
|
].trueValue = DEFAULT_PLACEHOLDER
|
} else {
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE
|
].editable = false
|
if (downside === ObstacleAvoidanceStatusEnum.CLOSE) {
|
deviceSetting.value[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].value =
|
"关闭"
|
} else if (downside === ObstacleAvoidanceStatusEnum.OPEN) {
|
deviceSetting.value[DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE].value =
|
"开启"
|
} else {
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE
|
].value = DEFAULT_PLACEHOLDER
|
}
|
deviceSetting.value[
|
DeviceSettingKeyEnum.OBSTACLE_AVOIDANCE_DOWNSIDE
|
].trueValue = downside
|
}
|
}
|
return deviceSetting.value
|
}
|
|
// 更新formModel
|
export function updateDeviceSettingFormModelByOsd(
|
deviceSettingFormModelFromOsd,
|
deviceInfo
|
) {
|
// const { device, dock, gateway } = deviceInfo || {}
|
let device = deviceInfo?? {}
|
if (!deviceSettingFormModelFromOsd.value) {
|
return
|
}
|
// 夜航灯
|
const nightLightsState = device?.night_lights_state
|
if (
|
!isNil(nightLightsState) &&
|
nightLightsState === NightLightsStateEnum.OPEN
|
) {
|
deviceSettingFormModelFromOsd.value.nightLightsState = true
|
} else {
|
deviceSettingFormModelFromOsd.value.nightLightsState = false
|
}
|
|
// 限高
|
const heightLimit = device?.height_limit
|
if (isNil(heightLimit) || heightLimit === 0) {
|
deviceSettingFormModelFromOsd.value.heightLimit = 20
|
} else {
|
deviceSettingFormModelFromOsd.value.heightLimit = heightLimit
|
}
|
|
// 限远
|
const distanceLimitStatus = device?.distance_limit_status?.state
|
if (
|
!isNil(distanceLimitStatus) &&
|
distanceLimitStatus === DistanceLimitStatusEnum.SET
|
) {
|
deviceSettingFormModelFromOsd.value.distanceLimitStatus.state = true
|
deviceSettingFormModelFromOsd.value.distanceLimitStatus.distanceLimit =
|
device?.distance_limit_status?.distance_limit || 15
|
} else {
|
deviceSettingFormModelFromOsd.value.distanceLimitStatus.state = false
|
deviceSettingFormModelFromOsd.value.distanceLimitStatus.distanceLimit = 15
|
}
|
|
// 避障
|
if (isNil(device?.obstacle_avoidance)) {
|
deviceSettingFormModelFromOsd.value.obstacleAvoidanceHorizon = false
|
deviceSettingFormModelFromOsd.value.obstacleAvoidanceUpside = false
|
deviceSettingFormModelFromOsd.value.obstacleAvoidanceDownside = false
|
} else {
|
const { horizon, upside, downside } = device.obstacle_avoidance || {}
|
if (!isNil(horizon) && horizon === ObstacleAvoidanceStatusEnum.OPEN) {
|
deviceSettingFormModelFromOsd.value.obstacleAvoidanceHorizon = true
|
} else {
|
deviceSettingFormModelFromOsd.value.obstacleAvoidanceHorizon = false
|
}
|
if (!isNil(upside) && upside === ObstacleAvoidanceStatusEnum.OPEN) {
|
deviceSettingFormModelFromOsd.value.obstacleAvoidanceUpside = true
|
} else {
|
deviceSettingFormModelFromOsd.value.obstacleAvoidanceUpside = false
|
}
|
if (!isNil(downside) && downside === ObstacleAvoidanceStatusEnum.OPEN) {
|
deviceSettingFormModelFromOsd.value.obstacleAvoidanceDownside = true
|
} else {
|
deviceSettingFormModelFromOsd.value.obstacleAvoidanceDownside = false
|
}
|
}
|
return deviceSettingFormModelFromOsd.value
|
}
|