Skip to content

Commit c4626de

Browse files
committed
machine-setup: add network config button
1 parent a68746c commit c4626de

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

packages/machine-setup/frontend/src/components/NetworkInfo.vue

+58-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
<template>
22
<n-card bordered title="网络信息" shadow="always">
33
<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>
823
</n-gi>
924
</n-grid>
10-
<p v-if="netInfo.length === 0">No network information found.</p>
1125
</n-card>
1226
</template>
1327

1428
<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';
1631
import { onMounted, ref } from 'vue';
1732
1833
const netInfo = ref<any[]>([]);
@@ -23,6 +38,43 @@ declare global {
2338
}
2439
}
2540
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+
2678
onMounted(async () => {
2779
try {
2880
const res = await os.execCommand('ip --json address');

packages/machine-setup/frontend/src/main.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import './style.css';
22

33
import { app, events, init } from '@neutralinojs/lib';
44
import {
5-
create, NButton, NCard, NConfigProvider, NGi, NGrid, NNotificationProvider,
5+
create, NButton, NCard, NConfigProvider, NGi, NGrid, NInput,
6+
NNotificationProvider,
67
NPopconfirm, NSpace, NStatistic, NTab, NTabPane, NTag,
78
} from 'naive-ui';
89
import { createApp } from 'vue';
910
import App from './App.vue';
1011

1112
const naive = create({
12-
components: [NButton, NGrid, NGi, NCard, NStatistic, NSpace, NConfigProvider, NTab, NTabPane, NTag, NNotificationProvider, NPopconfirm],
13+
components: [NButton, NGrid, NGi, NCard, NStatistic, NSpace, NConfigProvider, NTab, NTabPane, NTag, NNotificationProvider, NPopconfirm, NInput],
1314
});
1415

1516
createApp(App).use(naive).mount('#app');

0 commit comments

Comments
 (0)