el-table表格自动循环向上滚动鼠标放上去停止,移开恢复

排序的图标是两个图片,点击向后端发请求带不同的参数 

<template>
    <div style="height: 100%" class="table-content">
      <div :style="{ 'position': 'absolute', 'z-index': '9999', 'right': '3%', 'top': 0 }"
        :class="`tagBtn bg${centerKey}`">
        <div class="item" @click="centerKey = 1"></div>
        <div class="item" @click="centerKey = 2"></div>
      </div>
      <div style=" flex:1;height:0px" class="table-info" id="table">
        <el-table class="temp-table" ref="tableRef" @current-change="currChange" highlight-current-row
          :row-class-name="tableRowClassName" :data="tableData" size="mini" height="100%" :key="rank"
          @cell-mouse-enter="handleMouseOver" @cell-mouse-leave="handleMouseLeave">
          <el-table-column prop="rank" label="排名" align="center" min-width="80" show-overflow-tooltip>
            <template #header>
              <div style="display: flex;flex-direction: row;align-items: center;justify-content: center;"
                @click="sortChange">
                <span>排名</span>
                <span style="cursor: pointer;" v-if="show"><img
                    src="../../../assets/imgs/jiangxu.png" /></span>
                <span style="cursor: pointer;" v-if="!show"><img
                    src="../../../assets/imgs/shengxu.png" /></span>
              </div>
            </template>
            <template #default="scope">
              <span>{{ scope.row.rank }}</span>
            </template>
          </el-table-column>
          <el-table-column label="xx" prop="COMMUNITYNAME" min-width="120" align="left" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="xxx" prop="AVGTEMP" min-width="85" align="center" show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-if="centerKey === 1" label="xxx" prop="LOWTEMP" min-width="120" align="center"
            show-overflow-tooltip>
          </el-table-column>
          <el-table-column v-else label="xxx" prop="OVERTEMP" min-width="120" align="center" show-overflow-tooltip>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </Card>
</template>

<script lang="ts">
import { defineComponent, reactive, ref, toRefs, watch, computed, onMounted, onUnmounted, nextTick } from 'vue'
import { useRouter } from 'vue-router'
import { useAppStore } from '@/store/modules/app'
import { listRoomTempRange } from '@/api/Tou/index.ts'


