Add production data table with Ant Design and SQL Server integration

- Add API route to execute stored procedure and query production data
- Build search bar with isolated component to prevent input lag on large datasets
- Configure Ant Design Table with sticky header and horizontal scroll for 56 columns
- Add antd, @ant-design/icons, mssql dependencies
- Configure allowedDevOrigins for LAN access

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-06-10 10:05:32 +08:00
parent 38adf674e8
commit 93564c6f4e
7 changed files with 2176 additions and 132 deletions

View File

@@ -0,0 +1,65 @@
import { NextRequest, NextResponse } from "next/server";
import sql from "mssql";
const dbConfig = {
server: process.env.DB_SERVER!,
port: 1433,
database: process.env.DB_DATABASE!,
user: process.env.DB_USER!,
password: process.env.DB_PASSWORD!,
options: {
trustServerCertificate: process.env.DB_TRUST_CERT === "true",
encrypt: false,
},
};
export async function GET(request: NextRequest) {
const workshopNo = request.nextUrl.searchParams.get("workshopNo");
if (!workshopNo) {
return NextResponse.json(
{ error: "请提供车间号参数" },
{ status: 400 }
);
}
let pool: sql.ConnectionPool | undefined;
try {
pool = await sql.connect(dbConfig);
const result = await pool
.request()
.input("车间号", sql.NVarChar(50), workshopNo)
.execute(
"[productionContractData].[sp_压力表合同生产数据_按车间号]"
);
const recordset = result.recordset;
if (!recordset || recordset.length === 0) {
return NextResponse.json({ columns: [], data: [], total: 0 });
}
const columns = Object.keys(recordset[0]);
const data = recordset.map((row: Record<string, unknown>) => {
const serialized: Record<string, unknown> = {};
for (const key of columns) {
const val = row[key];
if (val instanceof Date) {
serialized[key] = val.toISOString().split("T")[0];
} else {
serialized[key] = val;
}
}
return serialized;
});
return NextResponse.json({ columns, data, total: data.length });
} catch (err) {
const message = err instanceof Error ? err.message : "Unknown error";
console.error("DB query error:", message);
return NextResponse.json({ error: message }, { status: 500 });
} finally {
if (pool) {
await pool.close();
}
}
}