From 86522ff5897d44024b9d35012e9020aec6161e14 Mon Sep 17 00:00:00 2001 From: qubiaobiao <3294694717@qq.com> Date: Wed, 28 Aug 2024 10:47:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E8=BF=9E=E6=8E=A5=E7=8A=B6=E6=80=81=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/render/stores/modules/network/index.ts | 14 +++++++++++++- .../SystemSettingsModalView/ConnectNetworkView.vue | 14 ++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) 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 ? '已连接' : '连 接' } ) } }