BoardContent.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div class="BI-board-content">
  3. <div class="BI-board-list">
  4. <table-no-data v-if="value.length===0" style="flex:1"/>
  5. <div
  6. class="BI-board-item-box"
  7. v-for="(item, index) in value"
  8. :key="item.BiDashboardDetailId"
  9. @dragover.prevent
  10. @drop="drop(index)"
  11. >
  12. <component :is="getCompType(item.Type)" :compData="item">
  13. <template v-slot:drag>
  14. <!-- Draggable icon -->
  15. <img
  16. v-if="canDrag"
  17. class="icon"
  18. src="~@/assets/img/data_m/move_ico.png"
  19. alt=""
  20. @mousedown="setDraggable(true, index)"
  21. @dragstart="dragStart(index)"
  22. @dragend="setDraggable(false, index)"
  23. style="cursor: move"
  24. />
  25. </template>
  26. <template v-slot:delete>
  27. <img class="icon" v-if="canDelete" src="~@/assets/img/icons/delete-red.png" alt="" @click="handleDel(index)"/>
  28. </template>
  29. </component>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import TableNoData from '../../../components/tableNoData.vue';
  36. import ChartBox from './ChartBox.vue';
  37. import TableBox from './TableBox.vue';
  38. export default {
  39. components: { ChartBox, TableBox, TableNoData },
  40. props: {
  41. value: {
  42. type: Array,
  43. default: () => []
  44. },
  45. canDrag: {//能否拖动
  46. type: Boolean,
  47. default: true
  48. },
  49. canDelete:{//能否删除
  50. type: Boolean,
  51. default: false
  52. }
  53. },
  54. data() {
  55. return {
  56. draggedIndex: null,
  57. };
  58. },
  59. methods: {
  60. getCompType(type) {
  61. return type === 1 ? ChartBox : TableBox;
  62. },
  63. handleDel(index){
  64. this.value.splice(index,1)
  65. this.$emit('delete',this.value)
  66. },
  67. setDraggable(draggable, index) {
  68. const box = this.$el.querySelectorAll('.BI-board-item-box')[index];
  69. box.draggable = draggable;
  70. },
  71. dragStart(index) {
  72. this.draggedIndex = index;
  73. },
  74. drop(index) {
  75. if (this.draggedIndex === null) return
  76. // Swap the two items
  77. const temp = this.value[this.draggedIndex];
  78. this.$set(this.value, this.draggedIndex, this.value[index]);
  79. this.$set(this.value, index, temp);
  80. this.draggedIndex = null;
  81. this.$emit('input',this.value)
  82. this.$emit('change',this.value)
  83. },
  84. }
  85. };
  86. </script>
  87. <style lang="scss" scoped>
  88. .BI-board-content {
  89. padding: 20px;
  90. .BI-board-list {
  91. height: calc(100vh - 300px);
  92. overflow-y: auto;
  93. display: flex;
  94. flex-wrap: wrap;
  95. gap: 20px;
  96. .BI-board-item-box {
  97. width: calc(50% - 14px);
  98. height: 560px;
  99. border: 1px solid #dcdfe6;
  100. box-shadow: 0px 2px 8px 0px #00000014;
  101. }
  102. }
  103. }
  104. </style>