table 拖拽移动

news2025/3/5 12:00:00

表格拖拽 

 Sortable.js中文网|配置

<!-- 教务处  -->

<template>
    <div class="but">
        <el-button @click="mergeAndPrintArrays()" type="primary">保存数据</el-button>
        <el-button @click="restoration()" type="primary">数据还原</el-button>
    </div>
    <div class="container">
        <div class="left">
            <el-table :data="myArray" row-key="id" ref="table1" id="table1">
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="state" label="前台是否展示" width="90">
                    <template v-slot="scope">
                        <el-switch v-model="scope.row.states" @change="stateChanged(scope.row)" />
                    </template>
                </el-table-column>
                <el-table-column prop="state" label="是否作为搜索条件" width="120">
                    <template v-slot="scope">
                        <el-switch v-model="scope.row.state" @change="stateChanged(scope.row)" />
                    </template>
                </el-table-column>
            </el-table>

        </div>

        <div class="left">
            <el-table :data="myArray2" row-key="id" ref="table2" id="table2">
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="state" label="前台是否展示" width="90">
                    <template v-slot="scope">
                        <el-switch v-model="scope.row.states" @change="stateChanged(scope.row)" />
                    </template>
                </el-table-column>
                <el-table-column prop="state" label="是否作为搜索条件" width="120">
                    <template v-slot="scope">
                        <el-switch v-model="scope.row.state" @change="stateChanged(scope.row)" />
                    </template>
                </el-table-column>
            </el-table>

        </div>

        <div class="left">
            <el-table :data="myArray3" row-key="id" ref="table3" id="table3">
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="state" label="前台是否展示" width="90">
                    <template v-slot="scope">
                        <el-switch v-model="scope.row.states" @change="stateChanged(scope.row)" />
                    </template>
                </el-table-column>
                <el-table-column prop="state" label="是否作为搜索条件" width="120">
                    <template v-slot="scope">
                        <el-switch v-model="scope.row.state" @change="stateChanged(scope.row)" />
                    </template>
                </el-table-column>
            </el-table>

        </div>


        <div class="left">
            <el-table :data="myArray4" row-key="id" ref="table4" id="table4">
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="state" label="前台是否展示" width="90">
                    <template v-slot="scope">
                        <el-switch v-model="scope.row.states" @change="stateChanged(scope.row)" />
                    </template>
                </el-table-column>
                <el-table-column prop="state" label="是否作为搜索条件" width="120">
                    <template v-slot="scope">
                        <el-switch v-model="scope.row.state" @change="stateChanged(scope.row)" />
                    </template>
                </el-table-column>
            </el-table>

        </div>


        <div class="left">
            <el-table :data="myArray5" row-key="id" ref="table5" id="table5">
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="state" label="前台是否展示" width="90">
                    <template v-slot="scope">
                        <el-switch v-model="scope.row.states" @change="stateChanged(scope.row)" />
                    </template>
                </el-table-column>
                <el-table-column prop="state" label="是否作为搜索条件" width="120">
                    <template v-slot="scope">
                        <el-switch v-model="scope.row.state" @change="stateChanged(scope.row)" />
                    </template>
                </el-table-column>
            </el-table>

        </div>

    </div>

</template>

