修复无法判断连接状态的问题
parent
b3a565930b
commit
86522ff589
|
@ -5,14 +5,26 @@ import { useMessage } from 'naive-ui'
|
||||||
export const useNetworkStore = defineStore('network', () => {
|
export const useNetworkStore = defineStore('network', () => {
|
||||||
const message = useMessage()
|
const message = useMessage()
|
||||||
const isOnLine = ref(window.navigator.onLine)
|
const isOnLine = ref(window.navigator.onLine)
|
||||||
|
let checkLine
|
||||||
|
const setCheck = () => {
|
||||||
|
checkLine = setTimeout(() => {
|
||||||
|
if(isOnLine.value) {
|
||||||
|
message.success('连接成功')
|
||||||
|
} else {
|
||||||
|
message.error('连接失败')
|
||||||
|
}
|
||||||
|
}, 5000)
|
||||||
|
}
|
||||||
window.addEventListener( 'online' , () => {
|
window.addEventListener( 'online' , () => {
|
||||||
isOnLine.value = true
|
isOnLine.value = true
|
||||||
|
clearTimeout(checkLine)
|
||||||
message.success('连接成功')
|
message.success('连接成功')
|
||||||
} )
|
} )
|
||||||
window.addEventListener( 'offline', () => {
|
window.addEventListener( 'offline', () => {
|
||||||
isOnLine.value = false
|
isOnLine.value = false
|
||||||
|
clearTimeout(checkLine)
|
||||||
message.error('连接失败')
|
message.error('连接失败')
|
||||||
} )
|
} )
|
||||||
|
|
||||||
return { isOnLine }
|
return { isOnLine, setCheck }
|
||||||
})
|
})
|
||||||
|
|
|
@ -25,6 +25,9 @@ import { h, ref } from 'vue'
|
||||||
import { NDivider, NCard, NDataTable, NInput, NButton, NIcon, useMessage } from 'naive-ui'
|
import { NDivider, NCard, NDataTable, NInput, NButton, NIcon, useMessage } from 'naive-ui'
|
||||||
import { Wifi1BarFilled, Wifi2BarFilled, WifiFilled, RefreshFilled } from '@vicons/material'
|
import { Wifi1BarFilled, Wifi2BarFilled, WifiFilled, RefreshFilled } from '@vicons/material'
|
||||||
import { hasIpcRenderer } from '@/utils'
|
import { hasIpcRenderer } from '@/utils'
|
||||||
|
import { useNetworkStore } from '@/stores/modules/network'
|
||||||
|
|
||||||
|
const network = useNetworkStore()
|
||||||
|
|
||||||
const emit = defineEmits(['done'])
|
const emit = defineEmits(['done'])
|
||||||
|
|
||||||
|
@ -74,12 +77,15 @@ const columns = [
|
||||||
return h(
|
return h(
|
||||||
NButton,
|
NButton,
|
||||||
{
|
{
|
||||||
type: row.ssid === current.value?.ssid ? 'primary' : 'info',
|
type: row.ssid === current.value?.ssid && network.isOnLine ? 'primary' : 'info',
|
||||||
secondary: true,
|
secondary: true,
|
||||||
disabled: row.ssid === current.value?.ssid || !row.password || row.password.length < 8,
|
disabled: row.ssid === current.value?.ssid && network.isOnLine || !row.password || row.password.length < 8,
|
||||||
onClick: () => connect({ ssid:row.ssid, password: row.password })
|
onClick: () => {
|
||||||
|
connect({ ssid:row.ssid, password: row.password })
|
||||||
|
network.setCheck();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{ default: () => row.ssid === current.value?.ssid ? '已连接' : '连 接' }
|
{ default: () => row.ssid === current.value?.ssid && network.isOnLine ? '已连接' : '连 接' }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue