ruoyi element-ui 实现拖拉调整图片顺序

ruoyi element-ui 实现拖拉调整图片顺序

安装sortablejs

https://sortablejs.com/

在这里插入图片描述

npm 安装sortablejs

npm install sortablejs --save

相关options

var sortable = new Sortable(el, {group: "name",  // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] }sort: true,  // sorting inside listdelay: 0, // time in milliseconds to define when the sorting should startdelayOnTouchOnly: false, // only delay if user is using touchtouchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag eventdisabled: false, // Disables the sortable if set to true.store: null,  // @see Storeanimation: 150,  // ms, animation speed moving items when sorting, `0` — without animationeasing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples.handle: ".my-handle",  // Drag handle selector within list itemsfilter: ".ignore-elements",  // Selectors that do not lead to dragging (String or Function)preventOnFilter: true, // Call `event.preventDefault()` when triggered `filter`draggable: ".item",  // Specifies which items inside the element should be draggabledataIdAttr: 'data-id', // HTML attribute that is used by the `toArray()` methodghostClass: "sortable-ghost",  // Class name for the drop placeholderchosenClass: "sortable-chosen",  // Class name for the chosen itemdragClass: "sortable-drag",  // Class name for the dragging itemswapThreshold: 1, // Threshold of the swap zoneinvertSwap: false, // Will always use inverted swap zone if set to trueinvertedSwapThreshold: 1, // Threshold of the inverted swap zone (will be set to swapThreshold value by default)direction: 'horizontal', // Direction of Sortable (will be detected automatically if not given)forceFallback: false,  // ignore the HTML5 DnD behaviour and force the fallback to kick infallbackClass: "sortable-fallback",  // Class name for the cloned DOM Element when using forceFallbackfallbackOnBody: false,  // Appends the cloned DOM Element into the Document's BodyfallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag.dragoverBubble: false,removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding itemptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into itsetData: function (/** DataTransfer */dataTransfer, /** HTMLElement*/dragEl) {dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent},// Element is chosenonChoose: function (/**Event*/evt) {evt.oldIndex;  // element index within parent},// Element is unchosenonUnchoose: function(/**Event*/evt) {// same properties as onEnd},// Element dragging startedonStart: function (/**Event*/evt) {evt.oldIndex;  // element index within parent},// Element dragging endedonEnd: function (/**Event*/evt) {var itemEl = evt.item;  // dragged HTMLElementevt.to;    // target listevt.from;  // previous listevt.oldIndex;  // element's old index within old parentevt.newIndex;  // element's new index within new parentevt.oldDraggableIndex; // element's old index within old parent, only counting draggable elementsevt.newDraggableIndex; // element's new index within new parent, only counting draggable elementsevt.clone // the clone elementevt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving},// Element is dropped into the list from another listonAdd: function (/**Event*/evt) {// same properties as onEnd},// Changed sorting within listonUpdate: function (/**Event*/evt) {// same properties as onEnd},// Called by any change to the list (add / update / remove)onSort: function (/**Event*/evt) {// same properties as onEnd},// Element is removed from the list into another listonRemove: function (/**Event*/evt) {// same properties as onEnd},// Attempt to drag a filtered elementonFilter: function (/**Event*/evt) {var itemEl = evt.item;  // HTMLElement receiving the `mousedown|tapstart` event.},// Event when you move an item in the list or between listsonMove: function (/**Event*/evt, /**Event*/originalEvent) {// Example: https://jsbin.com/nawahef/edit?js,outputevt.dragged; // dragged HTMLElementevt.draggedRect; // DOMRect {left, top, right, bottom}evt.related; // HTMLElement on which have guidedevt.relatedRect; // DOMRectevt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by defaultoriginalEvent.clientY; // mouse position// return false;for cancel// return -1; — insert before target// return 1; — insert after target// return true; — keep default insertion point based on the direction// return void; — keep default insertion point based on the direction},// Called when creating a clone of elementonClone: function (/**Event*/evt) {var origEl = evt.item;var cloneEl = evt.clone;},// Called when dragging element changes positiononChange: function(/**Event*/evt) {evt.newIndex // most likely why this event is used is to get the dragging element's current index// same properties as onEnd}
});

修改组件image-upload、el-upload

el-upload

<el-uploadmultiple:action="uploadImgUrl"list-type="picture-card":on-success="handleUploadSuccess":before-upload="handleBeforeUpload":limit="limit":on-error="handleUploadError":on-exceed="handleExceed"ref="imageUpload":on-remove="handleDelete":show-file-list="true":headers="headers":file-list.sync="fileList":on-preview="handlePictureCardPreview":class="{hide: this.fileList.length >= this.limit}"><i class="el-icon-plus"></i>
</el-upload>

