()
| 169 | } |
| 170 | |
| 171 | export function exportAllToCSV() { |
| 172 | const connections = Object.values(state.connections); |
| 173 | if (connections.length === 0) { |
| 174 | alert('没有连接数据可导出'); |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | const allMessages = []; |
| 179 | connections.forEach(conn => { |
| 180 | getVisibleMessages(conn.messages).forEach(msg => { |
| 181 | allMessages.push({ |
| 182 | ...msg, |
| 183 | timestamp: formatTimestampForExport(msg.timestamp), |
| 184 | connection: getConnectionExportInfo(conn) |
| 185 | }); |
| 186 | }); |
| 187 | }); |
| 188 | |
| 189 | if (allMessages.length === 0) { |
| 190 | alert('没有消息数据可导出'); |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | const headers = [ |
| 195 | 'ConnectionID', |
| 196 | 'ConnectionURL', |
| 197 | 'RequestType', |
| 198 | 'Source', |
| 199 | 'Status', |
| 200 | 'IsIframe', |
| 201 | 'FrameURL', |
| 202 | 'ConnectionCreatedAt', |
| 203 | 'ID', |
| 204 | 'EventType', |
| 205 | 'Data', |
| 206 | 'LastEventId', |
| 207 | 'Timestamp' |
| 208 | ]; |
| 209 | const rows = allMessages.map(msg => [ |
| 210 | escapeCSV(msg.connection.id), |
| 211 | escapeCSV(msg.connection.url), |
| 212 | escapeCSV(msg.connection.requestType), |
| 213 | escapeCSV(msg.connection.source), |
| 214 | escapeCSV(msg.connection.status), |
| 215 | escapeCSV(msg.connection.isIframe), |
| 216 | escapeCSV(msg.connection.frameUrl), |
| 217 | escapeCSV(msg.connection.createdAt), |
| 218 | escapeCSV(msg.id), |
| 219 | escapeCSV(msg.eventType), |
| 220 | escapeCSV(msg.data), |
| 221 | escapeCSV(msg.lastEventId), |
| 222 | escapeCSV(msg.timestamp) |
| 223 | ].join(',')); |
| 224 | |
| 225 | const csvWithConnectionInfo = [headers.join(','), ...rows].join('\n'); |
| 226 | const filename = `stream-all-messages-${Date.now()}.csv`; |
| 227 | downloadFile(csvWithConnectionInfo, filename, 'text/csv'); |
| 228 | } |
no test coverage detected