使用draggable组件实现拖拽自定义表格

article/2025/8/14 19:11:15

主要是为了给表格自定义功能添加设置项,拖拽行的位置改变更保存给后端更新页面,实现表格的前后位置变换及宽度自定义

 

 上代码

<template><div><div class="text-box" v-show="showTextBox" unselectable="on" onselectstart="return false;"><el-row class="title"><el-col :span="12" align="left">自定义显示列表</el-col><el-col :span="12" align="right"><i @click="showTextBox=false" class="el-icon-close"></i></el-col></el-row><el-row class="list-title"><el-col :span="4" align="center">显示</el-col><el-col :span="14" class="pl20">列名</el-col><el-col :span="6" align="center">拖动调整顺序</el-col></el-row><draggable :style="{maxHeight:textheight}" class="list-box" v-model="textLists" chosenClass="chosen"forceFallback="true" :scroll="true" animation="300" handle=".moveBox" :move="onMove"><transition-group><el-row v-for="city in textLists" :key="city.id"><el-row v-if="!city.columnshow || showRoleNew(city.columnshow[0])" class="item"><el-col :span="4" align="center"><el-checkbox :disabled="!!city.fixed" v-model="city.checked"></el-checkbox></el-col><el-col :span="14" class="text pl20">{{ city.name }}</el-col><el-col :span="6" align="center"><div class="moveBox" v-if="!city.fixed"><i class="iconfont iconsantiaogang"></i></div></el-col></el-row></el-row></transition-group></draggable><el-row class="btns"><el-col :span="12"><el-button type="text" @click="cleanText">恢复默认</el-button></el-col><el-col :span="12" align="right" class="fontSize0"><el-button size="mini" @click="showTextBox = false">取消</el-button><el-button size="mini" type="primary" @click="saveText">保存</el-button></el-col></el-row></div><div class="bag" v-show="showTextBox" @click="showTextBox=false" @contextmenu.prevent="showTextBox=false"></div></div>
</template><script>
import { saveTableHeadListText, getTableHeadListText } from '../../api/main';
import { showRoleNew } from '@/utils/common';
import draggable from 'vuedraggable';let that;
export default {name: 'tableHeadList',props: {textList: {type: Array,default: () => []},orderName: {type: String},type: {type: String}},components: { draggable },data() {that = this;return {showRoleNew,showTextBox: false,trajectory: [], //移动轨迹textheight: 200,textLists: []};},methods: {onMove(e) {if (e.relatedContext.element.fixed) return false;return true;},//获取屏幕高度beforeMount() {var h = document.documentElement.clientHeight || document.body.clientHeight;this.textheight = h - event.y - 50 + 'px'; //减去页面上固定高度height},showCustom() {this.$nextTick(() => {this.textLists = JSON.parse(JSON.stringify(this.textList));});if (this.showTextBox) {return;}this.showTextBox = true;this.beforeMount();},saveText() {let listLength = this.textLists.filter(item => {return item.checked;}).length;if (listLength < 5 && listLength !== this.textLists.length) {return this.$message.warning('显示列表数量不能小于5个!!!');}this.showTextBox = false;this.$emit('saveText');saveTableHeadListText({tableName: this.orderName,fieldStr: JSON.stringify(this.textLists)}).then(res => {if (res.data.status === 200) {this.$emit('saveText', this.textLists);}});},saveWidth(list) {saveTableHeadListText({tableName: this.orderName,fieldStr: JSON.stringify(list)}).then(res => {if (res.data.status === 200) {this.$emit('saveText', list);}});},getTableHeadList() {this.$emit('saveText');getTableHeadListText({tableName: this.orderName}).then(res => {if (res.data.status === 200) {if (res.data.data) {this.$emit('saveText', JSON.parse(res.data.data.fieldStr), 'start');} else {this.$emit('saveText', [], 'start');}}});},cleanText() {this.$emit('cleanText');}}
};
</script><style scoped lang="scss">
.text-box {position: fixed;top: 80px;left: 50%;z-index: 9999;background: #FFFFFF;width: 500px;margin-left: -250px;border: 1px solid #e3e3e3;border-radius: 8px;color: #111A34;overflow: hidden;.title {height: 50px;line-height: 50px;border-bottom: 1px solid #EFEFEF;font-size: 16px;padding: 0 20px;.el-icon-close {font-size: 20px;}}.list-title {height: 40px;line-height: 40px;font-size: 14px;background: #FAFAFA;border-radius: 8px 8px 0px 0px;padding: 0 5px;margin: 10px;}.list-box {padding: 0 10px 10px 10px;overflow-y: auto;.item {width: 100%;height: 40px;line-height: 39px;font-size: 14px;border-bottom: 1px solid #E9E9E9;padding: 0 5px;&:hover {background: #eeeeee;}}}.btns {font-size: 14px;padding: 20px;box-shadow: 0px -2px 6px 0px #EBEBF4;}.moveBox {cursor: move;color: #999999;}
}.bag {position: fixed;top: 0px;left: 0px;width: 100%;height: 100%;background: rgba(30, 36, 42, 0.49);z-index: 9998;
}
</style>
 saveText(list, type) {//进入页面获取表头数据if (type === 'start') {this.$parent.loading = falseif (list.length) {//后台返回数据this.tableheadlist = listthis.$nextTick(() => {this.$refs.reportTable.doLayout();})} else {//使用默认数据this.tableheadlist = tableHead[this.orderName] || []this.$nextTick(() => {this.$refs.reportTable.doLayout();})}try {this.getRightTableHeight()} catch (e) {}} else {if (list && list.length) {this.$parent.loading = falsethis.$message.success('保存成功')this.tableheadlist = listthis.$nextTick(() => {this.$refs.reportTable.doLayout();})} else {this.$parent.loading = truethis.tableheadlist = []                  }}


http://chatgpt.dhexx.cn/article/0KQouJvi.shtml

相关文章

vue拖拽组件draggable

1、安装vuedraggable依赖 npm i vuedraggable2、在页面中引入 import Draggable from vuedraggable components: {Draggable },下面为实图使用&#xff0c;代码直接参考下面的&#xff0c;拷贝即可使用 //主页面 <template><div class"ctnr"><div…

vue3 draggable拖拽

&#xff01;&#xff01;首先安装 vuedraggable npm i -S vuedraggablenext一定要带上next&#xff0c;不然就会报错 很恶心&#xff01;使用建议看官网。 官网&#xff1a;vue.draggable中文文档 - itxst.comVue.Draggable是一款基于Sortable.js实现的vue拖拽插件。支持移动…

vue-draggable-resizable定制化可拖动控件

最近遇到一个需求&#xff1a;前端定制化生成合同模板&#xff0c;生成时可以在指定位置拖放指定的控件&#xff0c;可动态编辑指定控件的属性和位置&#xff0c;最后将控件的位置等属性传给后台&#xff0c;后续使用模板签署合同时&#xff0c;乙方可在模板上指定位置签署。 点…

使用 vue.draggable 实现拖拽、克隆

这是大佬的博客 https://blog.csdn.net/zjiang1994/article/details/79809687 里面对vue.draggable的一些方法和属性&#xff0c;进行了详解&#xff0c;非常的详细&#xff0c;比官网的还要详细哦&#xff01;给大佬点赞&#xff01;&#xff01;&#xff01; 这是vue.draggab…

React Draggable 实现拖拽 - 最详细中文教程 - 卡拉云

本文首发&#xff1a;《React Draggable 实现拖拽 - 最详细中文教程 - 卡拉云》 React Draggable 是 react 生态中&#xff0c;最好用的拖拽实现库之一。如果你的应用中需要实现拖拽功能&#xff0c;可以尝试用 react-draggable&#xff0c;它可以满足多数情况下的拖拽需求&am…

draggable属性的应用

draggable属性用来定义元素是否可以拖动。 效果图&#xff1a; 代码如下&#xff1a; <!DOCTYPE html> <html> <head><meta charset"UTF-8"><title>draggable属性的应用</title> </head> <body> <h3>元素拖…

draggable 和 sortable的JS原生实现

概要 本文主要利用html 5的draggable原生特性&#xff0c;实现一个可拖拽的效果。我们可以创建包含多个页面节点的容器&#xff0c;每个容器可以包含多个节点。通过拖拽&#xff0c;可以移动一个容器内的节点到其他容器&#xff0c;每个容器内的节点和以通过拖拽改变排列顺序。…

vue3使用拖拽组件draggable.next的使用教程【保姆级】

环境&#xff1a;vue3setup语法 首先放官方文档的链接&#xff1a; 中文版本&#xff1a; https://www.itxst.com/vue-draggable-next/tutorial.html &#xff08;民间翻译&#xff09; 英文版本&#xff1a;https://github.com/SortableJS/vue.draggable.next 因为自己写的过程…

vue的拖拽插件: vue.draggable

中文文档地址: vue.draggable中文文档 - itxst.comVue.Draggable是一款基于Sortable.js实现的vue拖拽插件。支持移动设备、拖拽和选择文本、智能滚动&#xff0c;可以在不同列表间拖拽、不依赖jQuery为基础、vue 2过渡动画兼容、支持撤销操作&#xff0c;总之是一款非常优秀的…

react-draggable实现拖拽详解

react-draggable 属性常用属性属性列表 事件列表举例首先安装 react-draggable实现移动 希望小编写的能够帮助到你&#x1f618; 属性 常用属性 属性默认值介绍axisxhandle拖动的方向&#xff0c;可选值 x ,y,bothhandle无指定拖动handle的classposition无handle的位置&#…

draggable拖拽组件使用

项目开发中需要用到拖拽组件&#xff0c;因为前端技术框架是vue&#xff0c;这里就使用了vue的一款拖拽插件vue.draggable&#xff0c;一般基本的需求都能满足&#xff0c;这里使用了多个draggable嵌套&#xff0c;达到两级之前相互拖拽的功能。 以下是类似teambition的效果图…

原生JS的拖拽属性draggable(详解)

摘要 作为h5新增的属性draggable&#xff0c;它能够给与一切的html元素拖动的效果。而在这个属性之下&#xff0c;也有着关于拖动效果的各个方法。 而这一篇文章&#xff0c;主要就是说一下关于draggable属性的使用以及工作场景。 1.了解draggable属性的使用 对我来讲&#…

EasyUI基础入门之Draggable(拖拽)

前面学习了easyui基础的解析器,加载器。对于他们入门阶段我们只需简单的了解下即可&#xff0c;毕竟先阶段并不会太过深入。接下来根据easyui官网文档的顺序安排学习下Draggable插件。 Draggable是什么 Draggable是easyui中用于实现拖拽功能的一个插件。利用它&#xff0c;我们…

jts-core 使用说明(二)

jts-core 使用说明 示例代码库 JTS源码底层使用说明&#xff0c;通过一下章节介绍说明 层次结构 org.locationtech.jts: algorithm - 算法包jts-io-common - I/O classes for open spatial formatsgeom - geom基础包geom.prep - 对适当准备的几何图形执行优化的几何操作类e…

java jts获取线上任意一点到起点的距离

java jts获取线上任意一点到起点的距离 近期项目要求计算某段公路上一辆车的运行轨迹&#xff0c;通过路上的设备实时获取车辆的经纬度信息并发送到后台接收。 抽象出来就是获取线上任意一点到起点的距离&#xff0c;按照一定每秒一次的频率去计算就获取该点的运动轨迹了。 主要…

JTS-Geometry 使用说明(五)

org.locationtech.jts.geom.Geometry 使用说明 示例代码库 Geometry 经纬度操作类 Geometry类继承关系 说明 平面、线性几何操作抽象类 提供的相关方法: 1.基础方法&#xff1a; 1.1 getLength:获取长度&#xff0c;线几何返回点与点之间的长度之和&#xff1b;闭合几何返回…

JAVA使用JTS 判断坐标点是否在坐标多边形内部

JAVA使用JTS 判断坐标点是否在坐标多边形内部 思路Geometry之间的关系API及参考博客代码依赖工具类测试类 思路 判断坐标点是否在坐标多边形内部&#xff0c;首先不能直接计算坐标点&#xff0c;是需要字符串坐标点转化为地理空间数据Geometry&#xff0c;然后使用JTS包中提供…

JTS学习笔记

JTS学习笔记 基础的类 Geometry geom对象Coordinate坐标类Point Point对象MultiPoint 基本对象MultiPoint等等GeometryFactory工厂对象PreparedGeometryFactoryPreparedGeometry 几何对象Geometry public abstract class Geometry implements Cloneable, Comparable, Seria…

JTS-Angle GIS几何角度计算使用说明(十八)

org.locationtech.jts.algorithm.Angle 角度计算使用说明 示例代码库 Angle 角度计算 1.Angle.angle(p0,p1) public static double angle(Coordinate p0, Coordinate p1) {double dx p1.x - p0.x;double dy p1.y - p0.y;return Math.atan2(dy, dx); }返回与x轴正方向的夹…

java jts_Java Topology Suite (JTS)与空间数据模型

JTS是Java的处理地理数据的API&#xff0c;它提供以下功能&#xff1a; 实现了OGC关于简单要素SQL查询规范定义的空间数据模型 一个完整的、一致的、基本的二维空间算法的实现&#xff0c;包括二元运算(例如touch和overlap)和空间分析方法(例如intersection和buffer) 一个显示的…