Prechádzať zdrojové kódy

新增查看设备自动升级配置的页面展示

niujiuru 2 dní pred
rodič
commit
54d3622fd0

+ 9 - 0
web-ui.service/page1_handler.go

@@ -670,3 +670,12 @@ func downloadUpgradeLog(w http.ResponseWriter, r *http.Request) {
 
 	http.ServeFile(w, r, tmpFile)
 }
+
+func getUpgradeConfig(w http.ResponseWriter, r *http.Request) {
+	switch r.Method {
+	case http.MethodGet:
+		callRPCResponse(w, r, 7005, "core.getUpgradeConf", nil)
+	default:
+		http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
+	}
+}

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

@@ -19,6 +19,7 @@
 <link rel="stylesheet" href="static/css/page7.css?v={{V}}">
 <link rel="stylesheet" href="static/css/page8.css?v={{V}}">
 <link rel="stylesheet" href="static/css/page9.css?v={{V}}">
+<link rel="stylesheet" href="static/css/jsonview.css?v={{V}}">
 </head>
 
 <body>
@@ -98,12 +99,27 @@
     </main>
   </div>
 </div>
+
+<!-- JSON查看弹窗 -->
+<div class="jsonview" id="jsonview">
+  <div class="jsonview-dialog">
+    <div class="jsonview-header">
+      <h2 id="jsonview-title">配置查看</h2>
+      <button class="jsonview-close" type="button" title="关闭" onclick="closeJsonView()">&times;</button>
+    </div>
+    <div class="jsonview-body">
+      <pre id="jsonview-content"></pre>
+    </div>
+  </div>
+</div>
+
 <!-- 兼容层:顺序不可调换(fetch 依赖 Promise),且须在业务 JS 之前 -->
 <script src="static/js/promise.min.js?v={{V}}"></script>
 <script src="static/js/fetch.min.js?v={{V}}"></script>
 <script src="static/js/eventsource.min.js?v={{V}}"></script>
 <script src="static/js/compat.js?v={{V}}"></script>
 <script src="static/js/util.js?v={{V}}"></script>
+<script src="static/js/jsonview.js?v={{V}}"></script>
 <script src="static/js/echarts.min.js?v={{V}}"></script>
 <script src="static/js/xterm.js?v={{V}}"></script>
 <script src="static/js/xterm-addon-fit.js?v={{V}}"></script>

+ 1 - 1
web-ui.service/web/pages/page1.html

@@ -176,7 +176,7 @@
 
         <div class="info-item">
           <div class="info-info">
-            <div class="info-name">设备自动升级</div>
+            <div class="info-name clickable" onclick="viewUpgradeConf()">设备自动升级</div>
             <div class="info-desc">upgrade.service</div>
           </div>
           <span class="info-value" id="var9">--</span>

+ 5 - 15
web-ui.service/web/pages/page9.html

@@ -1,4 +1,3 @@
-
 <!doctype html>
 <html lang="zh-CN">
 
@@ -107,6 +106,11 @@
           <div class="card firmware-card">
             <div class="card-header">
               <h2>固件升级</h2>
+              <button class="btn" id="p9AuthBtn" title="点击授权解锁操作" onclick="enablePUpgradeButtons()">
+                <svg class="icon">
+                  <use href="#i-unlock" xlink:href="#i-unlock"/>
+                </svg>
+              </button>
             </div>
             <div class="firmware-content">
             </div>
@@ -141,20 +145,6 @@
           </div>
         </div>
       </div>
-
-      <!-- 服务器配置弹窗 -->
-      <div class="config-modal" id="p9ConfigModal">
-        <div class="config-dialog">
-          <div class="config-header">
-            <h2>服务器配置</h2>
-            <button class="config-close" onclick="closeCBDServerConfig()">&times;</button>
-          </div>
-          <div class="config-body">
-            <pre id="p9ConfigContent">正在加载...</pre>
-          </div>
-        </div>
-      </div>
-
     </main>
   </div>
 </body>

+ 76 - 0
web-ui.service/web/static/css/jsonview.css

@@ -0,0 +1,76 @@
+/* JSON查看弹窗 */
+.jsonview {
+    display: none;
+    position: fixed;
+    inset: 0;
+    z-index: 1000;
+    padding: 20px;
+    background: rgba(0, 0, 0, 0.65);
+    align-items: center;
+    justify-content: center;
+}
+
+.jsonview.show {
+    display: flex;
+}
+
+.jsonview-dialog {
+    display: flex;
+    flex-direction: column;
+    width: 100%;
+    max-width: 760px;
+    max-height: 85vh;
+    background: #17243a;
+    border: 1px solid #30435f;
+    border-radius: 10px;
+    overflow: hidden;
+}
+
+.jsonview-header {
+    display: flex;
+    align-items: center;
+    justify-content: space-between;
+    flex: none;
+    padding: 14px 18px;
+    border-bottom: 1px solid #30435f;
+}
+
+.jsonview-header h2 {
+    min-width: 0;
+    font-size: 16px;
+    font-weight: 500;
+    color: #e2eaf5;
+    overflow-wrap: anywhere;
+}
+
+.jsonview-close {
+    flex: none;
+    margin-left: 16px;
+    padding: 0;
+    border: none;
+    background: none;
+    color: #9aacc5;
+    font-size: 26px;
+    line-height: 1;
+    cursor: pointer;
+}
+
+.jsonview-close:hover {
+    color: #ffffff;
+}
+
+.jsonview-body {
+    flex: 1;
+    min-height: 0;
+    overflow: auto;
+    padding: 16px;
+}
+
+.jsonview-body pre {
+    margin: 0;
+    color: #b9d5f5;
+    font-family: Consolas, "Courier New", monospace;
+    font-size: 13px;
+    line-height: 1.7;
+    white-space: pre;
+}

