李富豪 1 rok pred
rodič
commit
3a845c87a9
1 zmenil súbory, kde vykonal 19 pridanie a 2 odobranie
  1. 19 2
      app/components/Record.tsx

+ 19 - 2
app/components/Record.tsx

@@ -13,12 +13,29 @@ const RecordApp: React.FC = () => {
         if (data.account && data.password) {
             if (data.account === 'root' && password === 'root@2024') {
                 const res = await fetch('/api/bigModel');
-                const {data} = await res.json()
+                const body = await res.json();
+                const list: {
+                    id: string;
+                    type: "system" | "user" | "assistant";
+                    create_time: string;
+                    content: string;
+                }[] = body.data;
+                // 标题行
+                const headerRow = [
+                    { id: 'ID', role: '角色', createTime: '创建时间', content: '内容' },
+                ];
+                // 导出数据
+                const sheetData = [...headerRow, ...list.map(item => ({
+                    id: item.id,
+                    role: item.type,
+                    createTime: item.create_time,
+                    content: item.content,
+                }))];
                 // 导出数据到Excel
                 const option = {
                     fileName: '聊天记录',
                     datas: [{
-                        sheetData: data,
+                        sheetData: sheetData,
                         sheetName: '聊天记录',
                     }],
                 };