1
1
<template >
2
- <n-card bordered shadow =" always" title =" @Hydro/XCPC-TOOLS Setup Tool" >
3
- <n-statistic title =" 座位号" value =" 未配置" style =" text-align : center ; font-size : 8em ;" />
4
- </n-card >
5
- <n-card bordered shadow =" always" >
6
- <n-input placeholder =" 请输入座位号" type =" text" size =" large" style =" width : 100% ; margin-bottom : .5em ;" />
7
- <n-space style =" width : 100% ;" >
8
- <n-button type =" primary" style =" width : 100% ;" >保存</n-button >
9
- <n-button type =" info" style =" width : 100% ;" >放大显示</n-button >
10
- </n-space >
11
- </n-card >
2
+ <n-grid x-gap =" 6" :cols =" 2" >
3
+ <n-gi >
4
+ <n-card bordered shadow =" always" style =" margin-bottom : .25em ;" class =" text-center" >
5
+ <h2 style =" margin : .5em 0 ;" >@Hydro/XCPC-TOOLS</h2 >
6
+ <h2 style =" margin : .5em 0 ;" >Setup Tool</h2 >
7
+ </n-card >
8
+ <n-card bordered shadow =" always" >
9
+ <n-input placeholder =" 请输入座位号" v-model:value =" editSeat" type =" text" size =" large" style =" width : 100% ; margin-bottom : .5em ;" />
10
+ <n-grid x-gap =" 12" :cols =" 2" style =" width : 100% ;" >
11
+ <n-gi >
12
+ <n-button type =" primary" @click =" saveSeat" style =" width : 100% ;" >保存</n-button >
13
+ </n-gi >
14
+ <n-gi >
15
+ <n-button type =" info" @click =" showSeat" style =" width : 100% ;" >放大显示</n-button >
16
+ </n-gi >
17
+ </n-grid >
18
+ </n-card >
19
+ </n-gi >
20
+ <n-gi >
21
+ <n-card bordered shadow =" always" class =" text-center" >
22
+ <h1 style =" margin : 0 ;" >座位号</h1 >
23
+ <h1 style =" font-size : 8em ; margin : 0 ;" >{{ nowSeat || '未配置' }}</h1 >
24
+ </n-card >
25
+ </n-gi >
26
+ </n-grid >
12
27
</template >
13
28
14
29
<script setup lang="ts">
15
- import { NCard , NButton , NInput } from ' naive-ui' ;
30
+ import { filesystem , os } from ' @neutralinojs/lib' ;
31
+ import { NCard , NGrid , NGi , NButton , NInput } from ' naive-ui' ;
32
+ import { onMounted , ref } from ' vue' ;
33
+
34
+ const nowSeat = ref (' ' );
35
+ const editSeat = ref (' ' );
36
+
37
+ const saveSeat = async () => {
38
+ try {
39
+ console .log (' save seat' , editSeat .value );
40
+ await filesystem .writeFile (' /var/lib/icpc/config.json' , JSON .stringify ({ seat: editSeat .value }));
41
+ const read = await filesystem .readFile (' /var/lib/icpc/config.json' );
42
+ console .log (' read seat' , read );
43
+ const res = await os .execCommand (` hostnamectl set-hostname ${editSeat .value } ` );
44
+ console .log (' run hostnamectl' , res );
45
+ nowSeat .value = editSeat .value ;
46
+ } catch (error ) {
47
+ console .error (error );
48
+ window .$notification .error ({ title: ' 保存座位号失败' , content: (error as any ).message });
49
+ }
50
+ };
51
+
52
+ const showSeat = async () => {
53
+ try {
54
+ console .log (' show seat' , nowSeat .value );
55
+ const res = await os .execCommand (` zenity --info --text "<span font='256'>${nowSeat .value }</span>" ` );
56
+ if (res .stdErr ) throw new Error (res .stdErr );
57
+ } catch (error ) {
58
+ console .error (error );
59
+ window .$notification .error ({ title: ' 放大显示座位号失败' , content: (error as any ).message });
60
+ }
61
+ };
62
+
63
+
64
+ onMounted (async () => {
65
+ try {
66
+ const res = await filesystem .readFile (' /var/lib/icpc/config.json' );
67
+ nowSeat .value = JSON .parse (res || ' {}' ).seat || ' ' ;
68
+ } catch (error ) {
69
+ console .error (error );
70
+ }
71
+ });
16
72
</script >
0 commit comments