Преглед изворни кода

优化webui代码,对齐rtu_linux_service基础模块的webui底座

niujiuru пре 1 дан
родитељ
комит
4b47f7f6da

+ 1 - 1
web-ui.service/main.go

@@ -12,7 +12,7 @@ import (
 )
 )
 
 
 var (
 var (
-	Version   = "0.0.0.6"
+	Version   = "0.0.1.0"
 	BuildTime = ""
 	BuildTime = ""
 )
 )
 
 

+ 1 - 1
web-ui.service/page1_handler.go

@@ -515,7 +515,7 @@ func serviceVersionSwitchHandler(w http.ResponseWriter, r *http.Request) {
 		return
 		return
 	}
 	}
 
 
-	if req.Password != "yfkj123456" {
+	if req.Password != authPassword {
 		json.NewEncoder(w).Encode(VersionResp{Status: "error", Message: "输入的密码不正确"})
 		json.NewEncoder(w).Encode(VersionResp{Status: "error", Message: "输入的密码不正确"})
 		return
 		return
 	}
 	}

+ 13 - 12
web-ui.service/web/app.html

@@ -19,7 +19,7 @@
 <link rel="stylesheet" href="static/css/page7.css?v={{V}}">
 <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/page8.css?v={{V}}">
 <link rel="stylesheet" href="static/css/page9.css?v={{V}}">
 <link rel="stylesheet" href="static/css/page9.css?v={{V}}">
-<link rel="stylesheet" href="static/css/jsonview.css?v={{V}}">
+<link rel="stylesheet" href="static/css/jsondlg.css?v={{V}}">
 </head>
 </head>
 
 
 <body>
 <body>
@@ -42,9 +42,9 @@
   <symbol id="i-disk" viewBox="0 0 24 24"><line x1="22" y1="12" x2="2" y2="12"/><path d="M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"/><line x1="6" y1="16" x2="6.01" y2="16"/><line x1="10" y1="16" x2="10.01" y2="16"/></symbol>
   <symbol id="i-disk" viewBox="0 0 24 24"><line x1="22" y1="12" x2="2" y2="12"/><path d="M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"/><line x1="6" y1="16" x2="6.01" y2="16"/><line x1="10" y1="16" x2="10.01" y2="16"/></symbol>
   <symbol id="i-trend" viewBox="0 0 24 24"><polyline points="23 6 13.5 15.5 8.5 10.5 1 18"/><polyline points="17 6 23 6 23 12"/></symbol>
   <symbol id="i-trend" viewBox="0 0 24 24"><polyline points="23 6 13.5 15.5 8.5 10.5 1 18"/><polyline points="17 6 23 6 23 12"/></symbol>
   <symbol id="i-refresh" viewBox="0 0 24 24"><polyline points="23 4 23 10 17 10"/><polyline points="1 20 1 14 7 14"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/></symbol>
   <symbol id="i-refresh" viewBox="0 0 24 24"><polyline points="23 4 23 10 17 10"/><polyline points="1 20 1 14 7 14"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/></symbol>
-  <symbol id="i-cbd" viewBox="0 0 24 24"><rect x="8" y="7" width="8" height="13" rx="4"/><path d="M9 7a3 3 0 0 1 6 0"/><line x1="12" y1="2" x2="12" y2="4"/><line x1="8.5" y1="11" x2="3" y2="11"/><line x1="8.5" y1="15" x2="3" y2="15"/><line x1="8.5" y1="18" x2="4" y2="20"/><line x1="15.5" y1="11" x2="21" y2="11"/><line x1="15.5" y1="15" x2="21" y2="15"/><line x1="15.5" y1="18" x2="20" y2="20"/><line x1="12" y1="11" x2="12" y2="20"/></symbol>
   <symbol id="i-unlock" viewBox="0 0 24 24"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 9.9-1"/></symbol>
   <symbol id="i-unlock" viewBox="0 0 24 24"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 9.9-1"/></symbol>
