diff --git a/certificate.html b/certificate.html
index 0e93a08..c20d090 100644
--- a/certificate.html
+++ b/certificate.html
@@ -488,6 +488,16 @@
});
}
+ // 格式化日期,确保只显示到日
+ function formatDate(dateValue) {
+ if (!dateValue) return '';
+ // 如果是完整的日期时间字符串,只取日期部分
+ if (typeof dateValue === 'string' && dateValue.includes('T')) {
+ return dateValue.split('T')[0];
+ }
+ return dateValue;
+ }
+
// 显示合格证信息
function displayCertificate(certificate) {
const container = document.getElementById('certificateInfo');
@@ -520,7 +530,7 @@
开具日期:
- ${certificate.date || ''}
+ ${formatDate(certificate.date) || ''}
`;
diff --git a/server.js b/server.js
index e2d5b57..06dd2e5 100644
--- a/server.js
+++ b/server.js
@@ -81,7 +81,7 @@ const server = http.createServer(async (req, res) => {
try {
// 从数据库获取最新的合格证信息
const [rows] = await pool.execute(
- 'SELECT company as subjectName, phoneNumber as contact, productName, grossWeight as weight, commitBasis as basis, origin, issueDate, DATE_FORMAT(issueDate, "%Y-%m-%d") as date, signature FROM certificate ORDER BY id DESC LIMIT 1'
+ '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;
@@ -120,9 +120,8 @@ const server = http.createServer(async (req, res) => {
try {
// 解析表单数据
const formData = new URLSearchParams(body);
- // 使用当前的北京时间(精确到秒)作为开具日期
+ // 使用当前时间作为开具日期,数据库连接已配置为北京时间
const now = new Date();
- const beijingTime = new Date(now.getTime() + 8 * 60 * 60 * 1000); // 转换为北京时间
const certificate = {
subjectName: formData.get('subjectName'),
@@ -131,7 +130,7 @@ const server = http.createServer(async (req, res) => {
weight: formData.get('weight'),
basis: formData.get('basis'),
origin: formData.get('origin'),
- date: beijingTime,
+ date: now,
signature: formData.get('signature')
};
@@ -176,19 +175,21 @@ const server = http.createServer(async (req, res) => {
console.log('数据插入数据库成功');
- // 返回成功响应,确保返回的signature是OSS URL
- const responseCertificate = {
- ...certificate,
- signature: signatureUrl
- };
-
- 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: responseCertificate }));
+ // 返回成功响应,确保返回的signature是OSS URL,日期只显示到日
+ const responseCertificate = {
+ ...certificate,
+ signature: signatureUrl,
+ // 格式化日期为YYYY-MM-DD格式
+ date: certificate.date.toISOString().split('T')[0]
+ };
+
+ 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: responseCertificate }));
} catch (error) {
console.error('处理表单数据失败:', error.message);
res.writeHead(500, {