From 84e9a19f3e218264c43f3ac2724bd5c1829a2692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=BB=E5=8B=87=E7=A5=A5?= <237899745@qq.com> Date: Fri, 14 Nov 2025 13:54:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E5=88=B0=E6=9C=9F=E6=97=B6=E9=97=B4=E6=98=BE=E7=A4=BA=E7=9A=84?= =?UTF-8?q?=E4=B8=A4=E4=B8=AA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题1: 分享成功提示中到期时间显示为"永久有效" - 修复: backend/database.js 的create方法添加返回expires_at字段 - 修复: backend/server.js 的API响应中添加expires_at字段 - 现在创建分享后会正确显示设置的到期时间 问题2: share.html分享页面不显示到期时间 - 新增: 在分享信息中添加到期时间显示(frontend/share.html:527-528) - 新增: 添加formatExpireTime/isExpiringSoon/isExpired方法 - 效果: 访问分享页面时可以看到"到期时间"或"永久有效" 改进: - 使用颜色区分状态(绿色=永久/正常, 黄色=即将过期, 红色=已过期) - 友好的时间显示格式(X天后过期/明天过期等) 注意: 关于0.01天显示问题的优化方案已文档化,需要手动修改app.js 🤖 Generated with Claude Code Co-Authored-By: Claude --- backend/database.js | 3 ++- backend/server.js | 3 ++- frontend/share.html | 52 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/backend/database.js b/backend/database.js index c77a442..0a5c591 100644 --- a/backend/database.js +++ b/backend/database.js @@ -326,7 +326,8 @@ const ShareDB = { return { id: result.lastInsertRowid, share_code: shareCode, - share_type: share_type + share_type: share_type, + expires_at: expiresAt, }; }, diff --git a/backend/server.js b/backend/server.js index 7cac112..13a8a66 100644 --- a/backend/server.js +++ b/backend/server.js @@ -1505,7 +1505,8 @@ app.post('/api/share/create', authMiddleware, (req, res) => { message: '分享链接创建成功', share_code: result.share_code, share_url: shareUrl, - share_type: result.share_type + share_type: result.share_type, + expires_at: result.expires_at, }); } catch (error) { console.error('创建分享链接失败:', error); diff --git a/frontend/share.html b/frontend/share.html index b553bee..972e84e 100644 --- a/frontend/share.html +++ b/frontend/share.html @@ -524,6 +524,8 @@

分享者: {{ shareInfo.username }} | 创建时间: {{ formatDate(shareInfo.created_at) }} + | 到期时间: {{ formatExpireTime(shareInfo.expires_at) }} + | 有效期: 永久有效

@@ -822,6 +824,56 @@ hour12: false }); } +, + + // 格式化到期时间显示 + formatExpireTime(expiresAt) { + if (!expiresAt) return '永久有效'; + + const expireDate = new Date(expiresAt); + const now = new Date(); + const diffMs = expireDate - now; + const diffDays = Math.ceil(diffMs / (1000 * 60 * 60 * 24)); + + // 格式化日期 + const dateStr = expireDate.toLocaleString('zh-CN', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit' + }); + + if (diffDays < 0) { + return `已过期 (${dateStr})`; + } else if (diffDays === 0) { + return `今天过期 (${dateStr})`; + } else if (diffDays === 1) { + return `明天过期 (${dateStr})`; + } else if (diffDays <= 7) { + return `${diffDays}天后过期 (${dateStr})`; + } else { + return dateStr; + } + }, + + // 判断是否即将过期(3天内) + isExpiringSoon(expiresAt) { + if (!expiresAt) return false; + const expireDate = new Date(expiresAt); + const now = new Date(); + const diffMs = expireDate - now; + const diffDays = diffMs / (1000 * 60 * 60 * 24); + return diffDays > 0 && diffDays <= 3; + }, + + // 判断是否已过期 + isExpired(expiresAt) { + if (!expiresAt) return false; + const expireDate = new Date(expiresAt); + const now = new Date(); + return expireDate <= now; + } }, mounted() {