mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 07:28:37 +08:00
统一处理低版本safari浏览器Date兼容性问题
This commit is contained in:
@@ -171,6 +171,7 @@ export function formatDateDifference(dateString: string): string {
|
|||||||
// return `${minutesDifference}分钟前`
|
// return `${minutesDifference}分钟前`
|
||||||
// else
|
// else
|
||||||
// return '刚刚'
|
// return '刚刚'
|
||||||
|
if (!dateString)
|
||||||
|
return ''
|
||||||
return dayjs(dateString).fromNow()
|
return dayjs(dateString).fromNow()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,12 +33,16 @@ export function isToday(date: Date) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算时间差,返回xx天/xx小时/xx分钟/xx秒
|
/**
|
||||||
|
* 计算时间差,返回xx天/xx小时/xx分钟/xx秒
|
||||||
|
*
|
||||||
|
* @deprecated 建议使用:@core/utils/formatters.ts formatDateDifference
|
||||||
|
*/
|
||||||
export function calculateTimeDifference(inputTime: string): string {
|
export function calculateTimeDifference(inputTime: string): string {
|
||||||
if (!inputTime)
|
if (!inputTime)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
const inputDate = new Date(inputTime)
|
const inputDate = new Date(inputTime.replaceAll(/-/g, '/'))
|
||||||
const currentDate = new Date()
|
const currentDate = new Date()
|
||||||
|
|
||||||
const timeDifference = currentDate.getTime() - inputDate.getTime()
|
const timeDifference = currentDate.getTime() - inputDate.getTime()
|
||||||
@@ -70,7 +74,7 @@ export function calculateTimeDiff(inputTime: string): string {
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
// 使用当前时区
|
// 使用当前时区
|
||||||
const inputDate = new Date(inputTime)
|
const inputDate = new Date(inputTime.replaceAll(/-/g, '/'))
|
||||||
const currentDate = new Date()
|
const currentDate = new Date()
|
||||||
|
|
||||||
const timeDifference = currentDate.getTime() - inputDate.getTime()
|
const timeDifference = currentDate.getTime() - inputDate.getTime()
|
||||||
|
|||||||
@@ -423,14 +423,14 @@ function getSeasonPoster(posterPath: string) {
|
|||||||
function formatAirDate(airDate: string) {
|
function formatAirDate(airDate: string) {
|
||||||
if (!airDate)
|
if (!airDate)
|
||||||
return ''
|
return ''
|
||||||
const date = new Date(airDate)
|
const date = new Date(airDate.replaceAll(/-/g, '/'))
|
||||||
return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`
|
return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`
|
||||||
}
|
}
|
||||||
// 从yyyy-mm-dd中提取年份
|
// 从yyyy-mm-dd中提取年份
|
||||||
function getYear(airDate: string) {
|
function getYear(airDate: string) {
|
||||||
if (!airDate)
|
if (!airDate)
|
||||||
return ''
|
return ''
|
||||||
const date = new Date(airDate)
|
const date = new Date(airDate.replaceAll(/-/g, '/'))
|
||||||
return date.getFullYear()
|
return date.getFullYear()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang='ts' setup>
|
<script lang='ts' setup>
|
||||||
import { useToast } from 'vue-toast-notification'
|
import { useToast } from 'vue-toast-notification'
|
||||||
import SubscribeEditDialog from '../dialog/SubscribeEditDialog.vue'
|
import SubscribeEditDialog from '../dialog/SubscribeEditDialog.vue'
|
||||||
import { calculateTimeDifference } from '@/@core/utils'
|
import { formatDateDifference } from '@/@core/utils/formatters'
|
||||||
import { formatSeason } from '@/@core/utils/formatters'
|
import { formatSeason } from '@/@core/utils/formatters'
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import type { Subscribe } from '@/api/types'
|
import type { Subscribe } from '@/api/types'
|
||||||
@@ -26,11 +26,9 @@ const subscribeEditDialog = ref(false)
|
|||||||
|
|
||||||
// 上一次更新时间
|
// 上一次更新时间
|
||||||
const lastUpdateText = ref(
|
const lastUpdateText = ref(
|
||||||
`${
|
props.media && props.media.last_update
|
||||||
props.media?.last_update
|
? formatDateDifference(props.media.last_update)
|
||||||
? `${calculateTimeDifference(props.media?.last_update || '')}前`
|
: '',
|
||||||
: ''
|
|
||||||
}`,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 图片加载完成响应
|
// 图片加载完成响应
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { calculateTimeDifference } from '@/@core/utils'
|
import { formatDateDifference } from '@/@core/utils/formatters'
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
|
|
||||||
// 系统环境变量
|
// 系统环境变量
|
||||||
@@ -62,7 +62,7 @@ async function queryAllRelease() {
|
|||||||
// 计算发布时间
|
// 计算发布时间
|
||||||
function releaseTime(releaseDate: string) {
|
function releaseTime(releaseDate: string) {
|
||||||
// 上一次更新时间
|
// 上一次更新时间
|
||||||
return `${calculateTimeDifference(releaseDate)}前`
|
return formatDateDifference(releaseDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ function compareTime(time1: string, time2: string) {
|
|||||||
return -1
|
return -1
|
||||||
if (!time2)
|
if (!time2)
|
||||||
return 1
|
return 1
|
||||||
return new Date(time1).getTime() - new Date(time2).getTime()
|
return new Date(time1.replaceAll(/-/g, '/')).getTime() - new Date(time2.replaceAll(/-/g, '/')).getTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user