MediaPanel.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div class="header">照片视频</div>
  3. <a-spin :spinning="loading" :delay="1000" tip="downloading" size="large">
  4. <div class="media-panel-wrapper">
  5. <a-table class="media-table" :columns="columns" :data-source="mediaData.data" row-key="fingerprint"
  6. :pagination="paginationProp" :scroll="{ x: '100%', y: 600 }" @change="refreshData">
  7. <template v-for="col in ['name', 'path']" #[col]="{ text }" :key="col">
  8. <a-tooltip :title="text">
  9. <a v-if="col === 'name'">{{ text }}</a>
  10. <span v-else>{{ text }}</span>
  11. </a-tooltip>
  12. </template>
  13. <template #original="{ text }">
  14. {{ text }}
  15. </template>
  16. <template #action="{ record }">
  17. <a-tooltip title="download">
  18. <a class="fz18" @click="downloadMedia(record)">
  19. <DownloadOutlined />
  20. </a>
  21. </a-tooltip>
  22. </template>
  23. </a-table>
  24. </div>
  25. </a-spin>
  26. </template>
  27. <script setup lang="ts">
  28. import { onMounted, reactive, ref } from 'vue'
  29. import { Pagination } from 'ant-design-vue'
  30. import { TableState } from 'ant-design-vue/lib/table/interface'
  31. import { IPage } from '../api/http/type'
  32. import { downloadFile } from '../utils/common'
  33. import { downloadMediaFile, getMediaFiles } from '/@/api/media'
  34. import { DownloadOutlined } from '@ant-design/icons-vue'
  35. import { getWorkspaceId } from '/@/utils/index';
  36. const loading = ref(false)
  37. const columns = [
  38. {
  39. title: '文件名称',
  40. dataIndex: 'file_name',
  41. ellipsis: true,
  42. slots: { customRender: 'name' }
  43. },
  44. {
  45. title: '目录',
  46. dataIndex: 'file_path',
  47. ellipsis: true,
  48. slots: { customRender: 'path' }
  49. },
  50. {
  51. title: '设备',
  52. dataIndex: 'drone'
  53. },
  54. {
  55. title: '拍摄负载',
  56. dataIndex: 'payload'
  57. },
  58. {
  59. title: '原图',
  60. dataIndex: 'is_original',
  61. slots: { customRender: 'original' }
  62. },
  63. {
  64. title: '上传时间',
  65. dataIndex: 'create_time'
  66. },
  67. {
  68. title: '下载',
  69. slots: { customRender: 'action' }
  70. }
  71. ]
  72. const body: IPage = {
  73. page: 1,
  74. total: 0,
  75. page_size: 50
  76. }
  77. const paginationProp = reactive({
  78. pageSizeOptions: ['20', '50', '100'],
  79. showQuickJumper: true,
  80. showSizeChanger: true,
  81. pageSize: 50,
  82. current: 1,
  83. total: 0
  84. })
  85. type Pagination = TableState['pagination']
  86. interface MediaFile {
  87. fingerprint: string,
  88. drone: string,
  89. payload: string,
  90. is_original: string,
  91. file_name: string,
  92. file_path: string,
  93. create_time: string,
  94. file_id: string,
  95. }
  96. const mediaData = reactive({
  97. data: [] as MediaFile[]
  98. })
  99. onMounted(() => {
  100. getFiles()
  101. })
  102. function getFiles() {
  103. getMediaFiles(getWorkspaceId(), body).then(res => {
  104. mediaData.data = res.data.list
  105. paginationProp.total = res.data.pagination.total
  106. paginationProp.current = res.data.pagination.page
  107. console.info(mediaData.data[0])
  108. })
  109. }
  110. function refreshData(page: Pagination) {
  111. body.page = page?.current!
  112. body.page_size = page?.pageSize!
  113. getFiles()
  114. }
  115. function downloadMedia(media: MediaFile) {
  116. loading.value = true
  117. downloadMediaFile(getWorkspaceId(), media.file_id).then(res => {
  118. if (!res) {
  119. return
  120. }
  121. const data = new Blob([res])
  122. downloadFile(data, media.file_name)
  123. }).finally(() => {
  124. loading.value = false
  125. })
  126. }
  127. </script>
  128. <style lang="scss" scoped>
  129. .media-panel-wrapper {
  130. width: 100%;
  131. padding: 16px;
  132. .media-table {
  133. background: #fff;
  134. margin-top: 10px;
  135. }
  136. .action-area {
  137. color: $primary;
  138. cursor: pointer;
  139. }
  140. }
  141. .header {
  142. width: 100%;
  143. height: 60px;
  144. background: #fff;
  145. padding: 16px;
  146. font-size: 20px;
  147. font-weight: bold;
  148. text-align: start;
  149. color: #000;
  150. }
  151. </style>