diff --git a/certificate.html b/certificate.html
index e6bad2a..4062ee9 100644
--- a/certificate.html
+++ b/certificate.html
@@ -407,7 +407,7 @@
- 技术支持:厦门海荭兴仪器股份有限公司 0592-5768388
+ 技术支持:四川又鸟蛋贸易有限公司
@@ -474,13 +474,18 @@
// 从服务器加载最新的合格证信息
function loadCertificate() {
- // 这里可以添加从服务器获取最新合格证信息的代码
- // 暂时保留本地存储的支持,以便在服务器不可用时仍能显示数据
- const saved = localStorage.getItem('certificate');
- if (saved) {
- const certificate = JSON.parse(saved);
- displayCertificate(certificate);
- }
+ // 直接从服务器获取最新的合格证信息
+ fetch('/getLatestCertificate')
+ .then(response => response.json())
+ .then(data => {
+ if (data.success && data.certificate) {
+ displayCertificate(data.certificate);
+ }
+ })
+ .catch(error => {
+ console.error('获取合格证信息失败:', error);
+ // 即使获取失败,也不影响页面显示
+ });
}
// 显示合格证信息
diff --git a/server.js b/server.js
index c72f2ec..b506f40 100644
--- a/server.js
+++ b/server.js
@@ -36,6 +36,37 @@ async function testDbConnection() {
testDbConnection();
const server = http.createServer(async (req, res) => {
+ // 处理GET请求,获取最新的合格证信息
+ if (req.method === 'GET' && req.url === '/getLatestCertificate') {
+ try {
+ // 从数据库获取最新的合格证信息
+ const [rows] = await pool.execute(
+ 'SELECT company as subjectName, phoneNumber as contact, productName, grossWeight as weight, commitBasis as basis, origin, DATE_FORMAT(issueDate, "%Y-%m-%d") as date, signature FROM certificate ORDER BY id DESC LIMIT 1'
+ );
+
+ const certificate = rows.length > 0 ? rows[0] : null;
+
+ // 返回成功响应
+ res.writeHead(200, {
+ 'Content-Type': 'application/json',
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
+ 'Access-Control-Allow-Headers': 'Content-Type'
+ });
+ res.end(JSON.stringify({ success: true, certificate }));
+ } catch (error) {
+ console.error('获取合格证信息失败:', error.message);
+ res.writeHead(500, {
+ 'Content-Type': 'application/json',
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
+ 'Access-Control-Allow-Headers': 'Content-Type'
+ });
+ res.end(JSON.stringify({ success: false, error: '获取失败,请重试' }));
+ }
+ return;
+ }
+
// 处理POST请求
if (req.method === 'POST' && req.url === '/submit') {
try {