媒体库-左侧文件类型功能实装

main
滕嵩 2025-08-15 16:43:08 +08:00
parent 61fc2fac5a
commit c3bda54f50
4 changed files with 255 additions and 113 deletions

View File

@ -28,29 +28,33 @@
name: '媒体库',
children: [
{
id: 'allResource',
id: '',
name: '全部资源',
},
{
id: 'wideAngle',
name: '广角照片',
id: '1',
name: '可见光',
},
{
id: 'zoom',
id: '2',
name: '红外照片',
},
{
id: '3',
name: '变焦照片',
},
{
id: 'infrared',
name: '红外照片',
id: '4',
name: '广角照片',
},
// {
// id: 'alone',
// name: '',
// },
{
id: 'video',
id: '5',
name: '视频资源',
},
{
id: '0',
name: '其他文件',
},
],
},
];

View File

@ -22,7 +22,7 @@
</a-button>
<a-button :icon="h(ColumnHeightOutlined)" @click="moveFolderOrFile"></a-button>
<a-button :icon="h(DeleteOutlined)" @click="deleteFolderOrFile"> </a-button>
<!-- <a-button :icon="h(DownloadOutlined)" @click="compressFolderOrFile"></a-button> -->
<!-- <a-button :icon="h(DownloadOutlined)" @click="downloadFile"></a-button> -->
<a-radio-group v-model:value="tableType">
<a-radio-button value="table"><BarsOutlined /></a-radio-button>
<a-radio-button value="store"><AppstoreOutlined /></a-radio-button>
@ -335,6 +335,8 @@
import { columns, searchFormSchema } from './modal.data';
import dayjs from 'dayjs';
import { cloneDeep } from 'lodash-es';
import JSZip from 'jszip';
import { saveAs } from 'file-saver';
const { VITE_GLOB_MEDIALIBRARY_IMAGE_URL } = getAppEnvConfig();
const { createConfirm, createMessage } = useMessage();
@ -348,88 +350,98 @@
const tableHeight: any = ref(0);
watch(
() => tableType.value,
(newval) => {
//
if (newval === 'store') {
//
let query = { ...searchParams.value, page: 1, limit: 1000 };
if (routeFlag.value) {
query = {
...query,
taskId: route.query.flightId,
objectKeyExist: 1,
};
} else {
query = {
...query,
parentKey: nowParentKey.value,
};
}
GetMediaFile(query).then((res) => {
showTableData.value = res.items;
tableTypeAfterShow.value = newval;
// -
const containers = document.querySelectorAll('.ant-table-container');
tableHeight.value = containers[0] ? containers[0]?.scrollHeight : 0;
if (containers) {
containers.forEach((container) => {
container.style.display = 'none';
});
}
// -
const paginations = document.querySelectorAll('.ant-pagination');
if (paginations) {
paginations.forEach((pagination) => {
pagination.style.display = 'none';
});
}
//
let selectRowsIdArray = getSelectRows().map((item) => item.id);
showTableData.value.forEach((item) => {
if (selectRowsIdArray.includes(item.id)) {
item.checked = true;
changeStore(
{
target: {
checked: true,
},
},
item,
);
}
});
});
}
//
if (newval === 'table') {
reload().then((res) => {
tableTypeAfterShow.value = newval;
// -
const containers = document.querySelectorAll('.ant-table-container');
tableHeight.value = containers[0] ? containers[0]?.scrollHeight : 0;
if (containers) {
containers.forEach((container) => {
container.style.display = 'block';
});
}
// -
const paginations = document.querySelectorAll('.ant-pagination');
if (paginations) {
paginations.forEach((pagination) => {
pagination.style.display = 'block';
});
}
//
let selectRowsIdArray = showTableData.value.filter((item) => item.checked);
setSelectedRows(selectRowsIdArray);
});
}
() => {
//
getShowTableData();
},
);
function getShowTableData() {
//
if (tableType.value === 'store') {
//
let query = { ...searchParams.value, page: 1, limit: 1000 };
if (routeFlag.value) {
query = {
...query,
taskId: route.query.flightId,
objectKeyExist: 1,
};
} else {
query = {
...query,
//
parentKey: searchInfo.type
? nowParentKey.value == '0'
? ''
: nowParentKey.value
: nowParentKey.value,
type: searchInfo.type,
};
}
GetMediaFile(query).then((res) => {
showTableData.value = res.items;
tableTypeAfterShow.value = tableType.value;
// -
const containers = document.querySelectorAll('.ant-table-container');
tableHeight.value = containers[0] ? containers[0]?.scrollHeight : 0;
if (containers) {
containers.forEach((container) => {
container.style.display = 'none';
});
}
// -
const paginations = document.querySelectorAll('.ant-pagination');
if (paginations) {
paginations.forEach((pagination) => {
pagination.style.display = 'none';
});
}
//
let selectRowsIdArray = getSelectRows().map((item) => item.id);
showTableData.value.forEach((item) => {
if (selectRowsIdArray.includes(item.id)) {
item.checked = true;
changeStore(
{
target: {
checked: true,
},
},
item,
);
}
});
});
}
//
if (tableType.value === 'table') {
reload().then((res) => {
tableTypeAfterShow.value = tableType.value;
// -
const containers = document.querySelectorAll('.ant-table-container');
tableHeight.value = containers[0] ? containers[0]?.scrollHeight : 0;
if (containers) {
containers.forEach((container) => {
container.style.display = 'block';
});
}
// -
const paginations = document.querySelectorAll('.ant-pagination');
if (paginations) {
paginations.forEach((pagination) => {
pagination.style.display = 'block';
});
}
//
let selectRowsIdArray = showTableData.value.filter((item) => item.checked);
setSelectedRows(selectRowsIdArray);
});
}
}
//
const checkNameChecked = ref(false);
// or
// or-
function changeStore(e, record) {
if (typeof record == 'string') {
if (e.target.checked) {
@ -545,7 +557,12 @@
...data,
page: tableTypeAfterShow.value == 'table' ? data.page : 1,
limit: tableTypeAfterShow.value == 'table' ? data.limit : 1000,
parentKey: nowParentKey.value,
//
parentKey: searchInfo.type
? nowParentKey.value == '0'
? ''
: nowParentKey.value
: nowParentKey.value,
};
return temp;
}
@ -606,9 +623,15 @@
// ----------------------------------------------------------------------
//
function handleSelect(orgId = '') {
searchInfo.orgId = orgId;
reload();
function handleSelect(type = '') {
searchInfo.type = type;
//
if (tableType.value == 'table') {
reload();
} else {
//
getShowTableData();
}
}
//
const childRef = ref<any>();
@ -641,7 +664,13 @@
} else {
query = {
...query,
parentKey: nowParentKey.value,
//
parentKey: searchInfo.type
? nowParentKey.value == '0'
? ''
: nowParentKey.value
: nowParentKey.value,
type: searchInfo.type,
};
}
GetMediaFile(query).then((res) => {
@ -725,6 +754,86 @@
});
}
//
async function downloadFile() {
//
let rows = getSelectRows();
if (tableType.value == 'store') {
rows = showTableData.value.filter((item) => item.checked);
}
getFileList(rows).then(async (res) => {
let filelist: any = res;
console.log(res);
const token = localStorage.getItem('X-Token');
const zip = new JSZip();
// ZIP
for (const file of filelist) {
try {
const response = await fetch(file.url + '?t=' + Date.now(), {
headers: {
Authorization: `Bearer ${token}`,
},
mode: 'cors',
});
if (!response.ok) {
throw new Error(`HTTP 错误: ${response.status} - ${response.statusText}`);
}
const blob = await response.blob();
zip.file(`${file.path}/${file.name}`, blob, { binary: true });
} catch (error) {
console.error('请求失败:', error);
}
}
// ZIP
let zipFileName = '压缩文件';
try {
const blob = await zip.generateAsync({ type: 'blob' });
saveAs(blob, zipFileName + '.zip'); // ZIP
} catch (error) {
console.error('生成ZIP文件时出错:', error);
}
});
}
async function getFileList(rows) {
let fileList: any = [];
let num = 0;
rows.forEach(async (item) => {
if (item.objectKey) {
fileList.push({
name: item.name,
url: VITE_GLOB_MEDIALIBRARY_IMAGE_URL + item.objectKey,
path: '',
});
num++;
if (rows.length == num) {
console.log(fileList);
return fileList;
}
} else {
await GetMediaFile({
parentKey: item.id,
page: 1,
limit: 1000,
}).then((res) => {
res.items.forEach(async (r) => {
fileList.push({
name: r.name,
url: VITE_GLOB_MEDIALIBRARY_IMAGE_URL + r.objectKey,
path: item.name,
});
});
num++;
if (rows.length == num) {
console.log(fileList);
return fileList;
}
});
}
});
}
// ----------------------------------------------------------------------------
const openPreview = ref(false);
//
@ -746,7 +855,13 @@
} else {
query = {
...query,
parentKey: nowParentKey.value,
//
parentKey: searchInfo.type
? nowParentKey.value == '0'
? ''
: nowParentKey.value
: nowParentKey.value,
type: searchInfo.type,
};
}
GetMediaFile(query).then((res) => {
@ -773,6 +888,9 @@
showTableData.value = res;
});
}
setTimeout(() => {
clearSelectedRowKeys();
}, 500);
}
function uniqueByKey(arrlist, record) {
let resultList: any = [];
@ -851,7 +969,13 @@
} else {
query = {
...query,
parentKey: nowParentKey.value,
//
parentKey: searchInfo.type
? nowParentKey.value == '0'
? ''
: nowParentKey.value
: nowParentKey.value,
type: searchInfo.type,
};
}
GetMediaFile(query).then((res) => {

View File

@ -192,24 +192,20 @@
const imageTypeSelect = ref([]);
const imageOptions: any = ref([
{
value: '广角照片',
label: '广角照片',
value: 1,
label: '可见光照片',
},
{
value: '变焦照片',
label: '变焦照片',
},
{
value: '红外照片',
value: 2,
label: '红外照片',
},
{
value: '全景图',
label: '全景图',
value: 3,
label: '变焦照片',
},
{
value: '码流截图',
label: '码流截图',
value: 4,
label: '广角照片',
},
]);
//
@ -223,11 +219,9 @@
});
}
//
// if (tagSelect.value.length > 0) {
// imageTypeSelect.value.forEach((imagetype) => {
// filterImageData = filterImageData.filter((item) => item.fileTags.includes(imagetype));
// });
// }
if (imageTypeSelect.value.length > 0) {
filterImageData = filterImageData.filter((item) => imageTypeSelect.value.includes(item.type));
}
//
if (searchValue.value) {
filterImageData = filterImageData.filter((item) => item.name.includes(searchValue.value));

View File

@ -21,7 +21,7 @@
<span class="infotitle">照片类型</span>
</a-col>
<a-col :span="17">
<span class="infovalue">{{ props.nowPreviewRecord.imgtype || '--' }} </span>
<span class="infovalue">{{ getImageType(props.nowPreviewRecord.type) || '--' }} </span>
</a-col>
<a-col :span="7">
<span class="infotitle">任务名称</span>
@ -266,6 +266,26 @@
editName.value = props.nowPreviewRecord.name.split('.').slice(0, -1).join('.');
}
//
function getImageType(type) {
let imageType = '';
switch (type) {
case 1:
imageType = '可见光照片';
break;
case 2:
imageType = '红外照片';
break;
case 3:
imageType = '变焦照片';
break;
case 4:
imageType = '广角照片';
break;
}
return imageType;
}
// --------------------------------
const addFileTagsFlag = ref(false);
const newFileTagsName = ref('');