diff --git a/src/views/Jyh/Search/Components/OssQuery.vue b/src/views/Jyh/Search/Components/OssQuery.vue index 666c2f4..69b5375 100644 --- a/src/views/Jyh/Search/Components/OssQuery.vue +++ b/src/views/Jyh/Search/Components/OssQuery.vue @@ -512,56 +512,56 @@ onMounted(async () => { // 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('文件导出失败'); -// } -// }; +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(() => { // const query: any = route.query; @@ -570,53 +570,53 @@ onMounted(async () => { // }; // }); -const exportResult = () => { - - if (!allTableData.value.length) { - Message.info('暂无结果'); - return; - } - - const selectDatas = filterTableRef.value.store.getCheckedRows().map((d) => d.id); - if (!allTableData.value.length || selectDatas.length <= 0) { - Message.info('未选择任何数据'); - return; - } - - const exportData = allTableData.value - .filter((d) => { - return selectDatas.includes(d.id); - }) - .map((item) => { - let res = {}; - columns.value.forEach((col) => { - if (col.key === 'validStatus') { - res[col.label] = validStatusMap[item[col.key]] ? validStatusMap[item[col.key]] : ''; - } else { - res[col.label] = item[col.key] ? item[col.key] : ''; - } - }); - return res; - }); - - try { - const workSheet = XLSX.utils.json_to_sheet(exportData); - const workBook: any = { Sheets: { 校验结果: workSheet }, SheetNames: ['校验结果'] }; - const excelBuffer = XLSX.write(workBook, { bookType: 'xlsx', type: 'array' }); - - const link = document.createElement('a'); - const blob = new Blob([excelBuffer]); - link.setAttribute('href', window.URL.createObjectURL(blob)); - link.setAttribute('download', '软件存在及可信校验结果.xlsx'); - link.style.visibility = 'hidden'; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - Message.success('导出成功'); - } catch { - Message.error('导出失败'); - } -}; +// const exportResult = () => { +// +// if (!allTableData.value.length) { +// Message.info('暂无结果'); +// return; +// } +// +// const selectDatas = filterTableRef.value.store.getCheckedRows().map((d) => d.id); +// if (!allTableData.value.length || selectDatas.length <= 0) { +// Message.info('未选择任何数据'); +// return; +// } +// +// const exportData = allTableData.value +// .filter((d) => { +// return selectDatas.includes(d.id); +// }) +// .map((item) => { +// let res = {}; +// columns.value.forEach((col) => { +// if (col.key === 'validStatus') { +// res[col.label] = validStatusMap[item[col.key]] ? validStatusMap[item[col.key]] : ''; +// } else { +// res[col.label] = item[col.key] ? item[col.key] : ''; +// } +// }); +// return res; +// }); +// +// try { +// const workSheet = XLSX.utils.json_to_sheet(exportData); +// const workBook: any = { Sheets: { 校验结果: workSheet }, SheetNames: ['校验结果'] }; +// const excelBuffer = XLSX.write(workBook, { bookType: 'xlsx', type: 'array' }); +// +// const link = document.createElement('a'); +// const blob = new Blob([excelBuffer]); +// link.setAttribute('href', window.URL.createObjectURL(blob)); +// link.setAttribute('download', '软件存在及可信校验结果.xlsx'); +// link.style.visibility = 'hidden'; +// document.body.appendChild(link); +// link.click(); +// document.body.removeChild(link); +// Message.success('导出成功'); +// } catch { +// Message.error('导出失败'); +// } +// };