From 6f78dd91ffd0544b5fd3993d5f7d316ee08264d4 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 17 三月 2026 15:50:46 +0800
Subject: [PATCH] #

---
 src/main/webapp/static/js/dashboard/dashboard.js |  134 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 134 insertions(+), 0 deletions(-)

diff --git a/src/main/webapp/static/js/dashboard/dashboard.js b/src/main/webapp/static/js/dashboard/dashboard.js
index 42e63df..6a3cd1a 100644
--- a/src/main/webapp/static/js/dashboard/dashboard.js
+++ b/src/main/webapp/static/js/dashboard/dashboard.js
@@ -14,6 +14,7 @@
         rawPayload: null,
         loading: true,
         refreshing: false,
+        switchingSystem: false,
         countdown: REFRESH_SECONDS,
         countdownTimer: null,
         resizeHandler: null,
@@ -631,6 +632,16 @@
       displayText: function (value, fallback) {
         return value == null || value === "" ? (fallback || "") : value;
       },
+      showMessage: function (message, type) {
+        if (this.$message && typeof this.$message === "function") {
+          this.$message({
+            message: message,
+            type: type || "info"
+          });
+          return;
+        }
+        console[type === "error" ? "error" : "log"](message);
+      },
       networkSamplingText: function () {
         var config = this.network && this.network.samplingConfig ? this.network.samplingConfig : {};
         return this.i18n("dashboard.networkSampling", "閲囨牱 {0} ms / 瓒呮椂 {1} ms / 姣忔牱鏈� {2} 娆� / 鍖呭ぇ灏� {3}", [
@@ -771,6 +782,129 @@
           this.translateLegacyText("鐩戞帶绯荤粺")
         );
       },
+      syncParentSystemRunning: function (status) {
+        try {
+          if (window.parent && window.parent !== window) {
+            window.parent.systemRunning = !!status;
+          }
+        } catch (e) {
+        }
+      },
+      requestSystemSwitch: function (operatorType, password) {
+        var self = this;
+        this.switchingSystem = true;
+        $.ajax({
+          url: baseUrl + "/console/system/switch",
+          headers: {
+            token: localStorage.getItem("token")
+          },
+          data: {
+            operatorType: operatorType,
+            password: password || ""
+          },
+          method: "POST",
+          success: function (res) {
+            var status;
+            if (res && res.code === 200) {
+              status = !!(res.data && res.data.status);
+              self.overview = Object.assign({}, self.overview, {
+                systemRunning: status
+              });
+              self.syncParentSystemRunning(status);
+              self.showMessage(
+                status
+                  ? self.i18n("dashboard.systemStarted", "绯荤粺宸插惎鍔�")
+                  : self.i18n("dashboard.systemStopped", "绯荤粺宸插仠姝�"),
+                "success"
+              );
+              self.loadDashboard(false);
+              return;
+            }
+            if (res && res.code === 403) {
+              window.location.href = baseUrl + "/login";
+              return;
+            }
+            self.showMessage(
+              (res && res.msg) || self.i18n("dashboard.systemSwitchFailed", "绯荤粺鐘舵�佸垏鎹㈠け璐�"),
+              "error"
+            );
+          },
+          error: function () {
+            self.showMessage(
+              self.i18n("dashboard.systemSwitchFailedDetail", "绯荤粺鐘舵�佸垏鎹㈠け璐ワ紝璇锋鏌ユ帴鍙g姸鎬�"),
+              "error"
+            );
+          },
+          complete: function () {
+            self.switchingSystem = false;
+          }
+        });
+      },
+      startSystem: function () {
+        if (this.overview.systemRunning || this.switchingSystem) {
+          return;
+        }
+        this.requestSystemSwitch(1);
+      },
+      maskStopSystemPromptInput: function () {
+        setTimeout(function () {
+          var input = document.querySelector(".el-message-box__wrapper .el-message-box__input input");
+          if (!input) {
+            return;
+          }
+          input.setAttribute("type", "text");
+          input.setAttribute("name", "dashboard-stop-code");
+          input.setAttribute("autocomplete", "new-password");
+          input.setAttribute("autocapitalize", "off");
+          input.setAttribute("autocorrect", "off");
+          input.setAttribute("spellcheck", "false");
+          input.setAttribute("data-form-type", "other");
+          input.style.webkitTextSecurity = "disc";
+        }, 30);
+      },
+      stopSystem: function () {
+        var self = this;
+        var proceed = function (password) {
+          var cleanPassword = String(password == null ? "" : password).trim();
+          if (!cleanPassword) {
+            self.showMessage(self.i18n("dashboard.stopSystemPasswordRequired", "璇疯緭鍏ュ仠姝㈢郴缁熷彛浠�"), "warning");
+            return;
+          }
+          self.requestSystemSwitch(0, cleanPassword);
+        };
+
+        if (!this.overview.systemRunning || this.switchingSystem) {
+          return;
+        }
+
+        if (typeof this.$prompt === "function") {
+          this.$prompt(
+            this.i18n("dashboard.stopSystemPrompt", "璇疯緭鍏ュ彛浠わ紝骞跺仠姝� WCS 绯荤粺"),
+            this.i18n("dashboard.stopSystemTitle", "鍋滄绯荤粺"),
+            {
+              confirmButtonText: this.i18n("common.confirm", "纭畾"),
+              cancelButtonText: this.i18n("common.cancel", "鍙栨秷"),
+              inputType: "text",
+              inputPattern: /\S+/,
+              inputErrorMessage: this.i18n("dashboard.stopSystemPasswordRequired", "璇疯緭鍏ュ仠姝㈢郴缁熷彛浠�")
+            }
+          ).then(function (result) {
+            proceed(result && result.value);
+          }).catch(function () {
+          });
+          this.maskStopSystemPromptInput();
+          return;
+        }
+
+        proceed(window.prompt(this.i18n("dashboard.stopSystemPrompt", "璇疯緭鍏ュ彛浠わ紝骞跺仠姝� WCS 绯荤粺"), ""));
+      },
+      toggleSystem: function () {
+        if (this.overview.systemRunning) {
+          this.stopSystem();
+          return;
+        }
+        this.startSystem();
+      },
       openDevicePingAnalysis: function () {
         this.openParentMenuView(
           "/views/devicePingLog/devicePingLog.html",

--
Gitblit v1.9.1