diff --git a/certificate.html b/certificate.html
index 9bd00ba..0e93a08 100644
--- a/certificate.html
+++ b/certificate.html
@@ -446,7 +446,7 @@
-
+
@@ -709,25 +709,16 @@
});
});
- // 设置日期时间输入框的默认值和最大值
+ // 设置日期输入框的默认值和最大值
function setupDateInput() {
const dateInput = document.getElementById('date');
if (dateInput) {
- // 获取当前时间,格式为YYYY-MM-DDTHH:MM:SS
- const now = new Date();
- // 格式化时间,确保秒数正确
- const year = now.getFullYear();
- const month = String(now.getMonth() + 1).padStart(2, '0');
- const day = String(now.getDate()).padStart(2, '0');
- const hours = String(now.getHours()).padStart(2, '0');
- const minutes = String(now.getMinutes()).padStart(2, '0');
- const seconds = String(now.getSeconds()).padStart(2, '0');
- const formattedNow = `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;
-
- // 设置默认值为当前时间
- dateInput.value = formattedNow;
- // 设置最大值为当前时间,只能选择当前时间或之前的时间
- dateInput.max = formattedNow;
+ // 获取当前日期,格式为YYYY-MM-DD
+ const today = new Date().toISOString().split('T')[0];
+ // 设置默认值为今天
+ dateInput.value = today;
+ // 设置最大值为今天,只能选择今天或之前的日期
+ dateInput.max = today;
}
}
diff --git a/server.js b/server.js
index 54b2747..e2d5b57 100644
--- a/server.js
+++ b/server.js
@@ -81,10 +81,11 @@ 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, 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, issueDate, 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;
+ console.log('从数据库获取的最新合格证信息:', certificate);
// 返回成功响应
res.writeHead(200, {
@@ -119,6 +120,10 @@ 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'),
contact: formData.get('contact'),
@@ -126,7 +131,7 @@ const server = http.createServer(async (req, res) => {
weight: formData.get('weight'),
basis: formData.get('basis'),
origin: formData.get('origin'),
- date: formData.get('date'),
+ date: beijingTime,
signature: formData.get('signature')
};
@@ -137,7 +142,7 @@ const server = http.createServer(async (req, res) => {
weight: certificate.weight,
basis: certificate.basis,
origin: certificate.origin,
- date: certificate.date,
+ date: certificate.date.toISOString(),
hasSignature: !!certificate.signature
});