<script>
import Sortable from "sortablejs";
import webfield from "@/api/sys/webfield";
import notifyService from "@/api/notify/notifyService";
export default {
    data() {

        return {
            dataList: [],
            earchVisible: true,
            loading: false,
            myArray: [],
            myArray2: [],
            myArray3: [],
            myArray4: [],
            myArray5: [],
            userName: "",
            userNameF: "",
            companyDTO: '',
            ids: '',
            newtype: ''
        };
    },
    props: ["value1"],
    mounted() {
        this.refreshList();

    },
    async created() {
        var userInfo = this.$TOOL.data.get("USER_INFO");
        this.userName = userInfo.id;
        this.companyDTO = userInfo.companyDTO.id;
    },

    methods: {
        // 获取数据 初始化
        refreshList() {
            // this.newtype = JSON.parse(this.value1)
            // console.log(this.newtype, 'new11')
            this.loading = true;
            const params = {
                officeId: this.companyDTO,
                type: 1,
            };
            webfield.webfieldinit(params).then((data) => {
                this.dataList = JSON.parse(data.data.content)
                this.ids = data.data.id
                console.log(data, "disa")
                this.assignDataToArrays();
                this.loading = false;
            }).catch((error) => {
                console.error('Error fetching data:', error);
                this.loading = false;
            });
        },

        // 获取数据 平均分配
        assignDataToArrays() {
            this.myArray = [];
            this.myArray2 = [];
            this.myArray3 = [];
            this.myArray4 = [];
            this.myArray5 = [];

            // 计算每个数组应该分配的数据量
            const chunkSize = Math.ceil(this.dataList.length / 5);
            // 将 dataList 的数据平均分配到五个数组中
            for (let i = 0; i < this.dataList.length; i++) {
                if (i < chunkSize) {
                    this.myArray.push(this.dataList[i]);
                } else if (i < chunkSize * 2) {
                    this.myArray2.push(this.dataList[i]);
                } else if (i < chunkSize * 3) {
                    this.myArray3.push(this.dataList[i]);
                } else if (i < chunkSize * 4) {
                    this.myArray4.push(this.dataList[i]);
                } else {
                    this.myArray5.push(this.dataList[i]);
                }
            }

            this.initSortable();
        },

        initSortable() {
            const initSortableForTable = (tableRef, dataArray, num) => {
                const tbody = this.$refs[tableRef].$el.querySelector(".el-table__body-wrapper tbody");
                Sortable.create(tbody, {

                    onEnd: ({ newIndex, oldIndex, to, from, clone, pullMode, item }) => {
                        const totableid = to.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.id
                        const fromtableid = from.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.id
                        //id映射
                        const tablemap = {
                            table1: this.myArray,
                            table2: this.myArray2,
                            table3: this.myArray3,
                            table4: this.myArray4,
                            table5: this.myArray5,
                        }
                        if (totableid == fromtableid) {
                            const currRow = dataArray.splice(oldIndex, 1)[0];
                            dataArray.splice(newIndex, 0, currRow);
                        } else {
                            //不一致 跨列拖动
                            const currRow = tablemap[fromtableid].splice(oldIndex, 1)[0];
                            // //向to添加一个元素
                            tablemap[totableid].splice(newIndex, 0, currRow);
                            //from table会少一列
                            if (tablemap[totableid][newIndex + 1]) {
                                //如果 to table 的下一行有数据 补充回fromtable的oldindx
                                tablemap[fromtableid].splice(oldIndex, 0, tablemap[totableid][newIndex + 1])
                                //得删除to table的数据
                                tablemap[totableid].splice(newIndex + 1, 1)
                            } else if (tablemap[totableid][newIndex - 1]) {
                                tablemap[fromtableid].splice(oldIndex, 0, tablemap[totableid][newIndex - 1])
                                //得删除to table的数据
                                tablemap[totableid].splice(newIndex - 1, 1)
                            } else {
                                console.error("前后都没有数据 无法补充")
                            }
                            // console.log(this.myArray, this.myArray2)

                        }

                    },
                    group: 'zhaoxin'
                });
            };

            initSortableForTable('table1', this.myArray);
            initSortableForTable('table2', this.myArray2);
            initSortableForTable('table3', this.myArray3);
            initSortableForTable('table4', this.myArray4);
            initSortableForTable('table5', this.myArray5);
        },
        //合并数组  保存数据
        mergeAndPrintArrays() {

            // console.log(JSON.parse(this.value1), 'oooooooooooo')
            // this.newtype = JSON.parse(JSON.stringify(this.options))[0].value

            this.newtype = JSON.parse(this.value1)
            // 合并三个数组
            const mergedArray = [...this.myArray, ...this.myArray2, ...this.myArray3, ...this.myArray4, ...this.myArray5];
            const news = JSON.stringify(mergedArray);
            this.loading = true;

            // 构建请求参数对象
            const params = {
                officeId: this.companyDTO,
                type: this.newtype,
                content: news,
                operatorId: this.userName,

            };

            const newparams = {
                officeId: this.companyDTO,
                type: this.newtype,
                content: news,
                operatorId: this.userName,
                id: this.ids
            };

            if (this.ids === '') {
                console.log('空啦')
                webfield.webfieldadd(params).then((response) => {
                    location.reload(true);
                    this.loading = false;
                }).catch((error) => {
                    console.error('Error fetching data:', error);
                    this.loading = false;
                });
            } else {
                console.log("不空")
                console.log(this.myArray, 'cuirow')
                webfield.webfieldadd(newparams).then((response) => {
                    location.reload(true);
                    this.loading = false;

                }).catch((error) => {
                    console.error('Error fetching data:', error);
                    this.loading = false;
                });
            }


        },
        // 控制显隐
        stateChanged(row) {
            const index = this.myArray.findIndex(item => item.id === row.id);
            console.log('Row index:', index);
            console.log('Row data:', row);
        },

        // 还原数据
        restoration() {
            this.loading = true;
            console.log(this.loading, 'loading'); // 修正了拼写错误,从 'loda' 改为 'loading'

            if (this.ids === '' || this.ids === undefined || this.ids === null) {
                console.log('kong ')
                alert('已经还原成最初的原始数据了!');
                this.loading = false; // 如果不需要刷新页面,可以在这里直接设置 loading 为 false
            } else {
                console.log(this.ids, 'konglllll ')
                webfield.webfielddel(this.ids).then((data) => {
                    console.log(data)
                    this.assignDataToArrays();
                    location.reload(true); // 仅在数据删除成功后刷新页面
                }).catch((error) => {
                    console.error('Error fetching data:', error);
                    this.loading = false; // 请求失败时设置 loading 为 false
                });
            }
        }
    },
};
</script>

