| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- let gnssLogLevel = "";
- function setGnssLogLevel() {
- const level = logLevel.value;
- fetch("/api/gnss/loglevel", {
- method: "POST",
- headers: {"Content-Type": "application/json"},
- body: JSON.stringify({level})
- })
- .then(async r => {
- if (!r.ok) throw new Error(await r.text());
- gnssLogLevel = level;
- })
- .catch(e => {
- logLevel.value = gnssLogLevel;
- });
- }
- function getGnssLogLevel() {
- fetch("/api/gnss/loglevel")
- .then(async r => {
- if (!r.ok) throw new Error(await r.text());
- return r.json();
- })
- .then(d => {
- gnssLogLevel = d.log_level;
- logLevel.value = d.log_level;
- })
- .catch(e => {
- gnssLogLevel = "";
- logLevel.value = "";
- });
- }
- function downloadGnssLogFile() {
- const btn = event.currentTarget;
- btn.disabled = true;
- fetch("/api/gnss/logfile")
- .then(async r => {
- if (!r.ok) {
- throw new Error("HTTP " + r.status);
- }
- const disposition = r.headers.get("Content-Disposition");
- let filename = "gnss.log.tar.gz";
- if (disposition) {
- const match = disposition.match(/filename="?([^";]+)"?/);
- if (match) {
- filename = match[1];
- }
- }
- return {
- blob: await r.blob(),
- filename
- };
- })
- .then(({ blob, filename }) => {
- const url = URL.createObjectURL(blob);
- const a = document.createElement("a");
- a.href = url;
- a.download = filename;
- document.body.appendChild(a);
- a.click();
- a.remove();
- setTimeout(() => {
- URL.revokeObjectURL(url);
- }, 1000);
- alert("下载成功");
- })
- .catch(e => {
- console.error("download failed:", e);
- alert("下载失败: " + e.message);
- })
- .finally(() => {
- btn.disabled = false;
- btn.textContent = "下载";
- });
- }
- function restartGnssService() {
- if (!confirm("确定重启时间服务吗?")) {
- return;
- }
- const btn = event.currentTarget;
- btn.disabled = true;
- fetch("/api/gnss/restart", {
- method: "POST"
- })
- .then(async r => {
- if (!r.ok) {
- throw new Error(await r.text());
- }
- logLevel.value = "info";
- gnssLogLevel = logLevel.value;
- alert("重启成功");
- })
- .catch(e => {
- console.error("restart failed:", e);
- alert("重启失败: " + e.message);
- })
- .finally(() => {
- btn.disabled = false;
- });
- }
- let gnssStatusTimer = null;
- function getGnssStatus() {
- fetch("/api/gnss/status")
- .then(async r => {
- if (!r.ok) {
- throw new Error("HTTP " + r.status);
- }
- return r.json();
- })
- .then(data => {
- document.getElementById("var1").textContent = data.var1 || "--";
- document.getElementById("var2").textContent = data.var2 || "--";
- document.getElementById("var3").textContent = data.var3 || "--";
- })
- .catch(e => {
- console.error("gnss status failed:", e);
- document.getElementById("var1").textContent = "--";
- document.getElementById("var2").textContent = "--";
- document.getElementById("var3").textContent = "--";
- });
- getGnssLogLevel();
- }
- function startGnssStatusRefresh() {
- if (gnssStatusTimer) {
- return;
- }
- getGnssStatus();
- gnssStatusTimer = setInterval(() => {
- getGnssStatus();
- }, 3000);
- }
- function stopGnssStatusRefresh() {
- if (gnssStatusTimer) {
- clearInterval(gnssStatusTimer);
- gnssStatusTimer = null;
- }
- }
- function initPage4() {
- startGnssStatusRefresh()
- connectLog("yfkj-gnss.service", "text1");
- }
- function exitPage4() {
- stopGnssStatusRefresh()
- disconnectLog();
- }
|