From d8f9622931ab0e32d9233622c97e58ffb71ea37b Mon Sep 17 00:00:00 2001 From: wangdan-fit2cloud Date: Wed, 17 Jul 2024 16:13:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0license=E8=BF=87?= =?UTF-8?q?=E6=9C=9F=E6=97=B6=E9=97=B4=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/top-bar/avatar/AboutDialog.vue | 9 ++++- ui/src/utils/time.ts | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/ui/src/layout/components/top-bar/avatar/AboutDialog.vue b/ui/src/layout/components/top-bar/avatar/AboutDialog.vue index 16491b937..6b5af0df6 100644 --- a/ui/src/layout/components/top-bar/avatar/AboutDialog.vue +++ b/ui/src/layout/components/top-bar/avatar/AboutDialog.vue @@ -17,7 +17,13 @@ ISV{{ licenseInfo?.isv || '-' }}
- 过期时间{{ licenseInfo?.expired || '-' }} + 过期时间 + {{ licenseInfo?.expired || '-' }} + ({{ fromNowDate(licenseInfo?.expired) }})
版本 { diff --git a/ui/src/utils/time.ts b/ui/src/utils/time.ts index fcbc86a05..dcbe56586 100644 --- a/ui/src/utils/time.ts +++ b/ui/src/utils/time.ts @@ -1,4 +1,6 @@ import moment from 'moment' +import 'moment/dist/locale/zh-cn' +moment.locale('zh-cn') // 当天日期 YYYY-MM-DD export const nowDate = moment().format('YYYY-MM-DD') @@ -38,3 +40,41 @@ export const dateFormat = (timestamp: any) => { return `${y}-${m}-${d}` } + +export function fromNowDate(time: any) { + // 拿到当前时间戳和发布时的时间戳,然后得出时间戳差 + const curTime = new Date() + const futureTime = new Date(time) + const timeDiff = futureTime.getTime() - curTime.getTime() + + // 单位换算 + const min = 60 * 1000 + const hour = min * 60 + const day = hour * 24 + const week = day * 7 + + // 计算发布时间距离当前时间的周、天、时、分 + const exceedWeek = Math.floor(timeDiff / week) + const exceedDay = Math.floor(timeDiff / day) + const exceedHour = Math.floor(timeDiff / hour) + const exceedMin = Math.floor(timeDiff / min) + + // 最后判断时间差到底是属于哪个区间,然后return + if (exceedWeek > 0) { + return '' + } else { + if (exceedDay < 7 && exceedDay > 0) { + return exceedDay + '天后' + } else { + if (exceedHour < 24 && exceedHour > 0) { + return exceedHour + '小时后' + } else { + if (exceedMin < 0) { + return '已过期' + } else { + return '即将到期' + } + } + } + } +}