可信代码库-开源软件列表调用导出接口

This commit is contained in:
付民康
2025-03-31 17:12:11 +08:00
parent c818b7556e
commit de237799c7

View File

@@ -512,56 +512,56 @@ onMounted(async () => {
// getReleaseList(); // getReleaseList();
}); });
// const exportResult = async () => { const exportResult = async () => {
// const { data, error } = await getReleaseExport({ const { data, error } = await getReleaseExport({
// softwareName: newFormData.value.softwareName || '', softwareName: newFormData.value.softwareName || '',
// searchType: newFormData.value.searchType || '', searchType: newFormData.value.searchType || '',
// softwareVersion: newFormData.value.softwareVersion || '', softwareVersion: newFormData.value.softwareVersion || '',
// programmingLanguage: newFormData.value.programmingLanguage || '', programmingLanguage: newFormData.value.programmingLanguage || '',
// interestTag: newFormData.value.interestTag || '', interestTag: newFormData.value.interestTag || '',
// industry: newFormData.value.industry || '', industry: newFormData.value.industry || '',
// licenseName: newFormData.value.licenseName || '', licenseName: newFormData.value.licenseName || '',
// dependentSoftware: newFormData.value.dependentSoftware || '', dependentSoftware: newFormData.value.dependentSoftware || '',
// releaseDateStart: releaseDateStart:
// newFormData.value.dateRange && newFormData.value.dateRange.length > 0 ? newFormData.value.dateRange[0] : '', newFormData.value.dateRange && newFormData.value.dateRange.length > 0 ? newFormData.value.dateRange[0] : '',
// releaseDateEnd: releaseDateEnd:
// newFormData.value.dateRange && newFormData.value.dateRange.length > 0 ? newFormData.value.dateRange[1] : '', newFormData.value.dateRange && newFormData.value.dateRange.length > 0 ? newFormData.value.dateRange[1] : '',
// current: pager.value.pageIndex, current: pager.value.pageIndex,
// size: pager.value.pageSize size: pager.value.pageSize
// }); });
// if (data && !error) { if (data && !error) {
// debugger debugger
// // 方法1如果后端返回的是文件流Blob // 方法1如果后端返回的是文件流Blob
// const blob = new Blob([data.data]); const blob = new Blob([data.data]);
// const downloadUrl = window.URL.createObjectURL(blob); const downloadUrl = window.URL.createObjectURL(blob);
//
// // 创建一个临时的a标签触发下载 // 创建一个临时的a标签触发下载
// const link = document.createElement('a'); const link = document.createElement('a');
// link.href = downloadUrl; link.href = downloadUrl;
//
// // 从Content-Disposition头中获取文件名或者使用默认文件名 // 从Content-Disposition头中获取文件名或者使用默认文件名
// const contentDisposition = data.headers['content-disposition']; const contentDisposition = data.headers['content-disposition'];
// let fileName = 'export.xlsx'; // 默认文件名 let fileName = 'export.xlsx'; // 默认文件名
// if (contentDisposition) { if (contentDisposition) {
// const fileNameMatch = contentDisposition.match(/filename="?(.+)"?/); const fileNameMatch = contentDisposition.match(/filename="?(.+)"?/);
// if (fileNameMatch && fileNameMatch[1]) { if (fileNameMatch && fileNameMatch[1]) {
// fileName = fileNameMatch[1].replace(/^[^0-9]*|[^0-9.xlsx]*$/g, ""); fileName = fileNameMatch[1].replace(/^[^0-9]*|[^0-9.xlsx]*$/g, "");
// } }
// } }
//
// link.setAttribute('download', fileName); link.setAttribute('download', fileName);
// document.body.appendChild(link); document.body.appendChild(link);
// link.click(); link.click();
//
// // 清理 // 清理
// document.body.removeChild(link); document.body.removeChild(link);
// window.URL.revokeObjectURL(downloadUrl); window.URL.revokeObjectURL(downloadUrl);
// } else { } else {
// console.error('导出失败:', error); console.error('导出失败:', error);
// // 这里可以添加错误提示比如使用Element Plus的ElMessage // 这里可以添加错误提示比如使用Element Plus的ElMessage
// ElMessage.error('文件导出失败'); ElMessage.error('文件导出失败');
// } }
// }; };
// onMounted(() => { // onMounted(() => {
// const query: any = route.query; // const query: any = route.query;
@@ -570,53 +570,53 @@ onMounted(async () => {
// }; // };
// }); // });
const exportResult = () => { // const exportResult = () => {
//
if (!allTableData.value.length) { // if (!allTableData.value.length) {
Message.info('暂无结果'); // Message.info('暂无结果');
return; // return;
} // }
//
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">