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 list
	delay: 0, // time in milliseconds to define when the sorting should start
	delayOnTouchOnly: false, // only delay if user is using touch
	touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event
	disabled: false, // Disables the sortable if set to true.
	store: null,  // @see Store
	animation: 150,  // ms, animation speed moving items when sorting, `0` — without animation
	easing: "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 items
	filter: ".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 draggable

	dataIdAttr: 'data-id', // HTML attribute that is used by the `toArray()` method

	ghostClass: "sortable-ghost",  // Class name for the drop placeholder
	chosenClass: "sortable-chosen",  // Class name for the chosen item
	dragClass: "sortable-drag",  // Class name for the dragging item

	swapThreshold: 1, // Threshold of the swap zone
	invertSwap: false, // Will always use inverted swap zone if set to true
	invertedSwapThreshold: 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 in

	fallbackClass: "sortable-fallback",  // Class name for the cloned DOM Element when using forceFallback
	fallbackOnBody: false,  // Appends the cloned DOM Element into the Document's Body
	fallbackTolerance: 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 it
	emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it


	setData: function (/** DataTransfer */dataTransfer, /** HTMLElement*/dragEl) {
		dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
	},

	// Element is chosen
	onChoose: function (/**Event*/evt) {
		evt.oldIndex;  // element index within parent
	},

	// Element is unchosen
	onUnchoose: function(/**Event*/evt) {
		// same properties as onEnd
	},

	// Element dragging started
	onStart: function (/**Event*/evt) {
		evt.oldIndex;  // element index within parent
	},

	// Element dragging ended
	onEnd: function (/**Event*/evt) {
		var itemEl = evt.item;  // dragged HTMLElement
		evt.to;    // target list
		evt.from;  // previous list
		evt.oldIndex;  // element's old index within old parent
		evt.newIndex;  // element's new index within new parent
		evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
		evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
		evt.clone // the clone element
		evt.pullMode;  // when item is in another sortable: `"clone"` if cloning, `true` if moving
	},

	// Element is dropped into the list from another list
	onAdd: function (/**Event*/evt) {
		// same properties as onEnd
	},

	// Changed sorting within list
	onUpdate: 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 list
	onRemove: function (/**Event*/evt) {
		// same properties as onEnd
	},

	// Attempt to drag a filtered element
	onFilter: function (/**Event*/evt) {
		var itemEl = evt.item;  // HTMLElement receiving the `mousedown|tapstart` event.
	},

	// Event when you move an item in the list or between lists
	onMove: function (/**Event*/evt, /**Event*/originalEvent) {
		// Example: https://jsbin.com/nawahef/edit?js,output
		evt.dragged; // dragged HTMLElement
		evt.draggedRect; // DOMRect {left, top, right, bottom}
		evt.related; // HTMLElement on which have guided
		evt.relatedRect; // DOMRect
		evt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by default
		originalEvent.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 element
	onClone: function (/**Event*/evt) {
		var origEl = evt.item;
		var cloneEl = evt.clone;
	},

	// Called when dragging element changes position
	onChange: 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-upload
      multiple
      :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 ended
	onEnd: function (/**Event*/evt) {
		var itemEl = evt.item;  // dragged HTMLElement
		evt.to;    // target list
		evt.from;  // previous list
		evt.oldIndex;  // element's old index within old parent
		evt.newIndex;  // element's new index within new parent
		evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
		evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
		evt.clone // the clone element
		evt.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);
           
           //获取新list
           this.fileList = changelist;
           //将list转化成string
           this.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.mfbz.cn/a/560022.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【大模型系列】大模型评价指标总结

文章目录 1 图生文 (Image-to-Text)1.1 BLEU&#xff1a;基于准确率&#xff0c;得分越高越好1.2 METEOR&#xff1a;基于准确率和召回率&#xff0c;得分越高越好1.3 ROUGE&#xff1a;得分越高越好1.4 CIDEr&#xff1a;得分越高越好1.5 SPICE&#xff1a;得分越高越好1.6 Hu…

【云计算】云数据中心网络(五):对等连接

《云网络》系列&#xff0c;共包含以下文章&#xff1a; 云网络是未来的网络基础设施云网络产品体系概述云数据中心网络&#xff08;一&#xff09;&#xff1a;VPC云数据中心网络&#xff08;二&#xff09;&#xff1a;弹性公网 IP云数据中心网络&#xff08;三&#xff09;…

OpenHarmony网络通信-socket-io

简介 socket.io是一个在客户端和服务器之间实现低延迟、双向和基于事件的通信的库。建立在 WebSocket 协议之上&#xff0c;并提供额外的保证&#xff0c;例如回退到 HTTP 长轮询或自动重新连接。 效果展示 下载安装 ohpm install ohos/socketio OpenHarmony ohpm 环境配置等更…

原始部落版本潮玩宇宙小程序定制大逃杀游戏APP开发H5游戏

原始部落版本潮玩宇宙小程序定制大逃杀游戏APP开发H5游戏 潮玩宇宙小程序定制大逃杀游戏APP开发H5游戏 潮玩宇宙大逃杀小游戏模块成品源码&#xff0c;可嵌入任何平台系统&#xff0c;增加用户粘性&#xff0c;消除泡沫&#xff0c;短视频直播引流。 玩家选择一间房间躲避杀手…

Vue3+Spring Boot3实现跨域通信解决办法

Vue3Spring Boot3实现跨域通信解决办法 1 跨域是什么&#xff1f;2 何为同源呢?3 解决办法3.1 全局配置3.1.1 实现CorsFilter过滤器3.1.2 实现SpringMVC配置类3.1.3 创建CorsFilterFactory工厂类返回CorsFilter对象 3.2 局部跨域3.2.1 注解配置3.2.2 手动设置响应头(局部跨域)…

Python | Leetcode Python题解之第37题解数独

题目&#xff1a; 题解&#xff1a; class Solution:def solveSudoku(self, board: List[List[str]]) -> None:def dfs(pos: int):nonlocal validif pos len(spaces):valid Truereturni, j spaces[pos]for digit in range(9):if line[i][digit] column[j][digit] bloc…

类和对象【二】this指针,构造函数和成员初始化列表【超详细】

文章目录 this指针this指针的定义this指针的“工作”原理this指针的作用this指针的特点 构造函数构造函数的定义构造函数的作用构造函数的特点构造函数的调用方式括号法无参构造或者全缺省构造需要传参才能调用的构造函数 隐式类型转换法是只传一个参数就能调用的构造函数是要传…

发泡机液压站比例阀放大器

发泡机液压站是提供动力和压力以驱动发泡机工作的系统。 发泡机是一种用于制备聚氨酯发泡材料的设备&#xff0c;而液压站则扮演着为发泡机提供必要动力的角色。具体来看&#xff0c;液压站的主要组成包括&#xff1a; 液压油箱&#xff1a;存储液压油&#xff0c;为系统提供液…

11.接口自动化测试-Allure报告(2)

目录 1.如何同时执行多个测试文件2.Allure的不同层级应用Allure报告&#xff1a; 1.如何同时执行多个测试文件 &#xff08;1&#xff09;新建bat文件 &#xff08;2&#xff09;写命令 cd ./testCase pytest -s --alluredir ./report --clean-alluredir allure serve ./repo…

Unity之圆环slider

一、参考文章 Unity_圆环滑动条&#xff08;圆形、弧形滑动条&#xff09;_unity弧形滑动条-CSDN博客 此滑动条拖动超过360后继续往前滑动值会从0开始&#xff0c;正常我们超过360度时不可在滑动。 二、 超过360度不可滑动问题解决 参考HTML文章制作&#xff1a; https://www.c…

Java后端-文件上传大小限制解决

spring版本 2.5.4 报错如下&#xff1a;The field multipartFile exceeds its maximum permitted size of 1048576 bytes. 我上传的文件大小为2.5MB&#xff0c;如下图 原因&#xff1a;springboot默认的上传单个文件大小为1MB&#xff0c;而一次请求最大为10MB。 解决方案…

DFS专题:电话号码的字母组合

DFS专题&#xff1a;电话号码的字母组合 题目链接: 17.电话号码的字母组合 参考题解&#xff1a; 代码随想录 题目描述 代码思路 将数字到字母的映射用字符串数组表示出来。然后利用回溯算法&#xff0c;解决n个for循环的问题&#xff0c;枚举出每一种符合要求的情况。 代…

【Java探索之旅】用面向对象的思维构建程序世界

&#x1f3a5; 屿小夏 &#xff1a; 个人主页 &#x1f525;个人专栏 &#xff1a; Java编程秘籍 &#x1f304; 莫道桑榆晚&#xff0c;为霞尚满天&#xff01; 文章目录 &#x1f4d1;前言一、初识面向对象1.1 什么是面向对象&#xff1f;1.2 面向对象与面向过程 二、类的定义…

中颖51芯片学习7. ADC模数转换

中颖51芯片学习7. ADC模数转换 一、ADC工作原理简介1. 概念2. ADC实现方式3. 基准电压 二、中颖芯片ADC功能介绍1. 中颖芯片ADC特性2. ADC触发源&#xff08;1&#xff09;**软件触发**&#xff08;2&#xff09;**TIMER4定时器触发**&#xff08;3&#xff09;**外部中断2触发…

LLM推理加速,如何解决资源限制与效率挑战

©作者|Zane 来源|神州问学 LLM加速推理&#xff0c;GPU资源破局之道。 引言 大型语言模型&#xff08;LLM&#xff09;已经在多种领域得到应用&#xff0c;其重要性不言而喻。然而&#xff0c;随着这些模型变得越来越普遍&#xff0c;对GPU资源的需求也随之激增&#xff…

Github Actions实现CI/CD(golang项目)

Github Actions构建CI/CD&#xff08;golang项目&#xff09; 1 基础概念 1.1 Actions GitHub Actions允许构建一个完整的 CI/CD Pipeline&#xff0c;与 GitHub 生态系统深度集成&#xff0c;而无需使用 Travis CI 或者 Circle CI 等第三方服务&#xff0c;对于开源项目都是…

在IDEA中解决SSM项目修改图片不能回显问题

1.问题描述 图片成功上传之后&#xff0c;件夹中已经显示图片了&#xff0c;但是访问图片资源会出现404错误&#xff0c;再重新启动服务器之后&#xff0c;发现这个错误又消失了&#xff0c;图片又能正常显示&#xff0c;但是必须重启Tomcat才有效。 2.解决方法如下&#xff…

一键生成数据库文档,从此告别人工整理文档

背景 在我们日常开发过程中&#xff0c;常常遇到项目需要出一个数据库文档&#xff0c;面对数据表众多的场景一个一个写显然不现实&#xff0c;于是 screw工具很好的满足了我们的需求&#xff0c;从此告别人工整理文档; screw工具它可以将整个数据库的表输出为数据库表结构文档…

【Linux】服务器时区 [ CST | UTC | GMT | RTC ]

目录 1. 硬件时间&#xff08;Real_TIME Clock [RTC time]&#xff09; 1.1 硬件时间简介 1.2 如何使用硬件时间 2. 系统时间&#xff08;UTC时间&#xff09;&#xff08;Universal time&#xff09; 2.1 系统时间简介 2.2 UTC时间 3. 本地时间&#xff08;Local time&…

淘宝/天猫获取sku详细信息 API,item_sku-获取sku详细信息

淘宝/天猫获取sku详细信息 API,item_sku-获取sku详细信息 示例&#xff1a; {"seller_rate": true,"timeout_action_time": "2000-01-01 00:00:00","iid": "152e442aefe88dd41cb0879232c0dcb0","num": 10,"…
最新文章