@@ -904,26 +904,31 @@ class PlayerController {
904904 public startAutoCloseTimer ( time : number , remainTime : number ) {
905905 const statusStore = useStatusStore ( ) ;
906906 if ( ! time || ! remainTime ) return ;
907-
907+ // 清除已有定时器
908908 if ( this . autoCloseInterval ) {
909909 clearInterval ( this . autoCloseInterval ) ;
910910 }
911-
911+ // 计算目标结束时间戳
912+ const endTime = Date . now ( ) + remainTime * 1000 ;
912913 statusStore . autoClose . enable = true ;
913914 statusStore . autoClose . time = time ;
915+ statusStore . autoClose . endTime = endTime ;
914916 statusStore . autoClose . remainTime = remainTime ;
915-
917+ // 定时器仅用于 UI 更新,实际计时基于系统时间
916918 this . autoCloseInterval = setInterval ( ( ) => {
917- if ( statusStore . autoClose . remainTime <= 0 ) {
919+ const now = Date . now ( ) ;
920+ const remaining = Math . max ( 0 , Math . ceil ( ( statusStore . autoClose . endTime - now ) / 1000 ) ) ;
921+ statusStore . autoClose . remainTime = remaining ;
922+ // 到达时间
923+ if ( remaining <= 0 ) {
918924 clearInterval ( this . autoCloseInterval ) ;
919925 if ( ! statusStore . autoClose . waitSongEnd ) {
920926 this . pause ( ) ;
921927 statusStore . autoClose . enable = false ;
922928 statusStore . autoClose . remainTime = statusStore . autoClose . time * 60 ;
929+ statusStore . autoClose . endTime = 0 ;
923930 }
924- return ;
925931 }
926- statusStore . autoClose . remainTime -- ;
927932 } , 1000 ) ;
928933 }
929934
@@ -938,6 +943,7 @@ class PlayerController {
938943 statusStore . autoClose . enable = false ;
939944 // 重置时间
940945 statusStore . autoClose . remainTime = statusStore . autoClose . time * 60 ;
946+ statusStore . autoClose . endTime = 0 ;
941947 return true ;
942948 }
943949 return false ;
0 commit comments