You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
3.9 KiB

3 years ago
<template>
3 years ago
<div class="header">Media Files</div>
<a-spin :spinning="loading" :delay="1000" tip="downloading" size="large">
<div class="media-panel-wrapper">
<a-table class="media-table" :columns="columns" :data-source="mediaData.data" row-key="fingerprint"
:pagination="paginationProp" :scroll="{ x: '100%', y: 600 }" @change="refreshData">
<template v-for="col in ['name', 'path']" #[col]="{ text }" :key="col">
<a-tooltip :title="text">
<a v-if="col === 'name'">{{ text }}</a>
<span v-else>{{ text }}</span>
</a-tooltip>
</template>
<template #original="{ text }">
{{ text }}
</template>
<template #action="{ record }">
<a-tooltip title="download">
<a class="fz18" @click="downloadMedia(record)"><DownloadOutlined /></a>
</a-tooltip>
</template>
</a-table>
</div>
</a-spin>
3 years ago
</template>
<script setup lang="ts">
import { ref } from '@vue/reactivity'
3 years ago
import { TableState } from 'ant-design-vue/lib/table/interface'
import { onMounted, reactive } from 'vue'
import { IPage } from '../api/http/type'
import { ELocalStorageKey } from '../types/enums'
import { downloadFile } from '../utils/common'
import { downloadMediaFile, getMediaFiles } from '/@/api/media'
import { DownloadOutlined } from '@ant-design/icons-vue'
import { Pagination } from 'ant-design-vue'
import { load } from '@amap/amap-jsapi-loader'
const workspaceId = localStorage.getItem(ELocalStorageKey.WorkspaceId)!
const loading = ref(false)
3 years ago
const columns = [
{
3 years ago
title: 'File Name',
dataIndex: 'file_name',
ellipsis: true,
3 years ago
slots: { customRender: 'name' }
},
{
3 years ago
title: 'File Path',
dataIndex: 'file_path',
ellipsis: true,
slots: { customRender: 'path' }
},
// {
// title: 'FileSize',
// dataIndex: 'size',
// },
{
title: 'Drone',
dataIndex: 'drone'
},
{
title: 'Payload Type',
dataIndex: 'payload'
},
{
title: 'Original',
dataIndex: 'is_original',
slots: { customRender: 'original' }
3 years ago
},
{
3 years ago
title: 'Created',
dataIndex: 'create_time'
3 years ago
},
{
title: 'Action',
slots: { customRender: 'action' }
}
]
3 years ago
const body: IPage = {
page: 1,
total: 0,
page_size: 50
}
const paginationProp = reactive({
pageSizeOptions: ['20', '50', '100'],
showQuickJumper: true,
showSizeChanger: true,
pageSize: 50,
current: 1,
total: 0
})
type Pagination = TableState['pagination']
interface MediaFile {
fingerprint: string,
drone: string,
payload: string,
is_original: string,
file_name: string,
file_path: string,
create_time: string,
}
const mediaData = reactive({
data: [] as MediaFile[]
})
onMounted(() => {
getFiles()
})
function getFiles () {
getMediaFiles(workspaceId, body).then(res => {
mediaData.data = res.data.list
paginationProp.total = res.data.pagination.total
paginationProp.current = res.data.pagination.page
console.info(mediaData.data[0])
3 years ago
})
}
3 years ago
function refreshData (page: Pagination) {
body.page = page?.current!
body.page_size = page?.pageSize!
getFiles()
}
function downloadMedia (media: MediaFile) {
loading.value = true
downloadMediaFile(workspaceId, media.fingerprint).then(res => {
if (res.code && res.code !== 0) {
return
}
const suffix = media.file_name.substring(media.file_name.lastIndexOf('.'))
const data = new Blob([res.data], { type: suffix === '.mp4' ? 'video/mp4' : 'image/jpeg' })
downloadFile(data, media.file_name)
}).finally(() => {
loading.value = false
})
}
3 years ago
</script>
<style lang="scss" scoped>
.media-panel-wrapper {
width: 100%;
3 years ago
padding: 16px;
3 years ago
.media-table {
background: #fff;
3 years ago
margin-top: 10px;
3 years ago
}
.action-area {
color: $primary;
cursor: pointer;
}
}
3 years ago
.header {
width: 100%;
height: 60px;
background: #fff;
padding: 16px;
font-size: 20px;
font-weight: bold;
text-align: start;
color: #000;
}
3 years ago
</style>