export default defineComponent({
  components: {
  },
  props: {
    intervalTime: {
      type: Number,
      default: 20
    }
  },
  setup(props) {
    // store
    const appStore = useAppStore()
    const router = useRouter()

    const state = reactive({
      tableRef: null,
      tableData: [],
      centerKey: 1,
      type: 0,
      timer: null,
      distance: 0,
      mouserEnter: false, //用来标识鼠标是否在表格区域(防止请求接口之后,鼠标还指示在图表上)
      mouseScroll: false,
      currdata: null,
      show: true,
    }) as any

    const methods = {
      sortChange() {
        state.show = !state.show
        if (state.show === true) {
          state.type = 0 // 0降序
          methods.getData(state.type);
        } else {
          state.type = 1 // 1升序
          methods.getData(state.type);
        }
      },
      getData(type: number) {
        let params = {
          temporder: type == 0 ? 0 : 1, // 1升序 0降序
        }
        listRoomTempRange(params)
          .then(res => {
            // 处理成功的响应
            // 返回的数据顺序是后端处理好的,这里只需要按顺序添加编号即可            
            const data = res?.data.map((item: any, index: number) => {
              return {
                ...item,
                rank: index + 1,
              }
            })
            methods.initData(data);
          })
          .catch(error => {
            // 处理错误的响应
            console.error(error);
          });
      },
        
      // 设置行颜色
      tableRowClassName({ row, rowIndex }) {
        if (rowIndex % 2 == 0) {
          return "warning-row";
        } else if (rowIndex % 2 == 1) {
          return "success-row";
        }
        return "";
      },

      // 切换选项抛出事件
      currChange(val, i) {
        state.currdata = val;
      },

      initData(data) {
        //根据行数判断表格是否溢出,溢出滚动,否则不滚动
        if (data.length > 9) {

          state.tableData = [...data, ...data];
        } else {
          state.tableData = data;
        }
        //如果当前有选中的话,则请求接口之后高亮此项
        if (state.currdata) {
          let index = state.tableData.filter((r) => {
            if (r.COMMUNITYID == state.currdata.COMMUNITYID) {
              return r;
            }
          });
          state.tableRef.setCurrentRow(index[0]);
        } else {
          // 初始时是默认选中第一条
          state.tableRef.setCurrentRow(state.tableData[0]);
        }
        nextTick(() => {
          state.tableRef && state.tableRef.doLayout(); //解决表格错位
          if (data.length > 9 && !state.mouserEnter) {
            methods.scroll();
            methods.mouseWheel();
          }
        });
      },

      // 无缝滚动
      scroll() {
        window.clearInterval(state.timer);
        state.mouserEnter = true;
        const tableEl = document.getElementById('table')
        const bodyContent = tableEl.getElementsByClassName('el-table__body')[0];
        const bodyWrapperHeight = tableEl.getElementsByClassName('el-table__body-wrapper')[0].clientHeight;
        const bodyContentHeight = tableEl.getElementsByClassName('el-table__body')[0].clientHeight;
        if (bodyWrapperHeight < bodyContentHeight) {
          state.timer = setInterval(() => {
            state.distance -= 1;
            bodyContent.style.top = `${state.distance % bodyContent.offsetHeight / 2}px`;
          }, 20);
        }
      },
      // 滚轮滚动
      mouseWheel() {
        state.mouserEnter = true;
        const tableEl = document.getElementById('table')
        const bodyWrapper = tableEl.getElementsByClassName('el-table__body-wrapper')[0];
        const bodyContent = tableEl.getElementsByClassName('el-table__body')[0];
        bodyWrapper.addEventListener('mousewheel', (e) => {
          // 滚动table的时候,禁止屏幕滚动
          e.preventDefault();
          state.distance -= e.deltaY / 2;
          if (state.distance > 0) {
            state.distance = 0;
          }
          if (bodyContent.offsetHeight > bodyWrapper.offsetHeight) {
            bodyContent.style.top = `${state.distance % bodyContent.offsetHeight / 2}px`;
          }
        }, { passive: false })
      },
      // 鼠标移入停止滚动
      handleMouseOver() {
        window.clearInterval(state.timer);
        state.mouserEnter = true;
      },
      // 鼠标移出,恢复滚动
      handleMouseLeave() {
        methods.scroll();
      },
    }

    const timer2 = ref(null)

    onMounted(() => {
      methods.getData(0)
      timer2.value = setInterval(() => {
        methods.getData(state.type)
      }, 1000 * props.intervalTime);
    })

    onUnmounted(() => {
      clearInterval(timer2.value);
    })

    return {
      ...toRefs(state),
      ...methods,
    }
  }
})
</script>

<style lang="less" scoped>
.card-info {
  position: relative;
}

.table-content {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 3%;

  .table-info {
    height: 0;
    flex: 1;
    border-radius: 6px;
    overflow: hidden;
  }

  .tagBtn {
    width: 129px;
    height: 23px;
    background: url(../../../assets/imgs/upToPar1.png) no-repeat;
    background-size: 100% 100%;
    display: flex;
    flex-direction: row;
    justify-content: center;

    &.bg2 {
      background: url(../../../assets/imgs/upToPar2.png) no-repeat;
      background-size: 100% 100%;
    }

    &>.item {
      width: 65px;
      cursor: pointer;

      &:last-child {
        margin-left: 4px;

      }
    }
  }
}

.el-table {
  border-radius: 6px;
}

:deep(.el-table td.el-table__cell div) {
  padding-left: 8px !important;
  padding-right: 8px !important;
  font-size: 12px;
  font-family: MicrosoftYaHei;
  color: #C0D7FB;
  line-height: 16px;
}

:deep(.el-table th>.cell) {
  text-align: center;
}

::v-deep .el-table .warning-row {
  height: 36px;
  background: #070C33;
  // background: linear-gradient(90deg, rgba(0, 15, 35, 0) 0%, #000E23 100%);
}

::v-deep .el-table .success-row {
  height: 36px;
  background: #0A1749;
  // background: rgba(20, 57, 140, 0.34);
}

::v-deep .el-table .current-row {
  height: 36px;
  background: #043A90;
}

::v-deep .el-table--scrollable-y .el-table__body-wrapper {
  overflow: hidden;
}

::v-deep .el-table__body {
  position: relative;
  min-height: 100%;
  width: 100%;
}

// 表头样式
.el-table .el-table__header th {
  background: rgba(26, 131, 255, 0.29);
}

:deep(.el-table__header) {
  height: 46px !important;
}

