From fe0c86f85c5521c2d0aa1c9450832e800153e2b5 Mon Sep 17 00:00:00 2001 From: lxb <1580622474@qq.com> Date: Tue, 10 Dec 2024 11:58:58 +0800 Subject: [PATCH] update --- web/css/style_1.css | 8 +++++--- web/js/script.js | 25 +++++++++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/web/css/style_1.css b/web/css/style_1.css index 8799516..4a37211 100644 --- a/web/css/style_1.css +++ b/web/css/style_1.css @@ -14,18 +14,20 @@ padding: 5px 10px; margin: 5px; border-radius: 8px; - box-shadow: 0 3px 7px rgba(0, 0, 0, 0.3); + box-shadow: 0px 1px 10px rgba(0, 0, 0, 0.3); width: 300px; display: inline-block; vertical-align: top; + margin: 12px; } .server-name { background-color: rgb(0, 0, 0); color: white; border-radius: 8px; - padding: 4px 10px; + padding: 6px 10px; font-size: 26px; + margin-top: 4px; margin-bottom: 6px; } @@ -37,7 +39,7 @@ border-radius: 8px; margin-top: 5px; padding: 4px 8px; - margin-bottom: 5px; + margin-bottom: 12px; background-color: #f9f9f9; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); } diff --git a/web/js/script.js b/web/js/script.js index fe93e2a..a5e76d5 100644 --- a/web/js/script.js +++ b/web/js/script.js @@ -1,6 +1,23 @@ +// 判断内网还是公网 +let apiURL = ''; +fetch('/index.html') // 随便请求一个资源 + .then(response => { + // 获取X-Environment响应头 + const environment = response.headers.get('X-Environment'); + + // 根据环境变量设置API URL + if (environment === 'internal') { + apiURL = 'http://10.1.16.174:15001'; + } else { + apiURL = 'http://gpus.lxblxb.top'; + } + + console.log('访问地址: ' + apiURL); + }) + // 请求服务器获取数据 function fetchData() { - fetch('http://10.1.16.174:15001/api/get_data') // http://mm.zjgsu.edu.cn/serverInfo-api/get_data + fetch(apiURL + '/api/get_data') // 获取服务器和显卡数据 .then(response => response.json()) // 解析 JSON 响应 .then(data => { @@ -85,14 +102,14 @@ function displayServerData(data){ // 判断时间 let lastTime = new Date(serverData['update_time_stamp'] * 1000); let timeFromUpdate = Date.now() - lastTime; - if (timeFromUpdate > serverData['interval'] * 1000 * 3){ + if (timeFromUpdate > serverData['interval'] * 1000 * 4){ let errText = document.createElement('div'); errText.className = 'error-text'; errText.textContent = "长时间未更新,上次更新时间: " + lastTime.toLocaleString(); serverCard.appendChild(errText); serverDataContainer.appendChild(serverCard); continue; - }else if (timeFromUpdate > serverData['interval'] * 1000 * 1.5){ + }else if (timeFromUpdate > serverData['interval'] * 1000 * 2.5){ serverName.textContent = serverTitle + " - Not update -"; } @@ -132,7 +149,7 @@ function displayServerData(data){ }); cpuInfo.innerHTML = "" + serverData.cpu['name'] + "
" + "温度 : " + temperature_list_str + "
" + - "占用率 : " + serverData.cpu['core_avg_occupy'] + "%"; + "占用率 : " + serverData.cpu['core_avg_occupy'] + "%"; serverCard.appendChild(cpuInfo); // 分割线