You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
< script setup >
/**
* name:
* user: sa0ChunLuyu
* date: 2023年5月30日 12:53:12
*/
import {
ref ,
onMounted ,
onBeforeUnmount
} from 'vue'
import {
$response
} from '@/api'
onMounted ( ( ) => {
countdownAction ( )
} )
const page _show = ref ( true )
onBeforeUnmount ( ( ) => {
page _show . value = false
} )
const $emit = defineEmits ( [ 'changeStatus' ] )
const props = defineProps ( {
time : {
type : String ,
default : ''
} ,
id : {
type : Number ,
default : 0
}
} ) ;
const countdown = ref ( '' )
const countdownAction = ( ) => {
if ( ! page _show . value ) return
if ( ! props . time ) countdown . value = ''
let targetTime = new Date ( props . time ) ;
let currentTime = new Date ( ) ;
let timeDiff = targetTime . getTime ( ) - currentTime . getTime ( ) ;
let secondsDiff = Math . floor ( timeDiff / 1000 ) ;
let time = ( 60 * 60 * 2 ) + secondsDiff
if ( time > 0 ) {
let seconds = time ;
let hours = Math . floor ( seconds / 3600 ) ;
let minutes = Math . floor ( ( seconds % 3600 ) / 60 ) ;
let remainingSeconds = seconds % 60 ;
let timeString = hours + '小时' + minutes + '分钟' + remainingSeconds + '秒' ;
countdown . value = timeString
setTimeout ( ( ) => {
countdownAction ( )
} , 1000 )
} else {
$emit ( 'changeStatus' , props . id , 3 )
countdown . value = '已过期'
}
}
< / script >
< template >
< view > { { countdown } } < / view >
< / template >
< style scoped >
< / style >