1
1
<template >
2
2
<n-card bordered title =" 网络信息" shadow =" always" >
3
3
<n-grid x-gap =" 12" :cols =" 2" >
4
- <n-gi v-for =" info in netInfo" :key =" info.dev" >
5
- <p >{{ info.dev }}/{{ info.mac }}</p >
6
- <p >IPV4: {{ info.v4 }}</p >
7
- <p >IPV6: {{ info.v6 }}</p >
4
+ <n-gi >
5
+ <p v-if =" netInfo.length === 0" >No network information found.</p >
6
+ <div style =" overflow : auto ; height : 220px ;" >
7
+ <template v-for =" info in netInfo " :key =" info .dev " >
8
+ <p >{{ info.dev }}/{{ info.mac }}</p >
9
+ <p >IPV4: {{ info.v4 }}</p >
10
+ <p >IPV6: {{ info.v6 }}</p >
11
+ </template >
12
+ </div >
13
+ </n-gi >
14
+ <n-gi >
15
+ <n-space >
16
+ <n-button size =" small" type =" primary" @click =" statusDetect" >查看detect-wifi服务</n-button >
17
+ <n-button size =" small" type =" warning" @click =" runDetect" >自动选择wifi网卡生成默认配置</n-button >
18
+ <p >非授权请勿手动设置wifi!</p >
19
+ <n-input size =" small" v-model:value =" ssid" placeholder =" ssid" />
20
+ <n-input size =" small" v-model:value =" password" placeholder =" password" />
21
+ <n-button size =" small" type =" info" @click =" saveConfig" >保存</n-button >
22
+ </n-space >
8
23
</n-gi >
9
24
</n-grid >
10
- <p v-if =" netInfo.length === 0" >No network information found.</p >
11
25
</n-card >
12
26
</template >
13
27
14
28
<script setup lang="ts">
15
- import { os } from ' @neutralinojs/lib' ;
29
+ import { filesystem , os } from ' @neutralinojs/lib' ;
30
+ import { NCard , NGrid , NGi , NButton , NInput , NSpace } from ' naive-ui' ;
16
31
import { onMounted , ref } from ' vue' ;
17
32
18
33
const netInfo = ref <any []>([]);
@@ -23,6 +38,43 @@ declare global {
23
38
}
24
39
}
25
40
41
+ const statusDetect = async () => {
42
+ try {
43
+ const res = await os .execCommand (` systemctl status detect-wireless-interface ` );
44
+ if (res .stdErr ) throw new Error (res .stdErr );
45
+ window .$notification .success ({ title: ' 状态获取成功' , content: res .stdOut , duration: 10000 });
46
+ } catch (error ) {
47
+ console .error (error );
48
+ window .$notification .error ({ title: ' 状态获取失败' , content: (error as any ).message , duration: 3000 });
49
+ }
50
+ };
51
+
52
+ const runDetect = async () => {
53
+ try {
54
+ const config = await filesystem .readFile (' /etc/default/wifi-setup' );
55
+ const res = await os .execCommand (` ${config .replace (/ \\ n/ g , ' ' )} /usr/sbin/detect-wireless-interface ` );
56
+ if (res .stdErr ) throw new Error (res .stdErr );
57
+ window .$notification .success ({ title: ' 自动选择wifi网卡成功' , content: res .stdOut , duration: 10000 });
58
+ } catch (error ) {
59
+ console .error (error );
60
+ window .$notification .error ({ title: ' 自动选择wifi网卡失败' , content: (error as any ).message , duration: 3000 });
61
+ }
62
+ };
63
+
64
+ const ssid = ref (' ' );
65
+ const password = ref (' ' );
66
+
67
+ const saveConfig = async () => {
68
+ try {
69
+ const res = await os .execCommand (` WIFI_SSID=${ssid .value } WIFI_PASS=${password .value } /usr/sbin/detect-wireless-interface ` );
70
+ if (res .stdErr ) throw new Error (res .stdErr );
71
+ window .$notification .success ({ title: ' 配置保存成功' , content: res .stdOut , duration: 3000 });
72
+ } catch (error ) {
73
+ console .error (error );
74
+ window .$notification .error ({ title: ' 配置保存失败' , content: (error as any ).message , duration: 3000 });
75
+ }
76
+ };
77
+
26
78
onMounted (async () => {
27
79
try {
28
80
const res = await os .execCommand (' ip --json address' );
0 commit comments