Skip to content

Commit 0437c75

Browse files
committed
machine-setup: add popconfirm info for check all
1 parent adfbca0 commit 0437c75

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
</n-gi>
2020
<n-gi>
2121
<n-card bordered shadow="always">
22-
<n-popconfirm @positive-click="checkAll">
22+
<n-popconfirm @positive-click="checkAll(false)" positive-text="开始检查" negative-text="强制完成" @negative-click="checkAll(true)">
2323
<template #trigger>
2424
<n-button type="primary" style="width: 100%;">完成设备检查</n-button>
2525
</template>
26-
确认完成设备检查?
26+
确认完成设备检查?<br />
27+
设备座位号:{{ nowSeat || '未设置' }}<br />
28+
设备IP地址:{{ getIp() || '未获取' }}
2729
</n-popconfirm>
2830
</n-card>
2931
<n-card bordered shadow="always" class="text-center">
@@ -53,7 +55,7 @@ const saveSeat = async () => {
5355
nowSeat.value = editSeat.value;
5456
} catch (error) {
5557
console.error(error);
56-
window.$notification.error({ title: '保存座位号失败', content: (error as any).message });
58+
window.$notification.error({ title: '保存座位号失败', content: (error as any).message, duration: 3000 });
5759
}
5860
};
5961
@@ -64,14 +66,34 @@ const showSeat = async () => {
6466
if (res.stdErr) throw new Error(res.stdErr);
6567
} catch (error) {
6668
console.error(error);
67-
window.$notification.error({ title: '放大显示座位号失败', content: (error as any).message });
69+
window.$notification.error({ title: '放大显示座位号失败', content: (error as any).message, duration: 3000 });
6870
}
6971
};
7072
71-
const checkAll = () => {
72-
console.log('check all');
73+
const checkAll = async (force = false) => {
74+
if (force) {
75+
if (!nowSeat.value) {
76+
window.$notification.error({ title: '未设置座位号', content: '请先设置座位号', duration: 3000 });
77+
return;
78+
}
79+
const res = await filesystem.readFile('/etc/hostname');
80+
if (res !== nowSeat.value) {
81+
window.$notification.error({ title: '主机名不匹配', content: '请保存一次座位号以同步主机名', duration: 3000 });
82+
return;
83+
}
84+
if (!getIp()) {
85+
window.$notification.error({ title: '未获取到IP地址', content: '请检查网络连接或重启', duration: 3000 });
86+
return;
87+
}
88+
window.$notification.success({ title: '设备检查完成', content: `seat: ${nowSeat.value}\nip: ${window.ip}`, duration: 3000 });
89+
}
90+
await os.execCommand(`systemctl enable heartbeat.timer`);
91+
await os.execCommand(`zenity --info --text "<span font='256'>${nowSeat.value}</span><br><span font='128'>${window.ip}</span>"`);
92+
console.log('check all');
7393
};
7494
95+
const getIp = () => window.ip;
96+
7597
onMounted(async () => {
7698
try {
7799
const res = await filesystem.readFile('/var/lib/icpc/config.json');

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ import { onMounted, ref } from 'vue';
1717
1818
const netInfo = ref<any[]>([]);
1919
20+
declare global {
21+
interface Window {
22+
ip: string;
23+
}
24+
}
25+
2026
onMounted(async () => {
2127
try {
2228
const res = await os.execCommand('ip --json address');
2329
const info = JSON.parse(res.stdOut);
24-
console.log(info);
2530
const ips = info.filter((i: any) => {
2631
const local = i.addr_info?.filter((a: any) => a.family === 'inet')[0]?.local;
2732
return local && (local.startsWith('10') || local.startsWith('192.168') || local.startsWith('172.16'));
@@ -32,6 +37,7 @@ onMounted(async () => {
3237
mac: i.address
3338
}));
3439
netInfo.value = ips;
40+
window.ip = ips?.[0]?.v4;
3541
} catch (error) {
3642
console.error(error);
3743

0 commit comments

Comments
 (0)