大疆上云api代码示例
<script lang="ts" setup>
import { computed, onMounted, reactive, ref, watch, WritableComputedRef } from 'vue'
import { EDeviceTypeName, ELocalStorageKey } from '/@/types'
import noData from '/@/assets/icons/no-data.png'
import rc from '/@/assets/icons/rc.png'
import { OnlineDevice, EModeCode, OSDVisible, EDockModeCode, DeviceOsd } from '/@/types/device'
import { useMyStore } from '/@/store'
import { getDeviceTopo, getUnreadDeviceHms, updateDeviceHms } from '/@/api/manage'
import { RocketOutlined, EyeInvisibleOutlined, EyeOutlined, RobotOutlined, DoubleRightOutlined } from '@ant-design/icons-vue'
import { EHmsLevel } from '/@/types/enums'
const store = useMyStore()
const username = ref(localStorage.getItem(ELocalStorageKey.Username))
const workspaceId = ref(localStorage.getItem(ELocalStorageKey.WorkspaceId)!)
const osdVisible = computed(() => store.state.osdVisible)
const hmsVisible = new Map<string, boolean>()
const scorllHeight = ref()
const onlineDevices = reactive({
data: [] as OnlineDevice[]
})
const onlineDocks = reactive({
data: [] as OnlineDevice[]
})
const deviceInfo = computed(() => store.state.deviceState.deviceInfo)
const dockInfo = computed(() => store.state.deviceState.dockInfo)
const hmsInfo = computed({
get: () => store.state.hmsInfo,
set: (val) => {
return val
}
})
onMounted(() => {
getOnlineTopo()
setTimeout(() => {
watch(() => store.state.deviceStatusEvent,
data => {
getOnlineTopo()
if (data.deviceOnline.sn) {
getUnreadHms(data.deviceOnline.sn)
}
},
{
deep: true
}
)
getOnlineDeviceHms()
}, 3000)
const element = document.getElementsByClassName('scrollbar').item(0) as HTMLDivElement
const parent = element?.parentNode as HTMLDivElement
scorllHeight.value = parent?.clientHeight - parent?.firstElementChild?.clientHeight
})
function getOnlineTopo () {
getDeviceTopo(workspaceId.value).then((res) => {
if (res.code !== 0) {
return
}
onlineDevices.data = []
onlineDocks.data = []
res.data.forEach((gateway: any) => {
const child = gateway.children
const device: OnlineDevice = {
model: child?.device_name,
callsign: child?.nickname,
sn: child?.device_sn,
mode: EModeCode.Disconnected,
gateway: {
model: gateway?.device_name,
callsign: gateway?.nickname,
sn: gateway?.device_sn,
domain: gateway?.domain
},
payload: []
}
child?.payloads_list.forEach((payload: any) => {
device.payload.push({
index: payload.index,
model: payload.model,
payload_name: payload.payload_name,
payload_sn: payload.payload_sn,
control_source: payload.control_source,
payload_index: payload.payload_index
})
})
if (EDeviceTypeName.Dock === gateway.domain) {
hmsVisible.set(device.sn, false)
hmsVisible.set(device.gateway.sn, false)
onlineDocks.data.push(device)
}
if (gateway.status && EDeviceTypeName.Gateway === gateway.domain) {
onlineDevices.data.push(device)
}
})
})
}
function switchVisible (e: any, device: OnlineDevice, isDock: boolean, isClick: boolean) {
if (!isClick) {
e.target.style.cursor = 'not-allowed'
return
}
if (device.sn === osdVisible.value.sn) {
osdVisible.value.visible = !osdVisible.value.visible
} else {
osdVisible.value.sn = device.sn
osdVisible.value.callsign = device.callsign
osdVisible.value.model = device.model
osdVisible.value.visible = true
osdVisible.value.gateway_sn = device.gateway.sn
osdVisible.value.is_dock = isDock
osdVisible.value.gateway_callsign = device.gateway.callsign
osdVisible.value.payloads = device.payload
}
store.commit('SET_OSD_VISIBLE_INFO', osdVisible)
}
function getUnreadHms (sn: string) {
getUnreadDeviceHms(workspaceId.value, sn).then(res => {
if (res.data.length !== 0) {
hmsInfo.value[sn] = res.data
}
})
console.info(hmsInfo.value)
}
function getOnlineDeviceHms () {
const snList = Object.keys(dockInfo.value)
if (snList.length === 0) {
return
}
snList.forEach(sn => {
getUnreadHms(sn)
})
const deviceSnList = Object.keys(deviceInfo.value)
if (deviceSnList.length === 0) {
return
}
deviceSnList.forEach(sn => {
getUnreadHms(sn)
})
}
function readHms (visiable: boolean, sn: string) {
if (!visiable) {
updateDeviceHms(workspaceId.value, sn).then(res => {
if (res.code === 0) {
delete hmsInfo.value[sn]
}
})
}
}
function openLivestreamOthers () {
store.commit('SET_LIVESTREAM_OTHERS_VISIBLE', true)
}
function openLivestreamAgora () {
store.commit('SET_LIVESTREAM_AGORA_VISIBLE', true)
}
</script>
没注释,功能模块混乱,二次开发的我忍不住吐槽一下