Bläddra i källkod

Merge remote-tracking branch 'origin/master'

lxb 1 år sedan
förälder
incheckning
b683e904fe

+ 18 - 1
src/main/java/com/imcs/admin/business/controller/BigScreenDetailController.java

@@ -3,7 +3,9 @@ package com.imcs.admin.business.controller;
 import com.imcs.admin.business.service.BigScreenDetailService;
 import com.imcs.admin.common.PageParam;
 import com.imcs.admin.common.Result;
-import com.imcs.admin.db.service.JdbcService;
+import com.imcs.admin.common.constants.Constants;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -14,8 +16,23 @@ public class BigScreenDetailController {
     @Resource
     private BigScreenDetailService bigScreenDetailService;
 
+    @Autowired
+    private RedisTemplate redisTemplate;
+
     @RequestMapping("/detail")
     public Result getDeviceDetail(@RequestBody PageParam pageParam){
         return new Result(bigScreenDetailService.getBigScreenDetail(pageParam));
     }
+
+    @GetMapping("/setRefresh/{isRefresh}")
+    public Result setRefresh(@PathVariable Boolean isRefresh){
+        redisTemplate.opsForValue().set(Constants.IS_REFRESH,isRefresh);
+        return new Result();
+    }
+
+    @GetMapping("/getRefresh")
+    public Result getRefresh(){
+        Boolean isRefresh=Boolean.valueOf(redisTemplate.opsForValue().get(Constants.IS_REFRESH).toString());
+        return new Result(isRefresh);
+    }
 }

+ 1 - 0
src/main/java/com/imcs/admin/common/constants/Constants.java

@@ -11,4 +11,5 @@ public class Constants {
     public static final String CAPTCHA_TIMEOUT = "CAPTCHA_TIMEOUT";
     public static final String USER_CHOOSE_ENTERPRISE = "USER_CHOOSE_ENTERPRISE";
     public static final String QUERY_KEY_START = "q__";
+    public static final String IS_REFRESH = "isRefresh";
 }

+ 19 - 17
src/main/resources/static/admin/bigScreen/index.html

@@ -67,16 +67,29 @@
     // 假设设备信息的容器元素是一个 <div> 标签,并具有类名 "data_bottom"
     const container = document.querySelector('.data_bottom');
     var requestData;
+    let shouldRefresh = true; // 一个标志,用于确定页面是否应该刷新
     function init(){
+
         callAPI();
         // 首次调用函数开始刷新
-        refreshPage();
+        setInterval(function() {
+            refreshPage();
+        }, 10000); // 设置10秒钟的定时器
     }
     function refreshPage() {
-        setTimeout(function() {
-            location.reload(true); // 重新加载页面,参数为 true 表示强制从服务器重新加载
-            callAPI();
-        }, 10000); // 设置10秒钟的定时器
+            $.ajax({
+                url: "/bigScreen/getRefresh",
+                type: "GET", // 指定请求类型为 POST
+                dataType: "JSON",
+                success: function (resp) {
+                    if(resp.data ||resp.data == null){
+                        location.reload(true); // 重新加载页面,参数为 true 表示强制从服务器重新加载
+                    }
+                },
+                error: function (error) {
+                    console.error("发生错误:", error);
+                }
+            });
     }
 
 
@@ -88,6 +101,7 @@
                 "openPage": "NO"
             }
         };
+
         $.ajax({
             url:"/admin/page/crudQuery/aDevice",
             type: "POST", // 指定请求类型为 POST
@@ -172,18 +186,6 @@
                         document.body.appendChild(link);
                         link.click();
 
-                        // 发送新的请求
-                        /*$.ajax({
-                            url: "/admin/page/crudQuery/deviceDetail",
-                            type: "POST",
-                            contentType: "application/json",
-                            dataType: "JSON",
-                            data: JSON.stringify(detailRequestData),
-                            success: function(detailResp) {
-                                // 成功返回数据后,渲染新页面
-                                renderDetailPage(detailResp);
-                            }
-                        });*/
                     });
                 });
 

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

@@ -99,15 +99,26 @@
     function init(){
         callAPI();
         // 首次调用函数开始刷新
-        refreshPage();
+        setInterval(function() {
+            refreshPage();
+        }, 10000); // 设置10秒钟的定时器
 
 
     }
     function refreshPage() {
-        setTimeout(function() {
-            location.reload(true); // 重新加载页面,参数为 true 表示强制从服务器重新加载
-            callAPI();
-        }, 10000); // 设置10秒钟的定时器
+        $.ajax({
+            url: "/bigScreen/getRefresh",
+            type: "GET", // 指定请求类型为 POST
+            dataType: "JSON",
+            success: function (resp) {
+                if(resp.data ||resp.data == null){
+                    location.reload(true); // 重新加载页面,参数为 true 表示强制从服务器重新加载
+                }
+            },
+            error: function (error) {
+                console.error("发生错误:", error);
+            }
+        });
     }
     function callAPI(){
         $.ajax({