3 changed files with 36 additions and 72 deletions
@ -1,33 +0,0 @@ |
|||||
import { ref } from 'vue' |
|
||||
|
|
||||
export const useAutoBack = (callback: () => void) => { |
|
||||
const MIN_TIME = 0 |
|
||||
const CHECK_TIME = 1000 |
|
||||
const TO_INDEX_TIME = 15 |
|
||||
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 |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue