visibilitychange
navigator.sendBeacon()
https://developer.mozilla.org/zh-CN/docs/Web/API/Document/visibilitychange_event
https://zhuanlan.zhihu.com/p/381796039
export function visibilitywindow() {
document.addEventListener('visibilitychange', function () {
if (document.visibilityState !== 'visible') {
const timer: any = dayjs().format('YYYY-MM-DD HH:mm:ss');
const user = Encryption.decodeBase64(localStorage.getItem('user'));
const data = {
end_time: timer,
start_time: localStorage.getItem('startTime'),
user_id: user?.user.user_id,
};
if (localStorage.getItem('startTime')) {
const flag = reportData('/index/Service/sendUserActive', data);
if (flag) {
localStorage.removeItem('startTime');
}
}
} else {
localStorage.setItem('startTime', dayjs().format('YYYY-MM-DD HH:mm:ss'));
}
});
}
const reportData = (url, data?) => {
const flag = navigator.sendBeacon(url, JSON.stringify(data));
return flag;
};
useEffect(() => {
const user = Encryption.decodeBase64(localStorage.getItem('user'));
if (isApp && user?.user?.user_id) {
if (!localStorage.getItem('startTime')) {
localStorage.setItem('startTime', dayjs().format('YYYY-MM-DD HH:mm:ss'));
}
visibilitywindow();
}
}, []);
localStorage.setItem('startTime', dayjs().format('YYYY-MM-DD HH:mm:ss'));
切换应用—切换浏览器tab
关闭浏览器
清除后台–alt+tab清除所在浏览器
锁屏–电脑锁屏
使用软件 Fiddler,可查看传递参数,请求返回
fiddler的session图标图片含义解释
关闭电脑防火墙
cmd-ipconfig获取ip地址
拼接地址手机访问即可