File tree Expand file tree Collapse file tree 2 files changed +48
-3
lines changed
ruoyi-fastapi-frontend/src/components Expand file tree Collapse file tree 2 files changed +48
-3
lines changed Original file line number Diff line number Diff line change 4343
4444<script >
4545import { getToken } from " @/utils/auth" ;
46+ import Sortable from ' sortablejs' ;
4647
4748export default {
4849 name: " FileUpload" ,
@@ -82,6 +83,11 @@ export default {
8283 disabled: {
8384 type: Boolean ,
8485 default: false
86+ },
87+ // 拖动排序
88+ drag: {
89+ type: Boolean ,
90+ default: true
8591 }
8692 },
8793 data () {
@@ -96,6 +102,21 @@ export default {
96102 fileList: [],
97103 };
98104 },
105+ mounted () {
106+ if (this .drag ) {
107+ this .$nextTick (() => {
108+ const element = document .querySelector (' .upload-file-list' )
109+ Sortable .create (element, {
110+ ghostClass: ' file-upload-darg' ,
111+ onEnd : (evt ) => {
112+ const movedItem = this .fileList .splice (evt .oldIndex , 1 )[0 ]
113+ this .fileList .splice (evt .newIndex , 0 , movedItem)
114+ this .$emit (" input" , this .listToString (this .fileList ))
115+ }
116+ })
117+ })
118+ }
119+ },
99120 watch: {
100121 value: {
101122 handler (val ) {
@@ -216,6 +237,10 @@ export default {
216237 </script >
217238
218239<style scoped lang="scss">
240+ .file-upload-darg {
241+ opacity : 0.5 ;
242+ background : #c8ebfb ;
243+ }
219244.upload-file-uploader {
220245 margin-bottom : 5px ;
221246}
Original file line number Diff line number Diff line change 4646<script >
4747import { getToken } from " @/utils/auth" ;
4848import { isExternal } from " @/utils/validate" ;
49+ import Sortable from ' sortablejs' ;
4950
5051export default {
5152 props: {
@@ -62,22 +63,27 @@ export default {
6263 // 图片数量限制
6364 limit: {
6465 type: Number ,
65- default: 5 ,
66+ default: 5
6667 },
6768 // 大小限制(MB)
6869 fileSize: {
6970 type: Number ,
70- default: 5 ,
71+ default: 5
7172 },
7273 // 文件类型, 例如['png', 'jpg', 'jpeg']
7374 fileType: {
7475 type: Array ,
75- default : () => [" png" , " jpg" , " jpeg" ],
76+ default : () => [" png" , " jpg" , " jpeg" ]
7677 },
7778 // 是否显示提示
7879 isShowTip: {
7980 type: Boolean ,
8081 default: true
82+ },
83+ // 拖动排序
84+ drag: {
85+ type: Boolean ,
86+ default: true
8187 }
8288 },
8389 data () {
@@ -95,6 +101,20 @@ export default {
95101 fileList: []
96102 };
97103 },
104+ mounted () {
105+ if (this .drag ) {
106+ this .$nextTick (() => {
107+ const element = document .querySelector (' .el-upload-list' )
108+ Sortable .create (element, {
109+ onEnd : (evt ) => {
110+ const movedItem = this .fileList .splice (evt .oldIndex , 1 )[0 ]
111+ this .fileList .splice (evt .newIndex , 0 , movedItem)
112+ this .$emit (" input" , this .listToString (this .fileList ))
113+ }
114+ })
115+ })
116+ }
117+ },
98118 watch: {
99119 value: {
100120 handler (val ) {
You can’t perform that action at this time.
0 commit comments