+ 4 - 0
web-ui.service/web/static/css/page1.css

@@ -71,6 +71,10 @@
     font-size: 14px;
 }
 
+.info-name.clickable {
+    cursor: pointer;
+}
+
 .page1 .info-desc {
     color: #64748b;
     font-size: 12px;

+ 0 - 66
web-ui.service/web/static/css/page9.css

@@ -1,4 +1,3 @@
-
 /* 页面整体布局 */
 .page-cbd {
     display: flex;
@@ -216,71 +215,6 @@
     min-height: 0;
 }
 
-/* 服务器配置弹窗 */
-.page-cbd .config-modal {
-    display: none;
-    position: fixed;
-    inset: 0;
-    z-index: 1000;
-    padding: 20px;
-    background: rgba(0, 0, 0, 0.65);
-    align-items: center;
-    justify-content: center;
-}
-
-.page-cbd .config-modal.show {
-    display: flex;
-}
-
-.page-cbd .config-dialog {
-    display: flex;
-    flex-direction: column;
-    width: 100%;
-    max-width: 760px;
-    max-height: 85vh;
-    background: #17243a;
-    border: 1px solid #30435f;
-    border-radius: 10px;
-    overflow: hidden;
-}
-
-.page-cbd .config-header {
-    display: flex;
-    align-items: center;
-    justify-content: space-between;
-    padding: 14px 18px;
-    border-bottom: 1px solid #30435f;
-}
-
-.page-cbd .config-header h2 {
-    font-size: 16px;
-    color: #e2eaf5;
-}
-
-.page-cbd .config-close {
-    border: 0;
-    background: none;
-    color: #9aacc5;
-    font-size: 26px;
-    cursor: pointer;
-}
-
-.page-cbd .config-body {
-    flex: 1;
-    min-height: 0;
-    overflow: auto;
-    padding: 16px;
-}
-
-.page-cbd .config-body pre {
-    margin: 0;
-    color: #b9d5f5;
-    font-family: Consolas, monospace;
-    font-size: 13px;
-    line-height: 1.7;
-    white-space: pre;
-}
-
 /* ================= 移动端适配 (≤768px) ================= */
 @media (max-width: 768px) {
     .page-cbd .panes {

+ 29 - 0
web-ui.service/web/static/js/jsonview.js

@@ -0,0 +1,29 @@
+function showJsonView(title, data) {
+    var dlg = document.getElementById("jsonview");
+    var content = document.getElementById("jsonview-content");
+
+    if (data === undefined || data === null) {
+        content.textContent = "暂无内容";
+    } else if (typeof data === "string") {
+        try {
+            content.textContent = JSON.stringify(JSON.parse(data), null, 2);
+        } catch (e) {
+            content.textContent = data;
+        }
+    } else {
+        try {
+            content.textContent = JSON.stringify(data, null, 2);
+        } catch (e) {
+            content.textContent = String(data);
+        }
+    }
+
+    document.getElementById("jsonview-title").textContent = title || "配置查看";
+
+    dlg.classList.add("show");
+    content.parentNode.scrollTop = 0;
+}
+
+function closeJsonView() {
+    document.getElementById("jsonview").classList.remove("show");
+}

+ 26 - 0
web-ui.service/web/static/js/page1.js

@@ -669,3 +669,29 @@ function dashSetUptime(text) {
         el.textContent = text || "--";
     }
 }
+
+function viewUpgradeConf() {
+    var password = prompt("请输入操作密码:");
+    if (password === null) {
+        return;
+    }
+    if (password !== "yfkj123456") {
+        alert("操作密码错误!");
+        return;
+    }
+
+    fetch("/api/upgrade/getUpgradeConf")
+        .then(function (r) {
+            if (!r.ok) {
+                throw new Error("HTTP " + r.status);
+            }
+            return r.json();
+        })
+        .then(function (data) {
+            showJsonView("设备自动升级配置", data);
+        })
+        .catch(function (e) {
+            console.error("viewUpgradeConf() failed:", e);
+            alert("获取设备自动升级配置失败:" + e.message);
+        });
+}

+ 2 - 12
web-ui.service/web/static/js/page9.js

@@ -131,12 +131,6 @@ function viewCBDServerConfig() {
         return;
     }
 
-    var modal = document.getElementById("p9ConfigModal");
-    var content = document.getElementById("p9ConfigContent");
-
-    content.textContent = "正在加载...";
-    modal.classList.add("show");
-
     fetch("/api/cbd/serverCfg")
         .then(function (r) {
             if (!r.ok) {
@@ -145,18 +139,14 @@ function viewCBDServerConfig() {
             return r.json();
         })
         .then(function (data) {
-            content.textContent = JSON.stringify(data, null, 2);
+            showJsonView("服务器配置", data);
         })
         .catch(function (e) {
             console.error("viewCBDServerConfig() failed:", e);
-            content.textContent = "获取服务器配置失败:" + e.message;
+            alert("获取服务器配置失败:" + e.message);
         });
 }
 
-function closeCBDServerConfig() {
-    document.getElementById("p9ConfigModal").classList.remove("show");
-}
-
 var cbdWorkStatusTimer = null;
 
 function getCBDWorkStatus() {

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

@@ -71,6 +71,11 @@ var routes = []Route{
 	},
 
 	{
+		"/api/upgrade/getUpgradeConf",
+		getUpgradeConfig,
+	},
+
+	{
 		"/api/network/interfaces",
 		netInterfaces,
 	},