-  <symbol id="i-server-config" viewBox="0 0 24 24"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/><path d="M11 11c-2 0-2 1-2 2v1c0 1-1 1-2 1 1 0 2 0 2 1v1c0 1 0 2 2 2M13 11c2 0 2 1 2 2v1c0 1 1 1 2 1-1 0-2 0-2 1v1c0 1 0 2-2 2"/></symbol>
+  <symbol id="i-json-file" viewBox="0 0 24 24"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/><path d="M11 11c-2 0-2 1-2 2v1c0 1-1 1-2 1 1 0 2 0 2 1v1c0 1 0 2 2 2M13 11c2 0 2 1 2 2v1c0 1 1 1 2 1-1 0-2 0-2 1v1c0 1 0 2-2 2"/></symbol>
+  <symbol id="i-cbd" viewBox="0 0 24 24"><rect x="8" y="7" width="8" height="13" rx="4"/><path d="M9 7a3 3 0 0 1 6 0"/><line x1="12" y1="2" x2="12" y2="4"/><line x1="8.5" y1="11" x2="3" y2="11"/><line x1="8.5" y1="15" x2="3" y2="15"/><line x1="8.5" y1="18" x2="4" y2="20"/><line x1="15.5" y1="11" x2="21" y2="11"/><line x1="15.5" y1="15" x2="21" y2="15"/><line x1="15.5" y1="18" x2="20" y2="20"/><line x1="12" y1="11" x2="12" y2="20"/></symbol>
 </svg>
 </svg>
 
 
 <div id="loading-mask">
 <div id="loading-mask">
@@ -53,8 +53,9 @@
     <div class="loading-text">页面加载中,请稍微...</div>
     <div class="loading-text">页面加载中,请稍微...</div>
   </div>
   </div>
 </div>
 </div>
+
 <div class="app">
 <div class="app">
-   <header class="topbar">
+  <header class="topbar">
     <div class="device">
     <div class="device">
       <span class="icon-box"><svg class="icon"><use href="#i-logo"/></svg></span>
       <span class="icon-box"><svg class="icon"><use href="#i-logo"/></svg></span>
       <div class="device-info">
       <div class="device-info">
@@ -101,14 +102,14 @@
 </div>
 </div>
 
 
 <!-- JSON查看弹窗 -->
 <!-- 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 class="jsondlg" id="jsondlg">
+  <div class="jsondlg-dialog">
+    <div class="jsondlg-header">
+      <h2 id="jsondlg-title">配置查看</h2>
+      <button class="jsondlg-close" type="button" title="关闭" onclick="closeJsonDlg()">&times;</button>
     </div>
     </div>
-    <div class="jsonview-body">
-      <pre id="jsonview-content"></pre>
+    <div class="jsondlg-body">
+      <pre id="jsondlg-content"></pre>
     </div>
     </div>
   </div>
   </div>
 </div>
 </div>
@@ -119,7 +120,7 @@
 <script src="static/js/eventsource.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/compat.js?v={{V}}"></script>
 <script src="static/js/util.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/jsondlg.js?v={{V}}"></script>
 <script src="static/js/echarts.min.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.js?v={{V}}"></script>
 <script src="static/js/xterm-addon-fit.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-item">
           <div class="info-info">
           <div class="info-info">
-            <div class="info-name clickable" onclick="viewUpgradeConf()">设备自动升级</div>
+            <div class="info-name clickable" onclick="viewUpgradeConfig()">设备自动升级</div>
             <div class="info-desc">upgrade.service</div>
             <div class="info-desc">upgrade.service</div>
           </div>
           </div>
           <span class="info-value" id="var9">--</span>
           <span class="info-value" id="var9">--</span>

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

@@ -23,7 +23,7 @@
               <h2>设备状态</h2>
               <h2>设备状态</h2>
               <button class="btn" title="点击查看服务器配置" onclick="viewCBDServerConfig()">
               <button class="btn" title="点击查看服务器配置" onclick="viewCBDServerConfig()">
                 <svg class="icon">
                 <svg class="icon">
