1.增加网络判断刷新页面,防止没网无法连接ws
2.商品增加上下架、售罄、修改库存登操作
This commit is contained in:
34
src/App.vue
34
src/App.vue
@@ -164,24 +164,6 @@ async function getBarCode(e) {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取网络状态
|
||||
const updateInfo = _.throttle(function () {
|
||||
let isOnLine = navigator.onLine
|
||||
// // 获取网络信息
|
||||
// let info = navigator.connection
|
||||
console.log(isOnLine);
|
||||
// console.log(info);
|
||||
if (store.userInfo && store.userInfo.shopId) {
|
||||
if (isOnLine) {
|
||||
console.log('有网了重新连接ws~');
|
||||
socket.init();
|
||||
} else {
|
||||
socket.close();
|
||||
console.log('网络连接失败~');
|
||||
}
|
||||
}
|
||||
}, 100, { leading: true, trailing: false })
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener("keydown", (e) => {
|
||||
getBarCode(e);
|
||||
@@ -200,14 +182,16 @@ onMounted(() => {
|
||||
.catch(() => { });
|
||||
})
|
||||
|
||||
// listnerCloseDialog()
|
||||
|
||||
// // 监听网络在线状态
|
||||
// window.addEventListener("onLine", updateInfo)
|
||||
// // 监听网络离线
|
||||
// window.addEventListener("offLine", updateInfo)
|
||||
// 监听网络信息变化
|
||||
// navigator.connection.addEventListener('change', updateInfo)
|
||||
window.addEventListener('online', function () {
|
||||
console.log('有网络了');
|
||||
this.location.reload()
|
||||
})
|
||||
|
||||
window.addEventListener('offline', function () {
|
||||
ElMessage.warning('网络异常')
|
||||
socket.close()
|
||||
})
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user