Files
QCN_rider/.svn/pristine/19/19f16508cf1144513459d4b24925e0f8ca2e7201.svn-base
2026-02-12 12:19:20 +08:00

75 lines
1.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { onLaunch, onShow, onHide, onError } from '@dcloudio/uni-app'
import { ref, onUnmounted } from 'vue'
// 全局定时器引用
let globalTimer = null
// 每分钟要执行的方法
const minuteTask = () => {
console.log('每分钟执行一次的任务', new Date().toLocaleTimeString())
}
// 启动全局定时器
const startGlobalTimer = () => {
if (globalTimer) {
clearInterval(globalTimer)
}
// 立即执行一次
minuteTask()
// 设置每分钟执行一次60000毫秒 = 1分钟
globalTimer = setInterval(() => {
minuteTask()
}, 60000)
}
// 停止全局定时器
const stopGlobalTimer = () => {
if (globalTimer) {
clearInterval(globalTimer)
globalTimer = null
}
}
onLaunch(() => {
console.log('App Launch')
// 应用启动时开始定时器
startGlobalTimer()
})
onShow(() => {
console.log('App Show')
// 应用回到前台时重新开始定时器
startGlobalTimer()
})
onHide(() => {
console.log('App Hide')
// 应用进入后台时停止定时器,节省资源
stopGlobalTimer()
})
// Vue组件卸载时清理定时器
onUnmounted(() => {
stopGlobalTimer()
})
// 全局错误处理
onError((err) => {
console.error('App Error:', err)
})
</script>
<style lang="scss">
@import "uview-plus/index.scss";
@import "colorui/main.css";
@import "colorui/icon.css";
page {
--nav-mian: #1890FF; //全局颜色
--nav-vice: #52C41A; //副颜色
--nav-diluted: #FF4D4F; //次颜色
}
</style>