-                  <use href="#i-server-config" xlink:href="#i-server-config"/>
+                  <use href="#i-json-file" xlink:href="#i-json-file"/>
                 </svg>
                 </svg>
               </button>
               </button>
             </div>
             </div>

+ 9 - 9
web-ui.service/web/static/css/jsonview.css

@@ -1,5 +1,5 @@
 /* JSON查看弹窗 */
 /* JSON查看弹窗 */
-.jsonview {
+.jsondlg {
     display: none;
     display: none;
     position: fixed;
     position: fixed;
     inset: 0;
     inset: 0;
@@ -10,11 +10,11 @@
     justify-content: center;
     justify-content: center;
 }
 }
 
 
-.jsonview.show {
+.jsondlg.show {
     display: flex;
     display: flex;
 }
 }
 
 
-.jsonview-dialog {
+.jsondlg-dialog {
     display: flex;
     display: flex;
     flex-direction: column;
     flex-direction: column;
     width: 100%;
     width: 100%;
@@ -26,7 +26,7 @@
     overflow: hidden;
     overflow: hidden;
 }
 }
 
 
-.jsonview-header {
+.jsondlg-header {
     display: flex;
     display: flex;
     align-items: center;
     align-items: center;
     justify-content: space-between;
     justify-content: space-between;
@@ -35,7 +35,7 @@
     border-bottom: 1px solid #30435f;
     border-bottom: 1px solid #30435f;
 }
 }
 
 
-.jsonview-header h2 {
+.jsondlg-header h2 {
     min-width: 0;
     min-width: 0;
     font-size: 16px;
     font-size: 16px;
     font-weight: 500;
     font-weight: 500;
@@ -43,7 +43,7 @@
     overflow-wrap: anywhere;
     overflow-wrap: anywhere;
 }
 }
 
 
-.jsonview-close {
+.jsondlg-close {
     flex: none;
     flex: none;
     margin-left: 16px;
     margin-left: 16px;
     padding: 0;
     padding: 0;
@@ -55,18 +55,18 @@
     cursor: pointer;
     cursor: pointer;
 }
 }
 
 
-.jsonview-close:hover {
+.jsondlg-close:hover {
     color: #ffffff;
     color: #ffffff;
 }
 }
 
 
-.jsonview-body {
+.jsondlg-body {
     flex: 1;
     flex: 1;
     min-height: 0;
     min-height: 0;
     overflow: auto;
     overflow: auto;
     padding: 16px;
     padding: 16px;
 }
 }
 
 
-.jsonview-body pre {
+.jsondlg-body pre {
     margin: 0;
     margin: 0;
     color: #b9d5f5;
     color: #b9d5f5;
     font-family: Consolas, "Courier New", monospace;
     font-family: Consolas, "Courier New", monospace;

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

@@ -71,7 +71,7 @@
     font-size: 14px;
     font-size: 14px;
 }
 }
 
 
-.info-name.clickable {
+.page1 .info-name.clickable {
     cursor: pointer;
     cursor: pointer;
 }
 }
 
 

+ 6 - 6
web-ui.service/web/static/js/jsonview.js

@@ -1,6 +1,6 @@
-function showJsonView(title, data) {
-    var dlg = document.getElementById("jsonview");
-    var content = document.getElementById("jsonview-content");
+function showJsonDlg(title, data) {
+    var dlg = document.getElementById("jsondlg");
+    var content = document.getElementById("jsondlg-content");
 
 
     if (data === undefined || data === null) {
     if (data === undefined || data === null) {
         content.textContent = "暂无内容";
         content.textContent = "暂无内容";
@@ -18,12 +18,12 @@ function showJsonView(title, data) {
         }
         }
     }
     }
 
 
-    document.getElementById("jsonview-title").textContent = title || "配置查看";
+    document.getElementById("jsondlg-title").textContent = title || "配置查看";
 
 
     dlg.classList.add("show");
     dlg.classList.add("show");
     content.parentNode.scrollTop = 0;
     content.parentNode.scrollTop = 0;
 }
 }
 
 
