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(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 } }