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() {