<style lang="less" scoped>
.but {
    margin-bottom: 3rem;
}

.container {
    display: flex;
    margin-bottom: 50rem;

    .left,
    .right {
        background-color: #fff;
        width: 282px;
        height: 1000px;
        margin: 0 4px;
        padding: 0 -8px;


        .item {
            height: 40px;
            border: 1px solid #e9e9e9;
            text-align: center;
            line-height: 40px;
            margin: 20px 0;
            background-color: rgb(242, 242, 242);
        }
    }
}
</style>

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

快速高效使用——阿里通义万相2.1的文生图、文生视频功能

前言&#xff1a;你仅需提供简单的几个提示词&#xff0c;即可快速高效帮你生成更为丰富的提示词并生成满意的图片或者视频。无论是为了创作艺术作品、设计商业宣传素材&#xff0c;还是满足个人兴趣爱好等&#xff0c;都能快速将脑海中的想法转化为逼真的图片或生动的视频。 目…

厦门大学第3弹:DeepSeek大模型及其企业应用实践(150页PPT,企业人员的大模型宝典)

本报告由厦门大学大数据教学团队制作&#xff0c;由林子雨副教授主讲&#xff0c;旨在为企业人员提供一份关于大模型技术及其应用的科普资料。从大模型的基本概念出发&#xff0c;详细介绍了其发展历程、分类方式以及与人工智能的关系&#xff0c;重点探讨了大模型在企业中的多…

Qt显示一个hello world

一、显示思路 思路一&#xff1a;通过图形化方式&#xff0c;界面上创建出一个控件显示。 思路二&#xff1a;通过编写C代码在界面上创建控件显示。 二、思路一实现 点开 Froms 的 widget.ui&#xff0c;拖拽 label 控件&#xff0c;显示 hello world 即可。 qmake 基于 .…

[LeetCode]day33 150.逆波兰式求表达值 + 239.滑动窗口最大值

逆波兰式求表达值 题目链接 题目描述 给你一个字符串数组 tokens &#xff0c;表示一个根据 逆波兰表示法 表示的算术表达式。 请你计算该表达式。返回一个表示表达式值的整数。 注意&#xff1a; 有效的算符为 ‘’、‘-’、‘*’ 和 ‘/’ 。 每个操作数&#xff08;运…

线代[9]|线性代数主要内容及其发展简史(任广千《线性代数的几何意义》的附录1)

文章目录 向量行列式矩阵线性方程组二次型 向量 向量又称为矢量&#xff0c;最初应用与物理学。很多物理量如力、速度、位移以及电场强度、磁感应强度等等都是向量。大约公元前350年前&#xff0c;古希腊著名学者亚里士多德就知道了力可以表示成向量&#xff0c;两个力的组合作…

FFmpeg-chapter3和chapter4-读取视频流(原理篇和实战篇)

ffmpeg网站&#xff1a;About FFmpeg 1 库介绍 &#xff08;1&#xff09;libavutil是一个包含简化编程函数的库&#xff0c;包括随机数生成器、数据结构、数学例程、核心多媒体实用程序等等。 &#xff08;2&#xff09;libavcodec是一个包含音频/视频编解码器的解码器和编…

音频3A测试--AEC(回声消除)测试

一、测试前期准备 一台录制电脑:用于作为近段音源和收集远端处理后的数据; 一台测试设备B:用于测试AEC的设备; 一个高保真音响:用于播放设备B的讲话; 一台播放电脑:用于模拟设备A讲话,和模拟设备B讲话; 一台音频处理器(调音台):用于录制和播放数据; 测试使用转接线若…

Unity插件-Mirror使用方法(一)Mirror介绍

目录 一、使用介绍 二、插件介绍 1、简述 2、核心功能与特点 基于组件的高层抽象 服务器-客户端架构 序列化与同步 可扩展性与灵活性 跨平台支持 社区与生态 3、典型应用场景 4、基本使用示例 安装 设置 NetworkManager 同步变量与 RPC 5、优缺点对比 6、为什…

Markdown HTML 图像语法

插入图片 Markdown ![图片描述](图片链接)一般来说&#xff0c;直接复制粘贴过来就行了&#xff0c;部分网页/应用可以拖拽&#xff0c;没人会真敲图片的链接吧…… 示例图片&#xff1a; ![Creeper?](https://i-blog.csdnimg.cn/direct/f5031c8c4f15421c9882d7eb23540b8…

