Переглянути джерело

上传组件新增拖动排序属性

RuoYi 11 місяців тому
батько
коміт
98738f23ad

+ 26 - 1
ruoyi-ui/src/components/FileUpload/index.vue

@@ -43,6 +43,7 @@
43 43
 
44 44
 <script>
45 45
 import { getToken } from "@/utils/auth"
46
+import Sortable from 'sortablejs'
46 47
 
47 48
 export default {
48 49
   name: "FileUpload",
@@ -82,6 +83,11 @@ export default {
82 83
     disabled: {
83 84
       type: Boolean,
84 85
       default: false
86
+    },
87
+      // 拖动排序
88
+    drag: {
89
+      type: Boolean,
90
+      default: true
85 91
     }
86 92
   },
87 93
   data() {
@@ -92,7 +98,22 @@ export default {
92 98
       headers: {
93 99
         Authorization: "Bearer " + getToken(),
94 100
       },
95
-      fileList: [],
101
+      fileList: []
102
+    }
103
+  },
104
+  mounted() {
105
+    if (this.drag) {
106
+      this.$nextTick(() => {
107
+        const element = document.querySelector('.upload-file-list')
108
+        Sortable.create(element, {
109
+          ghostClass: 'file-upload-darg',
110
+          onEnd: (evt) => {
111
+            const movedItem = this.fileList.splice(evt.oldIndex, 1)[0]
112
+            this.fileList.splice(evt.newIndex, 0, movedItem)
113
+            this.$emit("input", this.listToString(this.fileList))
114
+          }
115
+        })
116
+      })
96 117
     }
97 118
   },
98 119
   watch: {
@@ -215,6 +236,10 @@ export default {
215 236
 </script>
216 237
 
217 238
 <style scoped lang="scss">
239
+.file-upload-darg {
240
+  opacity: 0.5;
241
+  background: #c8ebfb;
242
+}
218 243
 .upload-file-uploader {
219 244
   margin-bottom: 5px;
220 245
 }

+ 23 - 3
ruoyi-ui/src/components/ImageUpload/index.vue

@@ -45,6 +45,7 @@
45 45
 
46 46
 <script>
47 47
 import { getToken } from "@/utils/auth"
48
+import Sortable from 'sortablejs'
48 49
 
49 50
 export default {
50 51
   props: {
@@ -61,22 +62,27 @@ export default {
61 62
     // 图片数量限制
62 63
     limit: {
63 64
       type: Number,
64
-      default: 5,
65
+      default: 5
65 66
     },
66 67
     // 大小限制(MB)
67 68
     fileSize: {
68 69
        type: Number,
69
-      default: 5,
70
+      default: 5
70 71
     },
71 72
     // 文件类型, 例如['png', 'jpg', 'jpeg']
72 73
     fileType: {
73 74
       type: Array,
74
-      default: () => ["png", "jpg", "jpeg"],
75
+      default: () => ["png", "jpg", "jpeg"]
75 76
     },
76 77
     // 是否显示提示
77 78
     isShowTip: {
78 79
       type: Boolean,
79 80
       default: true
81
+    },
82
+      // 拖动排序
83
+    drag: {
84
+      type: Boolean,
85
+      default: true
80 86
     }
81 87
   },
82 88
   data() {
@@ -93,6 +99,20 @@ export default {
93 99
       fileList: []
94 100
     }
95 101
   },
102
+  mounted() {
103
+    if (this.drag) {
104
+      this.$nextTick(() => {
105
+        const element = document.querySelector('.el-upload-list')
106
+        Sortable.create(element, {
107
+          onEnd: (evt) => {
108
+            const movedItem = this.fileList.splice(evt.oldIndex, 1)[0]
109
+            this.fileList.splice(evt.newIndex, 0, movedItem)
110
+            this.$emit("input", this.listToString(this.fileList))
111
+          }
112
+        })
113
+      })
114
+    }
115
+  },
96 116
   watch: {
97 117
     value: {
98 118
       handler(val) {