dock.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="height-100">
  3. <div style="height: 50px; line-height: 50px; border-bottom: 1px solid #4f4f4f; font-weight: 450;">
  4. <a-row>
  5. <a-col :span="1"></a-col>
  6. <a-col :span="22">Devices</a-col>
  7. <a-col :span="1"></a-col>
  8. </a-row>
  9. </div>
  10. <div class="scrollbar height-100" :style="{ height: scorllHeight + 'px' }">
  11. <div id="data" class=" uranus-scrollbar" v-if="docksData.data.length !== 0" @scroll="onScroll">
  12. <div v-for="dock in docksData.data" :key="dock.device_sn">
  13. <div class="panel" style="padding-top: 5px;" @click="selectDock(dock)">
  14. <div class="title">
  15. <a-tooltip :title="dock.nickname">
  16. <div class="pr10" style="width: 120px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden;">
  17. {{ dock.nickname }}</div>
  18. </a-tooltip>
  19. </div>
  20. <div class="ml10 mt5" style="color: hsla(0,0%,100%,0.65);">
  21. <span>
  22. <RocketOutlined />
  23. </span>
  24. <span class="ml5">{{ dock.children?.nickname ?? 'No drone' }}</span>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. <div v-else>
  30. <a-empty :image-style="{ height: '60px', marginTop: '60px' }" />
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script lang="ts" setup>
  36. import { message } from 'ant-design-vue'
  37. import { onMounted, reactive, ref } from 'vue'
  38. import { deleteWaylineFile, downloadWaylineFile, getWaylineFiles } from '/@/api/wayline'
  39. import { EDeviceTypeName, ELocalStorageKey } from '/@/types'
  40. import { EllipsisOutlined, RocketOutlined, CameraFilled, UserOutlined } from '@ant-design/icons-vue'
  41. import { Device } from '/@/types/device'
  42. import { useMyStore } from '/@/store'
  43. import { getBindingDevices } from '/@/api/manage'
  44. import { IPage } from '/@/api/http/type'
  45. const store = useMyStore()
  46. const docksData = reactive({
  47. data: [] as Device[]
  48. })
  49. const workspaceId = localStorage.getItem(ELocalStorageKey.WorkspaceId)!
  50. const scorllHeight = ref()
  51. const canRefresh = ref(true)
  52. onMounted(() => {
  53. const parent = document.getElementsByClassName('scrollbar').item(0)?.parentNode as HTMLDivElement
  54. scorllHeight.value = document.body.clientHeight - parent.firstElementChild!.clientHeight
  55. getDocks()
  56. const key = setInterval(() => {
  57. const data = document.getElementById('data')?.lastElementChild as HTMLDivElement
  58. if (body.total === 0 || Math.ceil(body.total / body.page_size) <= body.page || scorllHeight.value + 50 <= data?.clientHeight + data?.offsetTop) {
  59. clearInterval(key)
  60. return
  61. }
  62. body.page++
  63. getDocks()
  64. }, 1000)
  65. })
  66. const body: IPage = {
  67. page: 1,
  68. total: -1,
  69. page_size: 10,
  70. }
  71. async function getDocks() {
  72. if (!canRefresh.value) {
  73. return
  74. }
  75. canRefresh.value = false
  76. await getBindingDevices(workspaceId, body, EDeviceTypeName.Dock).then(res => {
  77. if (res.code !== 0) {
  78. return
  79. }
  80. docksData.data.push(...res.data.list)
  81. body.page = res.data.pagination.page
  82. body.page_size = res.data.pagination.page_size
  83. body.total = res.data.pagination.total
  84. }).finally(() => {
  85. canRefresh.value = true
  86. })
  87. }
  88. function onScroll(e: any) {
  89. const element = e.srcElement
  90. if (element.scrollTop + element.clientHeight >= element.scrollHeight - 5 && Math.ceil(body.total / body.page_size) > body.page && canRefresh.value) {
  91. body.page++
  92. getDocks()
  93. }
  94. }
  95. function selectDock(dock: Device) {
  96. store.commit('SET_SELECT_DOCK_INFO', dock)
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .panel {
  101. background: #3c3c3c;
  102. margin-left: auto;
  103. margin-right: auto;
  104. margin-top: 10px;
  105. height: 70px;
  106. width: 95%;
  107. font-size: 13px;
  108. border-radius: 2px;
  109. cursor: pointer;
  110. .title {
  111. display: flex;
  112. flex-direction: row;
  113. align-items: center;
  114. height: 30px;
  115. font-weight: bold;
  116. margin: 0px 10px 0 10px;
  117. }
  118. }
  119. .uranus-scrollbar {
  120. overflow: auto;
  121. scrollbar-width: thin;
  122. scrollbar-color: #c5c8cc transparent;
  123. height: 100%;
  124. }
  125. </style>