无人机管理后台前端(已迁走)
张含笑
2025-12-09 5808f76456ca0d40de5074f132b73a5a488e3e13
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
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
}