引入Sortable

import Sortable from 'sortablejs';

初始化挂载

mounted() {this.initDragSort();
},

实现前端拖动,后台路径变化

这里直接使用onEnd

// Element dragging endedonEnd: function (/**Event*/evt) {var itemEl = evt.item;  // dragged HTMLElementevt.to;    // target listevt.from;  // previous listevt.oldIndex;  // element's old index within old parentevt.newIndex;  // element's new index within new parentevt.oldDraggableIndex; // element's old index within old parent, only counting draggable elementsevt.newDraggableIndex; // element's new index within new parent, only counting draggable elementsevt.clone // the clone elementevt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving},
// 排序拖动initDragSort() {const el = this.$refs.imageUpload.$el.querySelectorAll('.el-upload-list')[0];Sortable.create(el, {onEnd: ({ oldIndex, newIndex }) => {// 交换位置const changelist = this.fileList;//console.log("內容1:"+this.fileList);const page = changelist[oldIndex];changelist.splice(oldIndex, 1);changelist.splice(newIndex, 0, page);//获取新listthis.fileList = changelist;//将list转化成stringthis.listToString(this.fileList)//console.log("內容2:"+this.fileList);//赋值返回this.$emit("input", this.listToString(this.fileList));}});}

使用组件

<el-form-item label="图片" prop="picture"><image-upload v-model="form.picture"/>
</el-form-item>

图片顺序调整

图片顺序调整
在这里插入图片描述

后台传值同步调整

在这里插入图片描述

组件下载
https://download.csdn.net/download/qq_21271511/89179959

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

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

相关文章

甘特图:如何制定一个有效的产品运营规划?

做好一个产品的运营规划是一个复杂且系统的过程&#xff0c;涉及多个方面和阶段。以下是一些关键步骤和考虑因素&#xff0c;帮助你制定一个有效的产品运营规划&#xff1a; 1、明确产品定位和目标用户&#xff1a; 确定产品的核心功能、特点和优势&#xff0c;明确产品在市…

python自动生成SQL语句自动化

&#x1f47d;发现宝藏 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。【点击进入巨牛的人工智能学习网站】。 Python自动生成SQL语句自动化 在数据处理和管理中&#xff0c;SQL&#xff08;Structured …

跟我学C++高级篇——获取类型名称的番外小插曲

一、获取类型名称 在前面的反射中&#xff0c;可以通过一些技术手段来实现获取类型的名称。这么一个看似简单的功能&#xff0c;其实实现起来并没有想象的那么简单。在一些框架中&#xff0c;包含了类似的功能&#xff0c;而主流的编译器则支持的各有不同。这不是说这种接口有…

【华为OD机试】处理器问题

目录 题目描述 输入描述 输出描述 用例 考察算法&#xff1a;深度优先搜索 题目解析 步骤1&#xff1a;确定每个链路上可用的处理器数量 步骤2&#xff1a;确定最佳的芯片组合策略 步骤3&#xff1a;选择合适的芯片组合 算法实现 实现一 实现二 实现三 题目描述 …

统一SQL 支持Oracle CHAR和VARCHAR2 (size BYTE|CHAR)转换

统一SQL介绍 https://www.light-pg.com/docs/LTSQL/current/index.html 源和目标 源数据库&#xff1a;Oracle 目标数据库&#xff1a;Postgresql&#xff0c;TDSQL-MySQL&#xff0c;达梦8&#xff0c;LightDB-Oracle 操作目标 在Oracle中的CHAR和VARCHAR2数据类型&…

揭开ChatGPT面纱(1):准备工作(搭建开发环境运行OpenAI Demo)

文章目录 序言&#xff1a;探索人工智能的新篇章一、搭建开发环境二、编写并运行demo1.代码2.解析3.执行结果 本博客的gitlab仓库&#xff1a;地址&#xff0c;本博客对应01文件夹。 序言&#xff1a;探索人工智能的新篇章 随着人工智能技术的飞速发展&#xff0c;ChatGPT作为…

nginx服务访问页面白色

问题描述 访问一个域名服务返回页面空白&#xff0c;非响应404。报错如下图。 排查问题 域名解析正常&#xff0c;网络通讯正常&#xff0c;绕过解析地址访问源站IP地址端口访问正常&#xff0c;nginx无异常报错。 在打开文件时&#xff0c;发现无法打开配置文件&#xff0c…

982: 输出利用二叉树存储的普通树的度

