feat: implement fromNowDate function for time difference calculation
This commit is contained in:
parent
1a792dd2e7
commit
368c175f62
@ -18,9 +18,9 @@
|
|||||||
<span class="label">{{ $t('layout.about.expiredTime') }}</span>
|
<span class="label">{{ $t('layout.about.expiredTime') }}</span>
|
||||||
<span
|
<span
|
||||||
>{{ licenseInfo?.expired || '-' }}
|
>{{ licenseInfo?.expired || '-' }}
|
||||||
<!-- <span class="color-danger"-->
|
<span class="color-danger"
|
||||||
<!-- v-if="licenseInfo?.expired && fromNowDate(licenseInfo?.expired)"-->
|
v-if="licenseInfo?.expired && fromNowDate(licenseInfo?.expired)"
|
||||||
<!-- >({{ fromNowDate(licenseInfo?.expired) }})</span>-->
|
>({{ fromNowDate(licenseInfo?.expired) }})</span>
|
||||||
</span
|
</span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
@ -66,7 +66,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {ref, computed, watch} from 'vue'
|
import {ref, computed, watch} from 'vue'
|
||||||
import licenseApi from '@/api/system/license'
|
import licenseApi from '@/api/system/license'
|
||||||
//import {fromNowDate} from '@/utils/time'
|
import {fromNowDate} from '@/utils/time'
|
||||||
import {Role} from '@/utils/permission/type'
|
import {Role} from '@/utils/permission/type'
|
||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
import { t } from '@/locales'
|
import { t } from '@/locales'
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import 'moment/dist/locale/zh-cn'
|
import 'moment/dist/locale/zh-cn'
|
||||||
|
|
||||||
moment.locale('zh-cn')
|
moment.locale('zh-cn')
|
||||||
import { t } from '@/locales'
|
import {t} from '@/locales'
|
||||||
|
|
||||||
// 当天日期 YYYY-MM-DD
|
// 当天日期 YYYY-MM-DD
|
||||||
export const nowDate = moment().format('YYYY-MM-DD')
|
export const nowDate = moment().format('YYYY-MM-DD')
|
||||||
@ -41,3 +42,42 @@ export const dateFormat = (timestamp: any) => {
|
|||||||
|
|
||||||
return `${y}-${m}-${d}`
|
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 + t('layout.time.daysLater')
|
||||||
|
} else {
|
||||||
|
if (exceedHour < 24 && exceedHour > 0) {
|
||||||
|
return exceedHour + t('layout.time.hoursLater')
|
||||||
|
} else {
|
||||||
|
if (exceedMin < 0) {
|
||||||
|
return t('layout.time.expired')
|
||||||
|
} else {
|
||||||
|
return t('layout.time.expiringSoon')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user