开源软件列表导出接口对接
This commit is contained in:
@@ -241,3 +241,15 @@ export const getGroupSubscribeList = (data): Promise<any> => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 搜索结果导出接口
|
||||||
|
export const getReleaseExport = (data): Promise<any> => {
|
||||||
|
return reqCatchV2(() =>
|
||||||
|
request({
|
||||||
|
url: `/api/v1/repo/release/export`,
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
responseType: 'blob' // 关键:告诉axios这是二进制数据
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@
|
|||||||
<a @click="gotoDetail(scope.row)">{{ scope.row.version }}</a>
|
<a @click="gotoDetail(scope.row)">{{ scope.row.version }}</a>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="column.key === 'releaseDate'">
|
<template v-else-if="column.key === 'releaseDate'">
|
||||||
<span>{{ formatTime(scope.row.releaseDate, 'YYYY-MM-DD') }}</span>
|
<span>{{ formatTime(scope.row.releaseDate, 'YYYY-MM-DD HH:mm:ss') }}</span>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="column.key === 'softwareVersion'">
|
<template v-else-if="column.key === 'softwareVersion'">
|
||||||
<a @click="gotoDetail(scope.row)">{{ scope.row.softwareVersion }}</a>
|
<a @click="gotoDetail(scope.row)">{{ scope.row.softwareVersion }}</a>
|
||||||
@@ -207,7 +207,7 @@ import NoData from '@/components/NoData/NoData.vue';
|
|||||||
import { useAccountStore } from '@/stores/user';
|
import { useAccountStore } from '@/stores/user';
|
||||||
import * as XLSX from 'xlsx';
|
import * as XLSX from 'xlsx';
|
||||||
const { formatTime } = useTimeFormat();
|
const { formatTime } = useTimeFormat();
|
||||||
import { releasePage, searchLanguageList } from '@/api/jyh';
|
import { getReleaseExport, releasePage, searchLanguageList } from '@/api/jyh';
|
||||||
import { useTimeFormat } from '@/utils/hooks/useTimeFormat';
|
import { useTimeFormat } from '@/utils/hooks/useTimeFormat';
|
||||||
import { useGlobalInfoStore } from '@/stores/Global';
|
import { useGlobalInfoStore } from '@/stores/Global';
|
||||||
|
|
||||||
@@ -503,6 +503,57 @@ onMounted(async () => {
|
|||||||
// getReleaseList();
|
// getReleaseList();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const exportResult = async () => {
|
||||||
|
const { data, error } = await getReleaseExport({
|
||||||
|
softwareName: newFormData.value.softwareName || '',
|
||||||
|
searchType: newFormData.value.searchType || '',
|
||||||
|
softwareVersion: newFormData.value.softwareVersion || '',
|
||||||
|
programmingLanguage: newFormData.value.programmingLanguage || '',
|
||||||
|
interestTag: newFormData.value.interestTag || '',
|
||||||
|
industry: newFormData.value.industry || '',
|
||||||
|
licenseName: newFormData.value.licenseName || '',
|
||||||
|
dependentSoftware: newFormData.value.dependentSoftware || '',
|
||||||
|
releaseDateStart:
|
||||||
|
newFormData.value.dateRange && newFormData.value.dateRange.length > 0 ? newFormData.value.dateRange[0] : '',
|
||||||
|
releaseDateEnd:
|
||||||
|
newFormData.value.dateRange && newFormData.value.dateRange.length > 0 ? newFormData.value.dateRange[1] : '',
|
||||||
|
current: pager.value.pageIndex,
|
||||||
|
size: pager.value.pageSize
|
||||||
|
});
|
||||||
|
if (data && !error) {
|
||||||
|
debugger
|
||||||
|
// 方法1:如果后端返回的是文件流(Blob)
|
||||||
|
const blob = new Blob([data.data]);
|
||||||
|
const downloadUrl = window.URL.createObjectURL(blob);
|
||||||
|
|
||||||
|
// 创建一个临时的a标签触发下载
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = downloadUrl;
|
||||||
|
|
||||||
|
// 从Content-Disposition头中获取文件名,或者使用默认文件名
|
||||||
|
const contentDisposition = data.headers['content-disposition'];
|
||||||
|
let fileName = 'export.xlsx'; // 默认文件名
|
||||||
|
if (contentDisposition) {
|
||||||
|
const fileNameMatch = contentDisposition.match(/filename="?(.+)"?/);
|
||||||
|
if (fileNameMatch && fileNameMatch[1]) {
|
||||||
|
fileName = fileNameMatch[1].replace(/^[^0-9]*|[^0-9.xlsx]*$/g, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
link.setAttribute('download', fileName);
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
|
||||||
|
// 清理
|
||||||
|
document.body.removeChild(link);
|
||||||
|
window.URL.revokeObjectURL(downloadUrl);
|
||||||
|
} else {
|
||||||
|
console.error('导出失败:', error);
|
||||||
|
// 这里可以添加错误提示,比如使用Element Plus的ElMessage
|
||||||
|
ElMessage.error('文件导出失败');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// onMounted(() => {
|
// onMounted(() => {
|
||||||
// const query: any = route.query;
|
// const query: any = route.query;
|
||||||
// newFormData.value = {
|
// newFormData.value = {
|
||||||
@@ -510,47 +561,47 @@ onMounted(async () => {
|
|||||||
// };
|
// };
|
||||||
// });
|
// });
|
||||||
|
|
||||||
const exportResult = () => {
|
// const exportResult = () => {
|
||||||
const selectDatas = filterTableRef.value.store.getCheckedRows().map((d) => d.id);
|
// const selectDatas = filterTableRef.value.store.getCheckedRows().map((d) => d.id);
|
||||||
if (!allTableData.value.length || selectDatas.length <= 0) {
|
// if (!allTableData.value.length || selectDatas.length <= 0) {
|
||||||
Message.info('未选择任何数据');
|
// Message.info('未选择任何数据');
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
const exportData = allTableData.value
|
// const exportData = allTableData.value
|
||||||
.filter((d) => {
|
// .filter((d) => {
|
||||||
return selectDatas.includes(d.id);
|
// return selectDatas.includes(d.id);
|
||||||
})
|
// })
|
||||||
.map((item) => {
|
// .map((item) => {
|
||||||
let res = {};
|
// let res = {};
|
||||||
columns.value.forEach((col) => {
|
// columns.value.forEach((col) => {
|
||||||
if (col.key === 'validStatus') {
|
// if (col.key === 'validStatus') {
|
||||||
res[col.label] = validStatusMap[item[col.key]] ? validStatusMap[item[col.key]] : '';
|
// res[col.label] = validStatusMap[item[col.key]] ? validStatusMap[item[col.key]] : '';
|
||||||
} else {
|
// } else {
|
||||||
res[col.label] = item[col.key] ? item[col.key] : '';
|
// res[col.label] = item[col.key] ? item[col.key] : '';
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
return res;
|
// return res;
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
const workSheet = XLSX.utils.json_to_sheet(exportData);
|
// const workSheet = XLSX.utils.json_to_sheet(exportData);
|
||||||
const workBook: any = { Sheets: { 校验结果: workSheet }, SheetNames: ['校验结果'] };
|
// const workBook: any = { Sheets: { 校验结果: workSheet }, SheetNames: ['校验结果'] };
|
||||||
const excelBuffer = XLSX.write(workBook, { bookType: 'xlsx', type: 'array' });
|
// const excelBuffer = XLSX.write(workBook, { bookType: 'xlsx', type: 'array' });
|
||||||
|
//
|
||||||
const link = document.createElement('a');
|
// const link = document.createElement('a');
|
||||||
const blob = new Blob([excelBuffer]);
|
// const blob = new Blob([excelBuffer]);
|
||||||
link.setAttribute('href', window.URL.createObjectURL(blob));
|
// link.setAttribute('href', window.URL.createObjectURL(blob));
|
||||||
link.setAttribute('download', '软件存在及可信校验结果.xlsx');
|
// link.setAttribute('download', '软件存在及可信校验结果.xlsx');
|
||||||
link.style.visibility = 'hidden';
|
// link.style.visibility = 'hidden';
|
||||||
document.body.appendChild(link);
|
// document.body.appendChild(link);
|
||||||
link.click();
|
// link.click();
|
||||||
document.body.removeChild(link);
|
// document.body.removeChild(link);
|
||||||
Message.success('导出成功');
|
// Message.success('导出成功');
|
||||||
} catch {
|
// } catch {
|
||||||
Message.error('导出失败');
|
// Message.error('导出失败');
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|||||||
Reference in New Issue
Block a user