添加批量删除、批量复制和导出选中链接到Excel的功能,同时更新链接状态和导出CSV的逻辑,优化了链接生成和显示的相关代码

This commit is contained in:
zyh
2025-08-26 16:41:11 +08:00
parent 7a75fbe887
commit 7854bd0288
4 changed files with 337 additions and 84 deletions

View File

@@ -74,7 +74,7 @@ export async function copyToClipboard(text) {
// 导出CSV数据
export function exportToCSV(data, headers, filename) {
const csvContent = [
headers.join(','),
headers.map(h => h.label).join(','),
...data.map(row =>
headers.map(header => {
const value = row[header.key] || ''
@@ -91,4 +91,46 @@ export function exportToCSV(data, headers, filename) {
link.click()
}
// 导出Excel数据
export function exportToExcel(data, headers, filename) {
// 创建HTML表格格式
const tableHTML = `
<html>
<head>
<meta charset="UTF-8">
<style>
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #f2f2f2; font-weight: bold; }
</style>
</head>
<body>
<table>
<thead>
<tr>
${headers.map(header => `<th>${header.label}</th>`).join('')}
</tr>
</thead>
<tbody>
${data.map(row =>
`<tr>
${headers.map(header => `<td>${row[header.key] || ''}</td>`).join('')}
</tr>`
).join('')}
</tbody>
</table>
</body>
</html>
`
// 创建Blob并下载
const blob = new Blob([tableHTML], {
type: 'application/vnd.ms-excel;charset=utf-8;'
})
const link = document.createElement('a')
link.href = URL.createObjectURL(blob)
link.download = filename
link.click()
}