| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- var cbdLogLevel = "";
- function setCBDLogLevel() {
- var level = logLevelP9.value;
- fetch("/api/cbd/loglevel", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ level: level }),
- })
- .then(function (r) {
- if (!r.ok) {
- return r.text().then(function (t) {
- throw new Error(t);
- });
- }
- cbdLogLevel = level;
- })
- .catch(function (e) {
- logLevelP9.value = cbdLogLevel;
- });
- }
- function getCBDLogLevel() {
- fetch("/api/cbd/loglevel")
- .then(function (r) {
- if (!r.ok) {
- return r.text().then(function (t) {
- throw new Error(t);
- });
- }
- return r.json();
- })
- .then(function (d) {
- cbdLogLevel = d.log_level;
- logLevelP9.value = d.log_level;
- })
- .catch(function (e) {
- cbdLogLevel = "";
- logLevelP9.value = "";
- });
- }
- function downloadCBDLogFile(event) {
- var btn = event.currentTarget;
- btn.disabled = true;
- fetch("/api/cbd/logfile")
- .then(function (r) {
- if (!r.ok) {
- throw new Error("HTTP " + r.status);
- }
- var disposition = r.headers.get("Content-Disposition");
- var filename = "cbd.log.tar.gz";
- if (disposition) {
- var match = disposition.match(/filename="?([^";]+)"?/);
- if (match) {
- filename = match[1];
- }
- }
- return r.blob().then(function (blob) {
- return { blob: blob, filename: filename };
- });
- })
- .then(function (res) {
- downloadBlobFile(res.blob, res.filename);
- alert("下载成功");
- })
- .catch(function (e) {
- console.error("download failed:", e);
- alert("下载失败: " + e.message);
- })
- .finally(function () {
- btn.disabled = false;
- btn.textContent = "下载";
- });
- }
- function restartCBDService(event) {
- if (!confirm("确定重启用户应用吗?")) {
- return;
- }
- var btn = event.currentTarget;
- btn.disabled = true;
- fetch("/api/user-app/restart", {
- method: "POST",
- })
- .then(function (r) {
- if (!r.ok) {
- return r.text().then(function (t) {
- throw new Error(t);
- });
- }
- alert("重启成功");
- })
- .catch(function (e) {
- console.error("restart failed:", e);
- alert("重启失败: " + e.message);
- })
- .finally(function () {
- btn.disabled = false;
- });
- }
- function disableP9CtrlCmdButtons() {
- for (var i = 1; i <= 12; i++) {
- setBtnStatus("p9btn" + (i < 10 ? "0" : "") + i, false, "page9");
- }
- }
- function enableP9CtrlCmdButtons() {
- var password = prompt("请输入操作密码:");
- if (password === null) {
- return;
- }
- fetch("/api/cbd/unlock", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- "X-Operation-Password": password
- }
- })
- .then(function (r) {
- if (!r.ok) {
- throw new Error(r.status === 401 ? "操作密码错误!" : "HTTP " + r.status);
- }
- for (var i = 1; i <= 12; i++) {
- setBtnStatus("p9btn" + (i < 10 ? "0" : "") + i, true, "page9");
- }
- setBtnStatus("p9AuthBtn", false, "page9");
- })
- .catch(function (e) {
- alert(e.message);
- });
- }
- function viewCBDServerConfig() {
- var password = prompt("请输入操作密码:");
- if (password === null) {
- return;
- }
- fetch("/api/cbd/serverCfg", {
- headers: {
- "X-Operation-Password": password
- }
- })
- .then(function (r) {
- if (!r.ok) {
- throw new Error(r.status === 401 ? "操作密码错误!" : "HTTP " + r.status);
- }
- return r.json();
- })
- .then(function (data) {
- showJsonView("服务器配置", data);
- })
- .catch(function (e) {
- console.error("viewCBDServerConfig() failed:", e);
- alert("获取服务器配置失败:" + e.message);
- });
- }
- var cbdWorkStatusTimer = null;
- function getCBDWorkStatus() {
- fetch("/api/cbd/getWorkStatus")
- .then(function (r) {
- if (!r.ok) {
- throw new Error("HTTP " + r.status);
- }
- return r.json();
- })
- .then(function (data) {
- setText("text1", data.mcuLastActiveTime, "page9");
- setText("text2", data.dataReportOKTime, "page9");
- setText("text3", data.photoUploadOKTime, "page9");
- })
- .catch(function (e) {
- console.error("getCBDWorkStatus() failed:", e);
- setText("text1", null, "page9");
- setText("text2", null, "page9");
- setText("text3", null, "page9");
- });
- getCBDLogLevel();
- }
- function startCBDWorkStatusRefresh() {
- if (cbdWorkStatusTimer) {
- return;
- }
- getCBDWorkStatus();
- cbdWorkStatusTimer = setInterval(function () {
- getCBDWorkStatus();
- }, 1000);
- }
- function stopCBDWorkStatusRefresh() {
- if (cbdWorkStatusTimer) {
- clearInterval(cbdWorkStatusTimer);
- cbdWorkStatusTimer = null;
- }
- }
- function initPage9() {
- disableP9CtrlCmdButtons();
- startCBDWorkStatusRefresh();
- connectLog("yfkj-user-app.service", "text5");
- }
- function exitPage9() {
- stopCBDWorkStatusRefresh();
- disconnectLog();
- }
|