李富豪 1 سال پیش
والد
کامیت
78eca28f4c
2فایلهای تغییر یافته به همراه17 افزوده شده و 12 حذف شده
  1. 12 9
      app/api/bigModel/route.ts
  2. 5 3
      app/components/Record.tsx

+ 12 - 9
app/api/bigModel/route.ts

@@ -21,6 +21,7 @@ interface Request {
   }[];
 }
 
+// 插入数据
 export async function POST(req: any) {
   try {
     // 从连接池中获取连接
@@ -50,13 +51,15 @@ export async function POST(req: any) {
 
     // 释放连接回连接池
     connection.release()
-    return NextResponse.json({ message: 'ok', data: (rows as any).length }, { status: 200 })
-  } catch (error) {
-    console.error('Error:', error)
-    return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 })
+
+    return NextResponse.json({ message: 'success', data: {} }, { status: 200 })
+  } catch (e) {
+    console.error('Error:', e)
+    return NextResponse.json({ message: 'error' }, { status: 500 })
   }
 }
 
+// 查询数据
 export async function GET() {
   try {
     // 从连接池中获取连接
@@ -64,14 +67,14 @@ export async function GET() {
 
     // 执行 MySQL 查询
     const [rows, fields] = await connection.query('SELECT he.id,he.dialog_name,de.id did,de.dialog_id,de.type,de.content,de.create_time ' +
-        'FROM dialog he left join dialog_detail de on he.id = de.dialog_id order by he.create_time desc, he.id , de.create_time, type desc')
+      'FROM dialog he left join dialog_detail de on he.id = de.dialog_id order by he.create_time desc, he.id , de.create_time, type desc')
 
     // 释放连接回连接池
     connection.release()
 
-    return NextResponse.json({ data: rows }, { status: 200 })
-  } catch (error) {
-    console.error('Error:', error)
-    return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 })
+    return NextResponse.json({ message: 'success', data: rows }, { status: 200 })
+  } catch (e) {
+    console.error('Error:', e)
+    return NextResponse.json({ message: 'error' }, { status: 500 })
   }
 }

+ 5 - 3
app/components/Record.tsx

@@ -3,8 +3,8 @@ import { Link } from 'react-router-dom';
 import { IconButton } from './button';
 import ReturnIcon from "../icons/return.svg";
 import Excel from 'js-export-excel';
+import { ApiPath } from "@/app/constant";
 import dayjs from 'dayjs';
-import {  ApiPath } from "@/app/constant";
 
 const RecordApp: React.FC = () => {
     const [account, setAccount] = React.useState('');
@@ -14,8 +14,8 @@ const RecordApp: React.FC = () => {
     const onClickExport = async (data: { account: string, password: string }) => {
         if (data.account && data.password) {
             if (data.account === 'root' && password === 'root@2024') {
-                const res = await fetch(ApiPath.BigModel,{
-                    method:'GET',
+                const res = await fetch(ApiPath.BigModel, {
+                    method: 'GET',
                 });
                 const body = await res.json();
                 const list: {
@@ -24,6 +24,7 @@ const RecordApp: React.FC = () => {
                     create_time: string;
                     content: string;
                 }[] = body.data;
+
                 // 标题行
                 const headerRow = [
                     { id: 'ID', role: '角色', createTime: '创建时间', content: '内容' },
@@ -35,6 +36,7 @@ const RecordApp: React.FC = () => {
                     createTime: dayjs(item.create_time).format('YYYY-MM-DD HH:mm:ss'),
                     content: item.content,
                 }))];
+
                 // 导出数据到Excel
                 const option = {
                     fileName: '聊天记录',