diff --git a/static/web_panel/js/app.js b/static/web_panel/js/app.js index 7dac60a..113da1e 100644 --- a/static/web_panel/js/app.js +++ b/static/web_panel/js/app.js @@ -6,6 +6,12 @@ document.documentElement.setAttribute("data-theme", s); })(); +// ═══ 工具函数 ═══ +function getCookie(name) { + var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); + return match ? match[2] : ''; +} + window.toggleTheme = function(){ var t = document.documentElement.getAttribute("data-theme") === "light" ? "dark" : "light"; document.documentElement.setAttribute("data-theme", t); diff --git a/static/web_panel/pages/dashboard.js b/static/web_panel/pages/dashboard.js index 27bcfb7..980c521 100644 --- a/static/web_panel/pages/dashboard.js +++ b/static/web_panel/pages/dashboard.js @@ -32,7 +32,8 @@ window.DashboardModule = { } var base = window.location.pathname.split("/").slice(0, 2).join("/"); - var ws = new WebSocket("ws://" + location.host + base + "/api/system/ws"); + var tok = getCookie("panel_token"); + var ws = new WebSocket("ws://" + location.host + base + "/api/system/ws?token=" + (tok || "")); self.ws = ws; ws.onopen = function() { diff --git a/static/web_panel/pages/logs.js b/static/web_panel/pages/logs.js index 1ac02bd..83c3a8e 100644 --- a/static/web_panel/pages/logs.js +++ b/static/web_panel/pages/logs.js @@ -25,7 +25,8 @@ window.LogsModule = { } var base = window.location.pathname.split("/").slice(0, 2).join("/"); - var ws = new WebSocket("ws://" + location.host + base + "/api/logs/ws"); + var tok = getCookie("panel_token"); + var ws = new WebSocket("ws://" + location.host + base + "/api/logs/ws?token=" + (tok || "")); self.ws = ws; ws.onopen = function() {