diff --git a/src/render/stores/modules/network/index.ts b/src/render/stores/modules/network/index.ts index 13b39fb..d9c228b 100644 --- a/src/render/stores/modules/network/index.ts +++ b/src/render/stores/modules/network/index.ts @@ -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 } }) diff --git a/src/render/views/index/SystemSettingsModalView/ConnectNetworkView.vue b/src/render/views/index/SystemSettingsModalView/ConnectNetworkView.vue index d7f6faa..088bd31 100644 --- a/src/render/views/index/SystemSettingsModalView/ConnectNetworkView.vue +++ b/src/render/views/index/SystemSettingsModalView/ConnectNetworkView.vue @@ -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 ? '已连接' : '连 接' } ) } }