-function closeJsonView() {
-    document.getElementById("jsonview").classList.remove("show");
+function closeJsonDlg() {
+    document.getElementById("jsondlg").classList.remove("show");
 }
 }

+ 4 - 4
web-ui.service/web/static/js/page1.js

@@ -670,13 +670,13 @@ function dashSetUptime(text) {
     }
     }
 }
 }
 
 
-function viewUpgradeConf() {
+function viewUpgradeConfig() {
     var password = prompt("请输入操作密码:");
     var password = prompt("请输入操作密码:");
     if (password === null) {
     if (password === null) {
         return;
         return;
     }
     }
 
 
-    fetch("/api/upgrade/getUpgradeConf", {
+    fetch("/api/upgrade/getUpgradeConfig", {
         headers: {
         headers: {
             "X-Operation-Password": password
             "X-Operation-Password": password
         }
         }
@@ -691,10 +691,10 @@ function viewUpgradeConf() {
             return r.json();
             return r.json();
         })
         })
         .then(function (data) {
         .then(function (data) {
-            showJsonView("设备自动升级配置", data);
+            showJsonDlg("设备自动升级配置", data);
         })
         })
         .catch(function (e) {
         .catch(function (e) {
-            console.error("viewUpgradeConf() failed:", e);
+            console.error("viewUpgradeConfig() failed:", e);
             alert("获取设备自动升级配置失败:" + e.message);
             alert("获取设备自动升级配置失败:" + e.message);
         });
         });
 }
 }

+ 1 - 1
web-ui.service/web/static/js/page9.js

@@ -151,7 +151,7 @@ function viewCBDServerConfig() {
             return r.json();
             return r.json();
         })
         })
         .then(function (data) {
         .then(function (data) {
-            showJsonView("服务器配置", data);
+            showJsonDlg("服务器配置", data);
         })
         })
         .catch(function (e) {
         .catch(function (e) {
             console.error("viewCBDServerConfig() failed:", e);
             console.error("viewCBDServerConfig() failed:", e);

+ 3 - 2
web-ui.service/web_handler.go

@@ -20,6 +20,7 @@ import (
 )
 )
 
 
 const noValue = "--"
 const noValue = "--"
+const authPassword = "yfkj123456"
 
 
 type LoginReq struct {
 type LoginReq struct {
 	Username string `json:"username"`
 	Username string `json:"username"`
@@ -485,7 +486,7 @@ func serviceControlHandler(w http.ResponseWriter, r *http.Request) {
 		return
 		return
 	}
 	}
 
 
-	if req.Secret != "yfkj123456" {
+	if req.Secret != authPassword {
 		http.Error(w, "密码错误", http.StatusForbidden)
 		http.Error(w, "密码错误", http.StatusForbidden)
 		return
 		return
 	}
 	}
@@ -509,7 +510,7 @@ func serviceControlHandler(w http.ResponseWriter, r *http.Request) {
 
 
 func checkOperationPassword(w http.ResponseWriter, r *http.Request) bool {
 func checkOperationPassword(w http.ResponseWriter, r *http.Request) bool {
 	password := r.Header.Get("X-Operation-Password")
 	password := r.Header.Get("X-Operation-Password")
-	if subtle.ConstantTimeCompare([]byte(password), []byte("yfkj123456")) != 1 {
+	if subtle.ConstantTimeCompare([]byte(password), []byte(authPassword)) != 1 {
 		http.Error(w, "操作密码错误", http.StatusUnauthorized)
 		http.Error(w, "操作密码错误", http.StatusUnauthorized)
 		return false
 		return false
 	}
 	}

+ 1 - 1
web-ui.service/web_route.go

@@ -71,7 +71,7 @@ var routes = []Route{
 	},
 	},
 
 
 	{
 	{
-		"/api/upgrade/getUpgradeConf",
+		"/api/upgrade/getUpgradeConfig",
 		getUpgradeConfig,
 		getUpgradeConfig,
 	},
 	},