index.vue 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div class="dndList">
  3. <div class="dndList-list" :style="{width:width1}">
  4. <h3>{{list1Title}}</h3>
  5. <draggable :list="list1" class="dragArea" :options="{group:'article'}">
  6. <div class="list-complete-item" v-for="element in list1" :key='element.id'>
  7. <div class="list-complete-item-handle">[{{element.author}}] {{element.title}}</div>
  8. <div style="position:absolute;right:0px;">
  9. <span style="float: right ;margin-top: -20px;margin-right:5px;" @click="deleteEle(element)">
  10. <i style="color:#ff4949" class="el-icon-delete"></i>
  11. </span>
  12. </div>
  13. </div>
  14. </draggable>
  15. </div>
  16. <div class="dndList-list" :style="{width:width2}">
  17. <h3>{{list2Title}}</h3>
  18. <draggable :list="filterList2" class="dragArea" :options="{group:'article'}">
  19. <div class="list-complete-item" v-for="element in filterList2" :key='element.id'>
  20. <div class='list-complete-item-handle2' @click="pushEle(element)"> [{{element.author}}] {{element.title}}</div>
  21. </div>
  22. </draggable>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. import draggable from 'vuedraggable'
  28. export default {
  29. name: 'DndList',
  30. components: { draggable },
  31. computed: {
  32. filterList2() {
  33. return this.list2.filter(v => {
  34. if (this.isNotInList1(v)) {
  35. return v
  36. }
  37. return false
  38. })
  39. }
  40. },
  41. props: {
  42. list1: {
  43. type: Array,
  44. default() {
  45. return []
  46. }
  47. },
  48. list2: {
  49. type: Array,
  50. default() {
  51. return []
  52. }
  53. },
  54. list1Title: {
  55. type: String,
  56. default: 'list1'
  57. },
  58. list2Title: {
  59. type: String,
  60. default: 'list2'
  61. },
  62. width1: {
  63. type: String,
  64. default: '48%'
  65. },
  66. width2: {
  67. type: String,
  68. default: '48%'
  69. }
  70. },
  71. methods: {
  72. isNotInList1(v) {
  73. return this.list1.every(k => v.id !== k.id)
  74. },
  75. isNotInList2(v) {
  76. return this.list2.every(k => v.id !== k.id)
  77. },
  78. deleteEle(ele) {
  79. for (const item of this.list1) {
  80. if (item.id === ele.id) {
  81. const index = this.list1.indexOf(item)
  82. this.list1.splice(index, 1)
  83. break
  84. }
  85. }
  86. if (this.isNotInList2(ele)) {
  87. this.list2.unshift(ele)
  88. }
  89. },
  90. pushEle(ele) {
  91. this.list1.push(ele)
  92. }
  93. }
  94. }
  95. </script>
  96. <style rel="stylesheet/scss" lang="scss" scoped>
  97. .dndList {
  98. background: #fff;
  99. padding-bottom: 40px;
  100. &:after {
  101. content: "";
  102. display: table;
  103. clear: both;
  104. }
  105. .dndList-list {
  106. float: left;
  107. padding-bottom: 30px;
  108. &:first-of-type {
  109. margin-right: 2%;
  110. }
  111. .dragArea {
  112. margin-top: 15px;
  113. min-height: 50px;
  114. padding-bottom: 30px;
  115. }
  116. }
  117. }
  118. .list-complete-item {
  119. cursor: pointer;
  120. position: relative;
  121. font-size: 14px;
  122. padding: 5px 12px;
  123. margin-top: 4px;
  124. border: 1px solid #bfcbd9;
  125. transition: all 1s;
  126. }
  127. .list-complete-item-handle {
  128. overflow: hidden;
  129. text-overflow: ellipsis;
  130. white-space: nowrap;
  131. margin-right: 50px;
  132. }
  133. .list-complete-item-handle2 {
  134. overflow: hidden;
  135. text-overflow: ellipsis;
  136. white-space: nowrap;
  137. margin-right: 20px;
  138. }
  139. .list-complete-item.sortable-chosen {
  140. background: #4AB7BD;
  141. }
  142. .list-complete-item.sortable-ghost {
  143. background: #30B08F;
  144. }
  145. .list-complete-enter,
  146. .list-complete-leave-active {
  147. opacity: 0;
  148. }
  149. </style>