a7a82dbf
张志伟
🚚 chore(*): 更新依赖
|
1
2
|
import { useCallback, useEffect, useLayoutEffect, useRef } from 'react';
import { Outlet, useNavigate } from '@modern-js/runtime/router';
|
a7a82dbf
张志伟
🚚 chore(*): 更新依赖
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
localdb.init('fw_h5_template', 'fw_h5_template', 'fw_h5_template_del');
const timer = useRef<any>();
const navigate = useNavigate();
const saveServerTimeDif = useCallback(async () => {
const idt = (await localdb.query<number>('i_dt')) || 0;
if (Math.abs(idt - Date.now()) < 1000 * 60 * 10) {
return;
}
const ser_time = await getServerTime();
localdb.save<number>(process.env.MODERN_CALKEY ?? 'i_dif', ser_time ? ser_time - Date.now() : 0);
localdb.save<number>('i_dt', Date.now());
}, []);
const lisFn = useCallback((e: any) => {
if ('hardwareBackPress' === e.data) {
helper.checkBack(() => navigate(-1));
}
}, []);
useLayoutEffect(() => {
localdb.clearExpireData();
saveServerTimeDif();
timer.current = setInterval(() => localdb.clearExpireData(), ONE_SECOND * 5);
return () => {
if (timer.current) {
clearInterval(timer.current);
}
};
}, [saveServerTimeDif]);
useEffect(() => {
window.document.addEventListener('message', lisFn);
return () => {
window.document.removeEventListener('message', lisFn);
};
}, []);
return <Outlet />;
|