File tree Expand file tree Collapse file tree 2 files changed +45
-5
lines changed
Expand file tree Collapse file tree 2 files changed +45
-5
lines changed Original file line number Diff line number Diff line change 1818 <span class =" label" >{{ $t('layout.about.expiredTime') }}</span >
1919 <span
2020 >{{ licenseInfo?.expired || '-' }}
21- <!-- <span class="color-danger"-->
22- <!-- v-if="licenseInfo?.expired && fromNowDate(licenseInfo?.expired)"-->
23- <!-- >({{ fromNowDate(licenseInfo?.expired) }})</span> -- >
21+ <span class =" color-danger"
22+ v-if =" licenseInfo?.expired && fromNowDate(licenseInfo?.expired)"
23+ >({{ fromNowDate(licenseInfo?.expired) }})</span >
2424 </span
2525 >
2626 </div >
6666<script setup lang="ts">
6767import {ref , computed , watch } from ' vue'
6868import licenseApi from ' @/api/system/license'
69- // import {fromNowDate} from '@/utils/time'
69+ import {fromNowDate } from ' @/utils/time'
7070import {Role } from ' @/utils/permission/type'
7171import useStore from ' @/stores'
7272import { t } from ' @/locales'
Original file line number Diff line number Diff line change 11import moment from 'moment'
22import 'moment/dist/locale/zh-cn'
3+
34moment . locale ( 'zh-cn' )
4- import { t } from '@/locales'
5+ import { t } from '@/locales'
56
67// 当天日期 YYYY-MM-DD
78export const nowDate = moment ( ) . format ( 'YYYY-MM-DD' )
@@ -41,3 +42,42 @@ export const dateFormat = (timestamp: any) => {
4142
4243 return `${ y } -${ m } -${ d } `
4344}
45+
46+
47+ export function fromNowDate ( time : any ) {
48+ // 拿到当前时间戳和发布时的时间戳,然后得出时间戳差
49+ const curTime = new Date ( )
50+ const futureTime = new Date ( time )
51+ const timeDiff = futureTime . getTime ( ) - curTime . getTime ( )
52+
53+ // 单位换算
54+ const min = 60 * 1000
55+ const hour = min * 60
56+ const day = hour * 24
57+ const week = day * 7
58+
59+ // 计算发布时间距离当前时间的周、天、时、分
60+ const exceedWeek = Math . floor ( timeDiff / week )
61+ const exceedDay = Math . floor ( timeDiff / day )
62+ const exceedHour = Math . floor ( timeDiff / hour )
63+ const exceedMin = Math . floor ( timeDiff / min )
64+
65+ // 最后判断时间差到底是属于哪个区间,然后return
66+ if ( exceedWeek > 0 ) {
67+ return ''
68+ } else {
69+ if ( exceedDay < 7 && exceedDay > 0 ) {
70+ return exceedDay + t ( 'layout.time.daysLater' )
71+ } else {
72+ if ( exceedHour < 24 && exceedHour > 0 ) {
73+ return exceedHour + t ( 'layout.time.hoursLater' )
74+ } else {
75+ if ( exceedMin < 0 ) {
76+ return t ( 'layout.time.expired' )
77+ } else {
78+ return t ( 'layout.time.expiringSoon' )
79+ }
80+ }
81+ }
82+ }
83+ }
You can’t perform that action at this time.
0 commit comments