操作系统启动——前置知识预备

文章目录 1. 理解冯诺依曼体系结构1.1 简单见一见冯诺依曼1.2 进一步认识1.3 为什么一定要有内存的存在&#xff1f; 2. 操作系统2.1 概念2.2 设计OS的目的2.3 OS的核心功能2.4 如何理解“管理”二字&#xff1f;(小故事版)2.5 系统调用和库函数概念 3. 进程简述3.1 基本概念3.…

详细分析KeepAlive的基本知识 并缓存路由(附Demo)

目录 前言1. 基本知识2. Demo2.1 基本2.2 拓展2.3 终极 3. 实战 前言 &#x1f91f; 找工作&#xff0c;来万码优才&#xff1a;&#x1f449; #小程序://万码优才/r6rqmzDaXpYkJZF 基本知识推荐阅读&#xff1a;KeepAlive知识点 从实战中学习&#xff0c;源自实战中vue路由的…

AI数据分析:deepseek生成SQL

在当今数据驱动的时代&#xff0c;数据分析已成为企业和个人决策的重要工具。随着人工智能技术的快速发展&#xff0c;AI 驱动的数据分析工具正在改变我们处理和分析数据的方式。本文将着重介绍如何使用 DeepSeek 进行自动补全SQL 查询语句。 我们都知道&#xff0c;SQL 查询语…

vue3(笔记)3.0 Pinia状态管理数据.持久化插件.内置vue devtools调试工具

---pinia状态管理数据(vuex升级版) 官网镜像:(https://pinia.vuejs.org/zh/core-concepts/) 安装(手动): npm install pinia 导入pinia: 组合式写法的格式: 使用前需要导入: import {defineStore} from piniaactions:支持了同步和异步的方法(融合了mutations) 在组件中调…

网络原理--HTTP协议

http中文名为超文本传输协议&#xff0c;所谓“超文本”就是指传输范围超出了能在UTF8等码表上找到的字符的范围&#xff0c;包含一些图片&#xff0c;特殊格式之类的。 HTTP的发展简介 从图中可以看出到现在已经发展出了HTTP3&#xff0c;但是市面上的主流还是以HTTP1.0为主。…

华为hcia——Datacom实验指南——配置手工模式以太网链路聚合

什么是以太网链路聚合&#xff08;Eth-trunk&#xff09; 是一种将多个物理链路捆绑在一起&#xff0c;让设备以为是一条大链路&#xff0c;能够增加带宽&#xff0c;增加冗余度&#xff0c;提升可靠性&#xff0c;实现负载平衡。 传输方式有两种 基于数据流传输和基于数据包…

【C语言6】数组和函数实践:扫雷游戏的简单实现

文章目录 一、扫雷游戏分析和设计1.1 扫雷游戏的功能说明1.2 游戏的分析和设计1.2.1 数据结构的分析1.2.2 文件结构设计 二、扫雷游戏的代码实现三、扫雷游戏的扩展总结 一、扫雷游戏分析和设计 1.1 扫雷游戏的功能说明 使用控制台实现经典的扫雷游戏游戏可以通过菜单实现继续…

LeetCode 热题 100----1.两数之和

LeetCode 热题 100----1.两数之和 题目描述 我的解法 语言&#xff1a;js 思路就是&#xff1a;用双重循环去找哪两个数字相加等于target&#xff0c;目前的时间复杂度为O(n2)&#xff0c;之后右优化思路再更新。

《模式和状态管理》知识总结三-EcuM与BswM模块的交互

前言 这篇文章主要搞清楚在模式管理中&#xff0c;BswM和EcuM各自的分工。距离学完模式管理也有几天时间了&#xff0c;写这篇文章算是复习一下。 EcuM及BswM交互总览 EcuM负责Ecu的上下电状态的处理&#xff0c;当Ecu处于正常运行状态的时候&#xff0c;EcuM会将Ecu的控制权…

客户需求模糊或频繁变更怎么办

应对客户需求模糊或频繁变更的关键在于 明确沟通、敏捷应对、科学决策。其中&#xff0c;明确沟通尤为重要&#xff0c;因为通过有效沟通&#xff0c;不仅能迅速厘清客户真实需求&#xff0c;还能及时发现隐藏问题&#xff0c;降低项目风险&#xff0c;为后续调整提供有力数据支…

动静态库-Linux 学习

在软件开发中&#xff0c;程序库是一组预先编写好的程序代码&#xff0c;它们存储了常用的函数、变量和数据结构等。这些库可以帮助开发者节省大量的时间和精力&#xff0c;避免重复编写相同的代码。当我们在 Linux 系统中开发程序时&#xff0c;经常会用到两种类型的程序库&am…