Browse Source

定时刷新页面

oyq28 1 năm trước cách đây
mục cha
commit
822b2ba175

+ 21 - 9
src/main/resources/static/admin/bigScreen/index.html

@@ -123,14 +123,28 @@
 <script type="text/javascript">
     // 假设设备信息的容器元素是一个 <div> 标签,并具有类名 "data_bottom"
     const container = document.querySelector('.data_bottom');
-    var requestData = {
-        // 根据你的后端要求构建 PageParam 对象
-        pageParam: {
-            // 可能需要添加具体的属性值,比如 pageSize, pageNumber 等等
-            "openPage": "NO"
-        }
-    };
+    var requestData;
     function init(){
+        callAPI();
+        // 首次调用函数开始刷新
+        refreshPage();
+    }
+    function refreshPage() {
+        setTimeout(function() {
+            location.reload(true); // 重新加载页面,参数为 true 表示强制从服务器重新加载
+            callAPI();
+        }, 10000); // 设置10秒钟的定时器
+    }
+
+
+    function callAPI() {
+        requestData = {
+            // 根据你的后端要求构建 PageParam 对象
+            pageParam: {
+                // 可能需要添加具体的属性值,比如 pageSize, pageNumber 等等
+                "openPage": "NO"
+            }
+        };
         $.ajax({
             url:"/admin/page/crudQuery/aDevice",
             type: "POST", // 指定请求类型为 POST
@@ -237,8 +251,6 @@
         });
     }
 
-
-
     init();
 
 </script>

+ 16 - 7
src/main/resources/static/admin/bigScreenDetail/index.html

@@ -89,6 +89,19 @@
     var avgYearMonth;
 
     function init(){
+        callAPI();
+        // 首次调用函数开始刷新
+        refreshPage();
+
+
+    }
+    function refreshPage() {
+        setTimeout(function() {
+            location.reload(true); // 重新加载页面,参数为 true 表示强制从服务器重新加载
+            callAPI();
+        }, 10000); // 设置10秒钟的定时器
+    }
+    function callAPI(){
         $.ajax({
             url: "/bigScreen/detail",
             type: "POST", // 指定请求类型为 POST
@@ -125,8 +138,8 @@
                             <i></i>
                         </li>
                         <li>
-                            <span>开机时长(分钟)</span>
-                            <h1>${data.powerOnTime}</h1>
+                            <span>当日开机时长(分钟)</span>
+                            <h1>${data.todayPowerOnTime}</h1>
                             <i></i>
                         </li>
                         <li>
@@ -192,13 +205,9 @@
                 echart_4();
             }
         });
-
-
-
-
     }
-
     init();
+
     function echart_1() {
         // 基于准备好的dom,初始化echarts实例
         var myChart = echarts.init(document.getElementById('chart_1'));