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

sortable中el-table拖拽及点击箭头上下移动row

效果

安装 

npm install sortablejs --save

引入

import Sortable from "sortablejs";
 <el-table:data="tableBody"borderref="tableRef":stripe="true":key="tableKey"><el-table-column type="index" label="排序" width="150" key="index" /><el-table-column prop="category" label="大类名称" key="category"><template #default="{ row, $index }"><div class="title">{{ row.category }}</div><div class="icon"><el-icon:class="{ active: activeButton === `up-${$index}` }"@click="moveItem($index, 'up')"><CaretTop/></el-icon><el-icon:class="{ active: activeButton === `down-${$index}` }"@click="moveItem($index, 'down')"><CaretBottom/></el-icon></div></template></el-table-column></el-table><script setup>
const activeButton = ref();
//行拖拽const rowDrop=()=> {const tbody = tableRef.value?.$el.querySelector(".el-table__body-wrapper tbody");Sortable.create(wrapperTr, {animation: 150,ghostClass: "blue-background-class",onEnd: async (evt: any) => {handleDragEnd(evt);},});}
const handleDragEnd = async (event: any) => {const { oldIndex, newIndex } = event;if (oldIndex !== newIndex) {const movedItem = tableBody.value.splice(oldIndex, 1)[0];tableBody.value.splice(newIndex, 0, movedItem);tableKey.value += 1;const url = "./?_m=&_a=";const formData = new FormData();formData.append("id", globalData.id);formData.append("category", movedItem.category);formData.append("xh", newIndex + 1);const response = await post(url, formData);if (response.code == 0) {ElMessage({showClose: true,message: "排序成功",type: "success",});}}
};const moveItem = async (index: any, direction: any) => {const newIndex = direction == "up" ? index - 1 : index + 1;if (newIndex >= 0 && newIndex < tableBody.value.length) {const item = tableBody.value.splice(index, 1)[0];tableBody.value.splice(newIndex, 0, item);activeButton.value = `${direction}-${index}`;setTimeout(() => (activeButton.value = null), 200);const url = "./?_m=&_a=";const formData = new FormData();formData.append("id", globalData.id);formData.append("category", item.category);formData.append("xh", newIndex + 1);const response = await post(url, formData);if (response.code == 0) {ElMessage({showClose: true,message: "排序成功",type: "success",});}}
};
</script>

点击箭头加颜色 

.active {color: #009688; /* 例如,活动状态的颜色 */
}


http://www.mrgr.cn/news/10315.html

相关文章:

  • C++ wxWidgets图形界面开发用什么IDE最好?
  • 【精选】分享9款AI毕业论文生成初稿题目网站
  • [SWPUCTF 2023 秋季新生赛]UnS3rialize
  • 【Linux】理解操作系统中的进程状态:阻塞、挂起、运行
  • Isaac Sim仿真平台学习(2)系统架构
  • FastCGI简述
  • Vue开发者工具安装详细教程
  • 全栈杂谈第二期:计算机中的线程
  • 云计算实训36——mysql镜像管理、同步容器和宿主机时间、在容器外执行容器内命令、容器的ip地址不稳定问题、基础镜像的制作、镜像应用
  • 电子电路学习之二极管-1
  • 【ES6新特性】介绍ES6新特性的内容,如var,Let,Const声明变量的区别,解构赋值的概念,字符串的扩展,数组的扩展,以及对象的扩展。
  • 【VectorNet】vectornet网络学习笔记
  • python | 图片转换为 pdf 实现方法
  • SQLserver复制已经存在的表和不存在的表
  • go设计模式——单例模式
  • Docker 安装 Zookeeper + Kafka 保姆级教程
  • 测试资料4444
  • 【机器学习】逻辑回归原理(极大似然估计,逻辑函数Sigmod函数模型详解!!!)
  • 鸿蒙内核源码分析(任务切换篇) | 看汇编如何切换任务
  • 云计算day30