update
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user