解法&#xff1a; 由题意&#xff0c;根据二叉树求对应的合法普通树的度&#xff0c;度就是节点儿子数的最大值。 也就是左孩子&#xff0b;兄弟 在二叉树中就是某根节点的右孩子某根节点的右孩子的右孩子。。。 例AB#CD##E### 关于树概念不理解的可以看看981: 统计利用二叉…

解决常见的 `npm install` 报错

解决常见的 npm install 报错 在 Node.js 项目中&#xff0c;我们经常使用 npm install 命令来安装项目所需的依赖包。然而&#xff0c;有时候在执行这个命令时会遇到一些问题和报错。本文将介绍一些常见的 npm install 报错&#xff0c;并提供相应的解决方法。 报错 1: “ER…

【WPF】取色器-Color Extractor

【WPF】取色器 序实现HookScreen Colorlayout.CS预览下载序 取色器是一个非常实用的小工具,网上也很多可供下载使用。为什么已有却还是想要自己去实现一个呢?一方面是因为工具虽小但毕竟涉及到操作系统 API 的使用。另一方面想要在技术上精进一些。 实现 实现思路测试通过 Ho…

PostgreSQL 17新特性之MERGE语句增强

PostgreSQL 15 提供了 MERGE 语句&#xff0c;它可以基于源表或者查询结果更新目标表中的数据。MERGE 可以在单个语句中实现 INSERT、UPDATE 以及 DELETE 操作。 PostgreSQL 17 进一步增强了该语句的功能&#xff0c;包括&#xff1a; 支持 RETURNING 子句&#xff0c;可以返…

牛客NC179 长度为 K 的重复字符子串【simple 哈希,滑动窗口 C++、Java、Go、PHP】

题目 题目链接&#xff1a; https://www.nowcoder.com/practice/eced9a8a4b6c42b79c95ae5625e1d5fd 思路 哈希统计每个字符出现的次数。没在窗口内的字符要删除参考答案C class Solution {public:/*** 代码中的类名、方法名、参数名已经指定&#xff0c;请勿修改&#xff0c…

java Date 月份加1

介绍 使用Date对象&#xff0c;执行月份加1操作 代码示例 import java.util.Calendar; import java.util.Date;public class Main {public static void main(String[] args) {// 获取当前日期的Calendar实例Calendar calendar Calendar.getInstance();// 设置为需要加一的日…

expdp备份报错ORA-01658

有个测试环境&#xff0c;没开归档&#xff0c;每天做一个expdp全备份&#xff0c;周末现场反馈备份失败&#xff0c;发出来的报错如下 orcl:/backup/orcldb> tail -f /tmp/orcl.log Export: Release 12.2.0.1.0 - Production on Mon Apr 21 10:58:28 2024 Copyright …

记录Python链接mysql的数据库的2种操作方式

一、使用pymysql库方式 import pymysqldb pymysql.connect(hostlocalhost,userroot,password123456) #创建链接&#xff0c;在3.8以后好像已经不支持这个种链接方式了&#xff0c; #db pymysql.connect(localhost,root,123456) cursor db.cursor()#拿到游标这样我们就拿到了…

在微信小程序部署AI模型的几种方法

前言 本文只是分享思路&#xff0c;不提供可完整运行的项目代码 onnx部署 以目标检测类模型为例&#xff0c;该类模型会输出类别信息&#xff0c;置信度&#xff0c;包含检测框的4个坐标信息 但不是所有的onnx模型都能在微信小程序部署&#xff0c;有些算子不支持&#xff…

一维递归:递去

示例&#xff1a; /*** brief how about recursive-forward-1? show you here.* author wenxuanpei* email 15873152445163.com(query for any question here)*/ #define _CRT_SECURE_NO_WARNINGS//support c-library in Microsoft-Visual-Studio #include <stdio.h>…

ctfshow 每周大挑战RCE极限挑战

讨厌SQl看到这个了想来玩玩 rce1 <?phperror_reporting(0); highlight_file(__FILE__);$code $_POST[code];$code str_replace("(","括号",$code);$code str_replace(".","点",$code);eval($code);?>括号过滤点过滤&…

c++补充

构造函数、析构函数 #include <iostream> using namespace std;// 构造函数、析构函数 // --- "构造函数"类比生活中的"出厂设置" --- // --- "析构函数"类比生活中的"销毁设置" --- // 如果我们不写这两种函数&#xff0c;编译…

在Linux系统中,如何查看当前登录的用户

在Linux系统中&#xff0c;要查看当前登录的用户&#xff0c;可以使用以下几种方法&#xff1a; who 命令&#xff1a; 这是最常用的命令之一&#xff0c;用于列出当前登录到系统的用户及其相关信息。只需在终端中输入&#xff1a; who 输出结果通常包括用户名、登录终端&am…