2
2
<n-card bordered shadow =" always" >
3
3
<n-grid x-gap =" 12" :cols =" 2" >
4
4
<n-gi >
5
- <p >摄像头服务:<n-tag :type =" runCamera ? 'success' : 'error'" >{{ runCamera ? '运行中' : '未运行' }}</n-tag ></p >
6
- {{ cameraInfo }}
5
+ <n-space >
6
+ <p >摄像头服务:</p >
7
+ <n-tag :type =" hasCamera ? 'success' : 'error'" >{{ hasCamera ? '已连接' : '未连接' }}</n-tag >
8
+ <n-tag :type =" runCamera ? 'success' : 'error'" >{{ runCamera ? '运行中' : '未运行' }}</n-tag >
9
+ </n-space >
7
10
<n-space >
8
11
<n-button size =" small" type =" primary" @click =" runService('vlc-webcam', 'restart')" >启动</n-button >
9
12
<n-button size =" small" type =" error" @click =" runService('vlc-webcam', 'stop')" >停止</n-button >
10
13
<n-button size =" small" type =" info" @click =" runVLC('webcam')" >测试</n-button >
11
14
<n-button size =" small" type =" warning" @click =" runService('vlc-webcam', 'enable')" >激活</n-button >
15
+ <n-button size =" small" @click =" statusService('vlc-webcam')" >状态</n-button >
12
16
</n-space >
13
17
<p >屏幕捕获服务:<n-tag :type =" runScreen ? 'success' : 'error'" >{{ runScreen ? '运行中' : '未运行' }}</n-tag ></p >
14
- {{ screenInfo }}
15
18
<n-space >
16
19
<n-button size =" small" type =" primary" @click =" runService('vlc-screen', 'restart')" >启动</n-button >
17
- <n-button size =" small" type =" primary " @click =" runService('vlc-screen', 'stop')" >停止</n-button >
18
- <n-button size =" small" type =" error " @click =" runVLC('screen')" >测试</n-button >
20
+ <n-button size =" small" type =" error " @click =" runService('vlc-screen', 'stop')" >停止</n-button >
21
+ <n-button size =" small" type =" info " @click =" runVLC('screen')" >测试</n-button >
19
22
<n-button size =" small" type =" warning" @click =" runService('vlc-screen', 'enable')" >激活</n-button >
23
+ <n-button size =" small" @click =" statusService('vlc-screen')" >状态</n-button >
20
24
</n-space >
21
25
</n-gi >
22
26
<n-gi >
23
27
<n-tabs default-value =" video" justify-content =" space-evenly" type =" line" animated >
24
28
<n-tab-pane name =" video" tab =" 视频配置" >
25
- <n-input type =" textarea" rows =" 4 " placeholder =" 配置文件" v-model:value =" cameraInfo" ></n-input >
29
+ <n-input type =" textarea" : rows =" 6 " placeholder =" 配置文件" v-model:value =" cameraInfo" ></n-input >
26
30
<n-button size =" small" block type =" primary" >保存</n-button >
27
31
</n-tab-pane >
28
32
<n-tab-pane name =" desktop" tab =" 桌面配置" >
29
- <n-input type =" textarea" rows =" 4 " placeholder =" 配置文件" v-model:value =" screenInfo" ></n-input >
33
+ <n-input type =" textarea" : rows =" 6 " placeholder =" 配置文件" v-model:value =" screenInfo" ></n-input >
30
34
<n-button size =" small" block type =" primary" >保存</n-button >
31
35
</n-tab-pane >
32
36
</n-tabs >
@@ -49,15 +53,20 @@ const cameraInfo = ref('');
49
53
const screenInfo = ref (' ' );
50
54
51
55
const runService = async (service : string , action : string ) => {
52
-
56
+ if (service === ' vlc-webcam' && ! hasCamera .value ) {
57
+ window .$notification .error ({ title: ' 摄像头未连接' , content: ' 请检查摄像头连接后再操作' , duration: 3000 });
58
+ return ;
59
+ }
53
60
try {
54
61
const res = await os .execCommand (` systemctl ${action } ${service } ` );
55
- console .log (` systemctl ${action } ${service } status ` , res );
56
- if (res .stdErr || res . exitCode ) throw new Error (res .stdErr );
62
+ console .log (` systemctl ${action } ${service } status ` , res . stdOut );
63
+ if (res .stdErr ) throw new Error (res .stdErr );
57
64
if (action === ' restart' ) {
65
+ const status = await os .execCommand (` systemctl status ${service } ` );
66
+ if (status .stdOut .includes (' dead' ) && status .stdOut .includes (' exited' )) throw new Error (' 服务启动失败' );
58
67
if (service === ' vlc-screen' ) runScreen .value = true ;
59
68
if (service === ' vlc-webcam' ) runCamera .value = true ;
60
- } else {
69
+ } else if ( action === ' stop ' ) {
61
70
if (service === ' vlc-screen' ) runScreen .value = false ;
62
71
if (service === ' vlc-webcam' ) runCamera .value = false ;
63
72
}
@@ -72,14 +81,25 @@ const runVLC = async (service: string) => {
72
81
try {
73
82
const res = await os .execCommand (` su icpc -c "vlc http://localhost:${port }/" ` );
74
83
console .log (' run vlc on test' , res );
75
- if (res .stdErr || res . exitCode ) throw new Error (res .stdErr );
84
+ if (res .exitCode ) throw new Error (res .stdErr );
76
85
window .$notification .success ({ title: ' VLC启动成功' , content: ' 请查看VLC播放器,确认视频正常后关闭' , duration: 3000 });
77
86
} catch (error ) {
78
87
console .error (error );
79
88
window .$notification .error ({ title: ' VLC启动失败' , content: (error as any ).message , duration: 3000 });
80
89
}
81
90
}
82
91
92
+ const statusService = async (service : string ) => {
93
+ try {
94
+ const res = await os .execCommand (` systemctl status ${service } ` );
95
+ if (res .stdErr ) throw new Error (res .stdErr );
96
+ window .$notification .success ({ title: ' 状态获取成功' , content: res .stdOut , duration: 10000 });
97
+ } catch (error ) {
98
+ console .error (error );
99
+ window .$notification .error ({ title: ' 状态获取失败' , content: (error as any ).message , duration: 3000 });
100
+ }
101
+ };
102
+
83
103
84
104
onMounted (async () => {
85
105
try {
@@ -96,11 +116,11 @@ onMounted(async () => {
96
116
}
97
117
try {
98
118
const res = await os .execCommand (' systemctl status vlc-screen' );
99
- console .log (' systemctl status vlc-screen status' , res );
100
- if (! res .stdOut .includes (' dead' )) runScreen .value = true ;
119
+ console .log (' systemctl status vlc-screen status' , res . stdOut );
120
+ if (! res .stdOut .includes (' dead' ) && ! res . stdOut . includes ( ' exited ' ) ) runScreen .value = true ;
101
121
const res2 = await os .execCommand (' systemctl status vlc-webcam' );
102
- console .log (' systemctl status vlc-webcam status' , res2 );
103
- if (! res2 .stdOut .includes (' dead' )) runCamera .value = true ;
122
+ console .log (' systemctl status vlc-webcam status' , res2 . stdOut );
123
+ if (! res2 .stdOut .includes (' dead' ) && ! res . stdOut . includes ( ' exited ' ) ) runCamera .value = true ;
104
124
} catch (error ) {
105
125
console .error (error );
106
126
}
0 commit comments