niujiuru 2 недель назад
Родитель
Сommit
8c3e64c616

+ 2 - 0
web-ui.service/web/app.html

@@ -28,6 +28,8 @@
       <span id="sys-time" class="clock">--</span>
       <!-- 退出系统 -->
       <button class="btn btn-red" onclick="logout()">退出</button>
+      <!-- 退出系统 -->
+      <button class="btn btn-red" onclick="reboot()">重启</button>
     </div>
   </header>
 

+ 48 - 0
web-ui.service/web/pages/page1.html

@@ -73,6 +73,12 @@
           </div>
           <span class="info-value" id="var1">--</span>
           <span class="info-value" id="var11">--</span>
+          <button class="btn" style="margin-right:32px;" onclick="switch1FVersion('factory')">
+            出厂版本
+          </button>
+          <button class="btn" onclick="switch1PVersion('previous')">
+            上一版本
+          </button>
         </div>
 
         <div class="info-item">
@@ -82,6 +88,12 @@
           </div>
           <span class="info-value" id="var2">--</span>
           <span class="info-value" id="var22">--</span>
+          <button class="btn" style="margin-right:32px;" onclick="switch2FVersion('factory')">
+            出厂版本
+          </button>
+          <button class="btn" onclick="switch2PVersion('previous')">
+            上一版本
+          </button>
         </div>
 
         <div class="info-item">
@@ -91,6 +103,12 @@
           </div>
           <span class="info-value" id="var3">--</span>
           <span class="info-value" id="var33">--</span>
+          <button class="btn" style="margin-right:32px;" onclick="switch3FVersion('factory')">
+            出厂版本
+          </button>
+          <button class="btn" onclick="switch3PVersion('previous')">
+            上一版本
+          </button>
         </div>
 
         <div class="info-item">
@@ -100,6 +118,12 @@
           </div>
           <span class="info-value" id="var4">--</span>
           <span class="info-value" id="var44">--</span>
+          <button class="btn" style="margin-right:32px;" onclick="switch4FVersion('factory')">
+            出厂版本
+          </button>
+          <button class="btn" onclick="switch4PVersion('previous')">
+            上一版本
+          </button>
         </div>
 
         <div class="info-item">
@@ -109,6 +133,12 @@
           </div>
           <span class="info-value" id="var5">--</span>
           <span class="info-value" id="var55">--</span>
+          <button class="btn" style="margin-right:32px;" onclick="switch5FVersion('factory')">
+            出厂版本
+          </button>
+          <button class="btn" onclick="switch5PVersion('previous')">
+            上一版本
+          </button>
         </div>
 
         <div class="info-item">
@@ -118,6 +148,12 @@
           </div>
           <span class="info-value" id="var6">--</span>
           <span class="info-value" id="var66">--</span>
+          <button class="btn" style="margin-right:32px;" onclick="switch6FVersion('factory')">
+            出厂版本
+          </button>
+          <button class="btn" onclick="switch6PVersion('previous')">
+            上一版本
+          </button>
         </div>
 
         <div class="info-item">
@@ -127,6 +163,12 @@
           </div>
           <span class="info-value" id="var7">--</span>
           <span class="info-value" id="var77">--</span>
+          <button class="btn" style="margin-right:32px;" onclick="switch7FVersion('factory')">
+            出厂版本
+          </button>
+          <button class="btn" onclick="switch7PVersion('previous')">
+            上一版本
+          </button>
         </div>
 
         <div class="info-item">
@@ -136,6 +178,12 @@
           </div>
           <span class="info-value" id="var8">--</span>
           <span class="info-value" id="var88">--</span>
+          <button class="btn" style="margin-right:32px;" onclick="enableAutoUpgrade">
+            开启升级
+          </button>
+          <button class="btn" onclick="disableAutoUpgrade('previous')">
+            关闭升级
+          </button>
         </div>
       </div>
     </div>

+ 2 - 2
web-ui.service/web/static/css/page1.css

@@ -58,7 +58,7 @@
 }
 
 .info-name {
-    width:160px;
+    width:150px;
     flex-shrink:0;
     color:#cbd5e1;
     font-size:14px;
@@ -71,7 +71,7 @@
 }
 
 .info-value {
-    width:160px;
+    width:150px;
     margin-left:8px;
     text-align:center;
     color:#94a3b8;

+ 18 - 1
web-ui.service/web/static/js/app.js

@@ -95,11 +95,28 @@ function startSysTime() {
   sysTimeTimer = setInterval(update, 1000);
 }
 
-
 document.addEventListener("DOMContentLoaded", () => {
   startSysTime();
 });
 
+function reboot() {
+  if (!confirm("确定重启设备吗?")) return;
+
+  fetch("/api/system/reboot", {
+    method: "POST"
+  })
+  .then(r => r.json())
+  .then(d => {
+    if (d.ok) {
+      alert("设备正在重启...");
+      setTimeout(logout, 1000);
+    } else {
+      alert("重启失败: " + d.error);
+    }
+  })
+  .catch(e => alert("请求失败: " + e));
+}
+
 function loadIMEI() {
   fetchIMEI();
 }

+ 13 - 0
web-ui.service/web_handler.go

@@ -10,6 +10,7 @@ import (
 	"os"
 	"os/exec"
 	"strings"
+	"time"
 
 	"hnyfkj.com.cn/rtu/linux/baseapp"
 	"hnyfkj.com.cn/rtu/linux/utils/jsonrpc2"
@@ -83,6 +84,18 @@ func getIMEIHandler(w http.ResponseWriter, r *http.Request) {
 	}
 }
 
+func systemRebootHandler(w http.ResponseWriter, r *http.Request) {
+	json.NewEncoder(w).Encode(map[string]bool{
+		"ok": true,
+	})
+
+	go func() {
+		time.Sleep(2 * time.Second)
+		exec.Command("systemctl", "reboot").Run()
+	}()
+
+}
+
 func (ui *WebUI) rootHandler(w http.ResponseWriter, r *http.Request) {
 	path := r.URL.Path
 

+ 5 - 0
web-ui.service/web_route.go

@@ -24,6 +24,11 @@ var routes = []Route{
 	},
 
 	{
+		"/api/system/reboot",
+		systemRebootHandler,
+	},
+
+	{
 		"/api/service/log",
 		serviceLogHandler,
 	},