:deep(.el-table thead th.el-table__cell ) {
  color: #FFFFFF !important;
  font-size: 14px !important;
}

::v-deep .el-table_3_column_11 .is-left .is-leaf {
  border-radius: 6px 0px 0px 6px;
}

:deep(.el-table__body tr.current-row>td) {
  color: #FFFFFF !important;
  background-color: #0073FF !important;
}
</style>

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/281799.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

MySQL例行检查

MySQL例行检查 1.实例例行检查1.1线程1.2索引1.3临时表1.4连接数1.5BINLOG1.6锁1.7WAIT事件1.8MySQL状态 2.事务与锁例行检查2.1查看索引的cardinality2.2查看是否存在事务阻塞现象2.3查看事务执行时长以及执行的所有SQL2.4事务与锁 3.库表例行检查3.1查看缺失主键的表3.2冗余索…

【网络安全 | Misc】miss_01 太湖杯

解压时提示输入密码&#xff1a; 如果 frFlags 或 deFlags 不为0会导致zip的伪加密 将deFlags的值修改为0 将9改为0&#xff0c;另存为123.zip&#xff1a; 即可绕过加密&#xff1a; 得到一个zip一个docx&#xff0c;但zip需要密码&#xff1a; 因此看docx有无敏感信息&#x…

文心一言 VS 讯飞星火 VS chatgpt (168)-- 算法导论13.2 1题

一、用go语言&#xff0c;写出 RIGHT-ROTATE 的伪代码。 文心一言&#xff1a; 在计算机科学中&#xff0c;右旋转&#xff08;RIGHT-ROTATE&#xff09;是一种常见的操作&#xff0c;通常用于数组或链表。以下是一个使用Go语言实现右旋转的伪代码&#xff1a; func rightRo…

java maven项目添加oracle jdbc的依赖

一般添加依赖是直接在pom.xml中添加配置即可&#xff0c;Maven会自动获取对应的jar包&#xff0c;但是oracle驱动依赖添加后会显示红色&#xff0c;代表找不到依赖项&#xff0c;是因为Oracle授权问题&#xff0c;Maven3不提供Oracle JDBC driver&#xff0c;为了在Maven项目中…

基于JAVA的农家乐订餐系统 开源项目

目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块2.1 用户2.2 管理员 三、系统展示四、核心代码4.1 查询菜品类型4.2 查询菜品4.3 加购菜品4.4 新增菜品收藏4.5 新增菜品留言 五、免责说明 一、摘要 1.1 项目介绍 基于JAVAVueSpringBootMySQL的农家乐订餐系统&#xff0c…

springmvc中controller路由出现404

[java]springmvc中controller路由出现404 problem [java]springmvc中controller路由出现404 reason 可能原因有很多 idea配置不对编译配置不对xml配置jsp位置 solution 核对idea配置 mac: idea->File -> Project Structure 最重要的是 Artifacts&#xff0c;默认配…

金三银四-JAVA核心知识高频面试题

又要快到一年一度的金三银四&#xff0c;开始复习啦&#xff5e;&#xff01; 每天一点点。。 目录 一、内存模型设计 二、synchronized和ReentrantLock的区别 三、垃圾回收机制 四、优化垃圾回收机制 4.1 了解应用需求 4.2. 调整堆大小 4.3. 减少对象分配 4.4. 使用合…

进阶学习——Linux系统服务器硬件认识与RAID磁盘

目录 一、服务器知识补充 1.硬件 2.服务器常见故障 二、认识RAID 1.什么是RAID 2.RAID的优点 3.RAID的实现方式 三、RAID磁盘陈列 1.RAID 0 磁盘陈列介绍——RAID 0 2.RAID 1 磁盘陈列介绍——RAID 1 3.RAID 5 磁盘陈列介绍——RAID 5 4.RAID 6 磁盘陈列介绍——RA…

基于SpringBoot实现的前后端分离电影评分项目,功能:注册登录、浏览影片、热门影片、搜索、评分、片单、聊天、动态

一、项目介绍 本项目主要基于SpringBoot、Mybatis-plus、MySQL、Redis实现的影片评分项目。 本系统是前后端分离的&#xff0c;分别由三个子项目构成&#xff1a;java服务端、用户前端、管理员管理前端 关键词&#xff1a;springboot java vue mysql reids websocket 毕业设计…

Windows 10启用Hyper-V

