永旺用户心声
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

33 lines
757 B

import { ref } from 'vue'
export const useAutoBack = (callback: () => void) => {
const MIN_TIME = 0
const CHECK_TIME = 1000
const TO_INDEX_TIME = 60
const toIndexTime = ref(TO_INDEX_TIME) //回首页的时间
const toIndexInterval = ref()
function sleepToIndex() {
return new Promise<void>(resolve => {
toIndexInterval.value = setInterval(() => {
toIndexTime.value--
if (toIndexTime.value <= MIN_TIME) {
clearInterval(toIndexInterval.value)
resolve()
}
}, CHECK_TIME)
})
}
async function checkHandleScreen() {
toIndexTime.value = TO_INDEX_TIME
clearInterval(toIndexInterval.value)
await sleepToIndex()
callback()
}
return {
checkHandleScreen
}
}