点击最后一个事件延迟多少秒刷新页面

 isSearching: false, // 判断当前页面是否被用户点击
 refreshTimer: null,
 userActionTimer: null, // 用户操作的定时器

 // 通用设置用户操作的函数
setUserAction() {
     // 标记用户正在执行操作
     this.isSearching = true;
     // 清除任何旧的定时器
     clearTimeout(this.userActionTimer);
     // 每次用户操作时,延迟刷新和重置状态
     this.userActionTimer = setTimeout(() => {
         this.isSearching = false;
         // 执行刷新操作
         this.resetQuery();
     }, 180000);
 },



this.ws.onmessage = function (res) {
  const obj = JSON.parse(res.data);
  
   // that.randomId !== obj.messageId  另一个用户在操作当前页面
   if (
       that.randomId !== obj.messageId &&
       obj.type === "messageback"
   ) {
       // that.resetQuery();
       if (!that.isSearching) {
           // 如果没有点击事件,立即刷新
           that.resetQuery();
       } else {
           // 用户正在操作,不直接刷新
           that.setUserAction(); // 延迟刷新逻辑移动到这里
       }
   }
};

你可能感兴趣的:(前端,javascript,开发语言)