Windows 10启用Hyper-V 官网教程PowerShell 启用 Hyper-V启用 Hyper-V 角色 我们知道VMware是创建虚拟机的好工具&#xff0c;那Windows平台上有没有虚拟工具呢&#xff1f; 今天我们要讲解的就是Windows才入局的虚拟工具&#xff1a;Hyper-V 官网教程 https://learn.microsof…

【中南林业科技大学】计算机组成原理复习包括题目讲解(超详细)

来都来了点个赞收藏关注一下再走呗&#x1f339;&#x1f339;&#x1f339;&#x1f339; 第1章&#xff1a;绪论 1.冯诺依曼机特点&#xff0c;与现代计算机的区别 冯诺依曼计算机的基本思想是&#xff1a;程序和数据以二进制形式表示&#xff0c;存储程序控制。在计算机中&…

结构体:搜索链表

#include<iostream> #include<iomanip> using namespace std; struct Student //创建结构体Student {int number; //学号char name[20]; //姓名float Chinese, Math, English; //成绩语数英Student* next; //下一个节点 }; Student* CreateList() //创建链表 {Stud…

【CSS】基础知识梳理和总结

1. 前言 CSS&#xff08;Cascading Style Sheets&#xff0c;层叠样式表&#xff09;&#xff0c;用来为HTML文档添加样式的计算机语言。HTML中加载样式的方法有三种&#xff1a; 通过<link>标签加载外部样式表&#xff08;External Style Sheet&#xff09;&#xff0c…

test mock-03-wiremock 模拟 HTTP 服务的开源工具 flexible and open source API mocking

拓展阅读 test 之 jmockit-01-overview jmockit-01-test 之 jmockit 入门使用案例 mockito-01-overview mockito 简介及入门使用 PowerMock Mock Server ChaosBlade-01-测试混沌工程平台整体介绍 jvm-sandbox 入门简介 wiremock WireMock是一个流行的开源工具&#xf…

副业类小报童热门专栏TOP15

今天介绍15个副业小报童&#xff0c;可以说是当前小报童平台&#xff0c;副业类专栏的天花板内容了 这些专栏&#xff0c;都有免费内容可以查看&#xff0c;而且还是3天无理由退款的&#xff0c;完全可以尝试着订阅一波 关键单价都非常亲民&#xff0c;怎么都不亏&#xff01…

C++/CLI——1简介

C/CLI——1简介 如果你是.net程序员&#xff0c;不免会用到C/C写的库。对于简单的调用&#xff0c;可以直接使用DllImport来完成就可以&#xff0c;详情可参考C#调用C/C从零深入讲解。但是对于复杂的C类和对象&#xff0c;尤其是类似于OCC的大型C项目&#xff0c;DllImport可能…

简单几步制作翻页电子画册

翻页电子画册是一种非常流行的电子书形式&#xff0c;它能够以生动、美观、有趣的方式展示您的内容。如果您想要制作自己的翻页电子画册&#xff0c;以下是一些简单的步骤&#xff0c;可以帮助您轻松上手。 首先&#xff0c;你需要一款在线制作电子杂志平台。比如FLBOOK&#x…

再薅!Pika全球开放使用;字节版GPTs免费不限量;大模型应用知识地图;MoE深度好文;2024年AIGC发展轨迹;李飞飞最新自传 | ShowMeAI日报

&#x1f440;日报&周刊合集 | &#x1f3a1;生产力工具与行业应用大全 | &#x1f9e1; 点赞关注评论拜托啦&#xff01; &#x1f440; 终于&#xff01;AI视频生成平台 Pika 面向所有用户开放网页端 https://twitter.com/pika_labs Pika 营销很猛&#xff0c;讲述的「使…

elasticsearch列一:索引模板的使用

概述 近期一直在负责es这块&#xff0c;就想着和大家分享一些使用经验&#xff0c;我们从存储、查询、优化、备份、运维等几个方面来做分享。今天咱们先看下如何更加合理的存储数据。 初见索引模板 记得刚接触es还是18年那会&#xff0c;项目上线后因一些原因导致日志这部分的…

c语言:打印平行四边形|练习题

一、题目 输入平行四边形的边数&#xff0c;用星号打印平行四边形 如图&#xff1a; 二、思路分析 图形分为两部分 1、左边的空格 2、右边的星号 因此&#xff0c;把空格和星号合起来&#xff0c;就是要求的图形 三、代码图片【带注释】 四、源代码【带注释】 #include <s…
最新文章