This commit is contained in:
zk
2023-12-19 10:46:50 +08:00
parent 8cb7d4baf8
commit 9b5be1af25
11 changed files with 76 additions and 58 deletions
+19 -5
View File
@@ -1,14 +1,18 @@
import { onMounted, onUnmounted, ref } from 'vue';
import { isFunction } from '/@/utils/is.ts';
export function useRefresh(time = 3000, callback) {
/**
* @desc 定时刷新
* @param time
* @param callback
*/
export function useRefresh(time = 3000, callback?: Function) {
const refreshState = ref(false);
const timer = ref(null);
function setRefreshState() {
timer.value = setInterval(() => {
refreshState.value = !refreshState.value;
callback();
}, time);
startRefresh();
}
function stopRefresh() {
@@ -16,6 +20,15 @@ export function useRefresh(time = 3000, callback) {
timer.value = null;
}
function startRefresh() {
timer.value = setInterval(() => {
refreshState.value = !refreshState.value;
if (callback && isFunction(callback)) {
callback();
}
}, time);
}
onMounted(() => {
if (timer.value != null) {
timer.value = null;
@@ -29,5 +42,6 @@ export function useRefresh(time = 3000, callback) {
return {
refreshState,
stopRefresh,
startRefresh,
};
}
+7 -3
View File
@@ -1,3 +1,7 @@
export default {
//预警
};
// 更新频率
const BASIC_MIN = 60 * 1000; //1min
const BASIC_SECOND = 1000; //1s
//副屏 心率、血氧、压力、睡眠、步数
export const DEFAULT_TIME = BASIC_MIN * 10;
//预警分页切换
export const PAGE_SWITCH = BASIC_SECOND * 3;