refactor(views): 重组页面目录并调整路由引用
- 页面按功能归入 dashboard、login、workspace、system、demo、internal - 数据大屏移入示例目录,错误页、内嵌页与刷新中转移入 internal - 个人中心与我的通知移入 workspace,统一认证回调移入 login - 应用中心移入 workspace,菜单组件值 iframe 解析到 internal/iframe - 在线人数函数更名,未收到推送时显示占位符
This commit is contained in:
52
src/views/demo/data-screen/composables/useKeepTicking.ts
Normal file
52
src/views/demo/data-screen/composables/useKeepTicking.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { onMounted, onUnmounted } from "vue";
|
||||
|
||||
/**
|
||||
* 常驻定时器:组件存活期间按固定间隔执行回调,页面隐藏时自动暂停
|
||||
*
|
||||
* @param callback 定时器每次触发时执行的回调
|
||||
* @param interval 间隔毫秒数,默认 3000
|
||||
*/
|
||||
export function useKeepTicking(callback: () => void, interval = 3000) {
|
||||
/** 定时器是否正在运行 */
|
||||
let ticking = false;
|
||||
/** 定时器标识 */
|
||||
let timerId: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
const startTicker = () => {
|
||||
if (!ticking) {
|
||||
ticking = true;
|
||||
timerId = setInterval(callback, interval);
|
||||
}
|
||||
};
|
||||
|
||||
const stopTicker = () => {
|
||||
if (ticking) {
|
||||
ticking = false;
|
||||
if (timerId) clearInterval(timerId);
|
||||
timerId = null;
|
||||
}
|
||||
};
|
||||
|
||||
const handleVisibilityChange = () => {
|
||||
if (document.hidden) {
|
||||
stopTicker();
|
||||
} else {
|
||||
startTicker();
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener("visibilitychange", handleVisibilityChange);
|
||||
startTicker();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
||||
stopTicker();
|
||||
});
|
||||
|
||||
return {
|
||||
startTicker,
|
||||
stopTicker,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user