|
@@ -53,6 +53,7 @@ const { proxy } = getCurrentInstance() as any;
|
|
|
const router = useRouter();
|
|
|
|
|
|
const data = reactive<any>({
|
|
|
+ timerManager: {},//计时器管理
|
|
|
reportList: [],//排行榜
|
|
|
date: "",//当前时间
|
|
|
unit: "",//单位
|
|
@@ -60,6 +61,7 @@ const data = reactive<any>({
|
|
|
});
|
|
|
|
|
|
const {
|
|
|
+ timerManager,
|
|
|
reportList,
|
|
|
date,
|
|
|
unit,
|
|
@@ -70,7 +72,7 @@ const {
|
|
|
* 更新时间
|
|
|
*/
|
|
|
const setDate = () => {
|
|
|
- setInterval(() => {
|
|
|
+ timerManager.value.currentTime = setInterval(() => {
|
|
|
date.value = proxy?.$utils.getDate();
|
|
|
}, 1000)
|
|
|
};
|
|
@@ -125,6 +127,25 @@ const confirmExit = async () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * 清空定时任务
|
|
|
+*/
|
|
|
+const getClearTimer = (data?: any) => {
|
|
|
+ if (data) {
|
|
|
+ //清除指定
|
|
|
+ clearInterval(timerManager.value[data])
|
|
|
+ timerManager.value[data] = null;
|
|
|
+ } else {
|
|
|
+ //清除全部
|
|
|
+ for (let key in timerManager.value) {
|
|
|
+ if (timerManager.value.hasOwnProperty(key)) {
|
|
|
+ clearInterval(timerManager.value[key])
|
|
|
+ timerManager.value[key] = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
onBeforeMount(() => {
|
|
|
//获取当前时间
|
|
|
setDate();
|
|
@@ -143,6 +164,7 @@ onMounted(() => {
|
|
|
})
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
+ getClearTimer();
|
|
|
})
|
|
|
</script>
|
|
|
|