/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
// 导出当前页日志为 CSV,只在前端处理,不新增后端接口
// 作用域:仅当前页(rows 是已加载到内存的列表)。如需全量导出,后续可接后端 stream 接口
// 用 \uFEFF BOM 让 Excel 自动识别 UTF-8;字段值里遇到 "、,、换行 的用双引号包裹并转义
const escapeCsvCell = (value) => {
if (value === null || value === undefined) return '';
const s = String(value);
if (
s.includes('"') ||
s.includes(',') ||
s.includes('\n') ||
s.includes('\r')
) {
return '"' + s.replace(/"/g, '""') + '"';
}
return s;
};
/**
* @param {Array<{key: string, title: string, format?: (row:any)=>string}>} columns
* @param {Array