当前位置: 首页 > news >正文

vue3实现多表头列表el-table,拖拽,鼠标滑轮滚动条优化

  • 需求背景
  • 解决效果
  • index.vue

需求背景

需要实现多表头列表的用户体验优化

解决效果

index.vue

<!--/**
* @author: liuk
* @date: 2024-07-03
* @describe:**** 多表头列表
*/-->
<template><el-table ref="tableRef" height="calc(100% - 80px)" :data="listData" border v-loading="loading" stripestyle="width: 100%" :resizable="false" @mousedown="mouseDownHandler" @mouseup="mouseUpHandler"@mousemove="mouseMoveHandler" element-loading-text="数据加载中..."><el-table-column label='时间' prop="tiem" width="145" fixed align="center" v-if="listData.length"><template #default="scope">{{ moment(scope.row['time']).format('YYYY/MM/DD HH:mm') }}</template></el-table-column><el-table-column v-for="(item, index) in keyArr" :key="index" :label=item.name :prop=item.propsalign="center" :width="item.name.length * 12 + 20 > 110 ? item.name.length * 12 + 20 : 110"><template #default="scope"><el-input class="cell-input" @change="addEditItem(scope.row[item.props])" :disabled="!disadledFalg"v-model.number="scope.row[item.props].rainstormValue"/></template></el-table-column></el-table>
</template><script lang="ts" setup>
import {reactive, toRefs} from "vue"
import moment from "moment";const model = reactive({keyArr: [...] // {name: '名称', props: 'name'}listData: [],loading: false,
})
const { keyArr,listData,loading} = toRefs(model)onMounted(() => {addTableWheel()
})// 列表长表头拖拽优化
const tableRef = ref(null)
const mouseFlag = ref(false)
const mouseOffset = ref(0)
const addTableWheel = () => {tableRef.value.scrollBarRef.wrapRef.addEventListener('wheel', event => {event.preventDefault()const delta = event.deltaX || event.deltaYtableRef.value.scrollBarRef.wrapRef.scrollLeft += delta})
}
const mouseDownHandler = (e) => {mouseOffset.value = e.clientX;mouseFlag.value = true;
}
const mouseUpHandler = () => {mouseFlag.value = false;
}
const mouseMoveHandler = (e) => {let divData = tableRef.value.scrollBarRef.wrapRef;if (mouseFlag.value) {divData.scrollLeft -= (-mouseOffset.value + (mouseOffset.value = e.clientX));}
}
</script><style lang="scss" scoped>
:deep(.el-table) {.el-table__inner-wrapper {height: 100% !important;}.el-scrollbar__thumb {background: #151515;}
}
</style>
http://www.lryc.cn/news/393261.html

相关文章:

  • Micron近期发布了32Gb DDR5 DRAM
  • SQL Server时间转换
  • kubernetes集群部署:node节点部署和CRI-O运行时安装(三)
  • 03:Spring MVC
  • 玩转springboot之springboot注册servlet
  • 推荐好玩的工具之OhMyPosh使用
  • pydub、ffmpeg 音频文件声道选择转换、采样率更改
  • 0803实操-Windows Server系统管理
  • 使用Java构建物联网应用的最佳实践
  • 价格预言机的使用总结(一):Chainlink篇
  • 【Pyhton】读取寄存器数据到MySQL数据库
  • jmeter-beanshell学习3-beanshell获取请求报文和响应报文
  • 【C++】B树及其实现
  • C++(Qt)-GIS开发-QGraphicsView显示瓦片地图简单示例
  • CTFShow的RE题(三)
  • WordPress主题开发进群付费主题v1.1.2 多种引流方式
  • SAP中的 UPDATA TASK 和 BACKGROUND TASK
  • UDP协议:独特之处及其在网络通信中的应用
  • 支持向量机(Support Vector Machine,SVM)及Python和MATLAB实现
  • 【RT-thread studio 下使用STM32F103-学习sem-信号量-初步使用-线程之间控制-基础样例】
  • 使用nodejs输出著作权申请所需的word版源码
  • [Vite]vite-plugin-react和vite-plugin-react-swc插件原理了解
  • 记一次使用“try-with-resources“的语法导致的BUG
  • 用Excel处理数据图像,出现交叉怎么办?
  • SpringBoot | 大新闻项目后端(redis优化登录)
  • ESP32——物联网小项目汇总
  • flutter:监听路由的变化
  • Linux多进程和多线程(六)进程间通信-共享内存
  • ruoyi后台修改
  • macOS查看系统日志的方法