dock.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 { onMounted, reactive, ref } from 'vue'
  37. import { deleteWaylineFile, downloadWaylineFile, getWaylineFiles } from '/@/api/wayline'
  38. import { EDeviceTypeName, ELocalStorageKey } from '/@/types'
  39. import { RocketOutlined } from '@ant-design/icons-vue'
  40. import { Device } from '/@/types/device'
  41. import { useMyStore } from '/@/store'
  42. import { getBindingDevices } from '/@/api/manage'
  43. import { IPage } from '/@/api/http/type'
  44. const store = useMyStore()
  45. const docksData = reactive({
  46. data: [] as Device[]
  47. })
  48. const workspaceId = localStorage.getItem(ELocalStorageKey.WorkspaceId)!
  49. const scorllHeight = ref()
  50. const canRefresh = ref(true)
  51. onMounted(() => {
  52. const parent = document.getElementsByClassName('scrollbar').item(0)?.parentNode as HTMLDivElement
  53. scorllHeight.value = document.body.clientHeight - parent.firstElementChild!.clientHeight
  54. getDocks()
  55. const key = setInterval(() => {
  56. const data = document.getElementById('data')?.lastElementChild as HTMLDivElement
  57. if (body.total === 0 || Math.ceil(body.total / body.page_size) <= body.page || scorllHeight.value + 50 <= data?.clientHeight + data?.offsetTop) {
  58. clearInterval(key)
  59. return
  60. }
  61. body.page++
  62. getDocks()
  63. }, 1000)
  64. })
  65. const body: IPage = {
  66. page: 1,
  67. total: -1,
  68. page_size: 10,
  69. }
  70. async function getDocks() {
  71. if (!canRefresh.value) {
  72. return
  73. }
  74. canRefresh.value = false
  75. await getBindingDevices(workspaceId, body, EDeviceTypeName.Dock).then(res => {
  76. if (res.code !== 0) {
  77. return
  78. }
  79. docksData.data.push(...res.data.list)
  80. body.page = res.data.pagination.page
  81. body.page_size = res.data.pagination.page_size
  82. body.total = res.data.pagination.total
  83. }).finally(() => {
  84. canRefresh.value = true
  85. })
  86. }
  87. function onScroll(e: any) {
  88. const element = e.srcElement
  89. if (element.scrollTop + element.clientHeight >= element.scrollHeight - 5 && Math.ceil(body.total / body.page_size) > body.page && canRefresh.value) {
  90. body.page++
  91. getDocks()
  92. }
  93. }
  94. function selectDock(dock: Device) {
  95. store.commit('SET_SELECT_DOCK_INFO', dock)
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. .panel {
  100. background: #3c3c3c;
  101. margin-left: auto;
  102. margin-right: auto;
  103. margin-top: 10px;
  104. height: 70px;
  105. width: 95%;
  106. font-size: 13px;
  107. border-radius: 2px;
  108. cursor: pointer;
  109. .title {
  110. display: flex;
  111. flex-direction: row;
  112. align-items: center;
  113. height: 30px;
  114. font-weight: bold;
  115. margin: 0px 10px 0 10px;
  116. }
  117. }
  118. .uranus-scrollbar {
  119. overflow: auto;
  120. scrollbar-width: thin;
  121. scrollbar-color: #c5c8cc transparent;
  122. height: 100%;
  123. }
  124. </style>