f7533c6a5f0bc0c1ecf368865d7d9179b8083291.svn-base 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <a-card>
  3. <draggable @end="end" :options="{animation: 300}" v-model="dataSource" style="display: inline-block">
  4. <template v-for="(data,index) in dataSource">
  5. <div style="float: left;width:150px;height:150px;margin-right: 10px;margin: 0 8px 8px 0;" :key="index">
  6. <div style="width: 100%;height: 100%;position: relative;padding: 8px;border: 1px solid #d9d9d9;border-radius: 4px;">
  7. <img style="width: 100%;" :src="data.filePath" preview="index">
  8. </div>
  9. </div>
  10. </template>
  11. <a-button @click="sureChange" type="primary" style="margin-top: 115px">确定</a-button>
  12. </draggable>
  13. <br/>
  14. <a-row>
  15. <a-col :span="12">
  16. <p>拖拽前json数据:</p>
  17. <textarea rows="25" style="width: 780px">{{ oldDateSource }}</textarea>
  18. </a-col>
  19. <a-col :span="12">
  20. <p>拖拽后json数据:</p>
  21. <textarea rows="25" style="width: 780px">{{ newDateSource }}</textarea>
  22. </a-col>
  23. </a-row>
  24. </a-card>
  25. </template>
  26. <script>
  27. import draggable from 'vuedraggable'
  28. import ARow from 'ant-design-vue/es/grid/Row'
  29. import ACol from 'ant-design-vue/es/grid/Col'
  30. export default {
  31. name: 'ImgDragSort',
  32. components:{
  33. ACol,
  34. ARow,
  35. draggable
  36. },
  37. data() {
  38. return {
  39. description: '图片拖拽排序',
  40. spinning: false,
  41. //数据集
  42. dataSource: [
  43. {id:'000',sort: 0,filePath: 'https://static.jeecg.com/upload/test/1_1588149743473.jpg'},
  44. {id:'111',sort: 1,filePath: 'https://static.jeecg.com/upload/test/u27356337152749454924fm27gp0_1588149731821.jpg'},
  45. {id:'222',sort: 2,filePath: 'https://static.jeecg.com/upload/test/u24454681402491956848fm27gp0_1588149712663.jpg'},
  46. {id:'333',sort: 3,filePath: 'https://static.jeecg.com/temp/国炬软件logo_1606575029126.png'},
  47. {id:'444',sort: 4,filePath: 'https://static.jeecg.com/upload/test/u8891206113801177793fm27gp0_1588149704459.jpg'}
  48. ],
  49. oldDateSource:[],
  50. newDateSource:[],
  51. }
  52. },
  53. created(){
  54. this.oldDateSource = this.dataSource;
  55. },
  56. methods:{
  57. end: function (evt) {
  58. console.log("拖动前的位置"+evt.oldIndex);
  59. console.log("拖动后的位置"+evt.newIndex);
  60. },
  61. sureChange(){
  62. for(var i=0;i<this.dataSource.length;i++){
  63. this.dataSource[i].sort = i;
  64. }
  65. this.newDateSource = this.dataSource;
  66. }
  67. }
  68. }
  69. </script>
  70. <style scoped>
  71. </style>