修复无法判断连接状态的问题

master
qubiaobiao 2024-08-28 10:47:02 +08:00
parent b3a565930b
commit 86522ff589
2 changed files with 23 additions and 5 deletions

View File

@ -5,14 +5,26 @@ import { useMessage } from 'naive-ui'
export const useNetworkStore = defineStore('network', () => {
const message = useMessage()
const isOnLine = ref(window.navigator.onLine)
let checkLine
const setCheck = () => {
checkLine = setTimeout(() => {
if(isOnLine.value) {
message.success('连接成功')
} else {
message.error('连接失败')
}
}, 5000)
}
window.addEventListener( 'online' , () => {
isOnLine.value = true
clearTimeout(checkLine)
message.success('连接成功')
} )
window.addEventListener( 'offline', () => {
isOnLine.value = false
clearTimeout(checkLine)
message.error('连接失败')
} )
return { isOnLine }
return { isOnLine, setCheck }
})

View File

@ -25,6 +25,9 @@ import { h, ref } from 'vue'
import { NDivider, NCard, NDataTable, NInput, NButton, NIcon, useMessage } from 'naive-ui'
import { Wifi1BarFilled, Wifi2BarFilled, WifiFilled, RefreshFilled } from '@vicons/material'
import { hasIpcRenderer } from '@/utils'
import { useNetworkStore } from '@/stores/modules/network'
const network = useNetworkStore()
const emit = defineEmits(['done'])
@ -74,12 +77,15 @@ const columns = [
return h(
NButton,
{
type: row.ssid === current.value?.ssid ? 'primary' : 'info',
type: row.ssid === current.value?.ssid && network.isOnLine ? 'primary' : 'info',
secondary: true,
disabled: row.ssid === current.value?.ssid || !row.password || row.password.length < 8,
onClick: () => connect({ ssid:row.ssid, password: row.password })
disabled: row.ssid === current.value?.ssid && network.isOnLine || !row.password || row.password.length < 8,
onClick: () => {
connect({ ssid:row.ssid, password: row.password })
network.setCheck();
}
},
{ default: () => row.ssid === current.value?.ssid ? '已连接' : '连 接' }
{ default: () => row.ssid === current.value?.ssid && network.isOnLine ? '已连接' : '连 接' }
)
}
}