styleThree.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <div class="contentShow">
  3. <div
  4. class="overflowHidden list_border mr10"
  5. :class="thisUpper == index + 1 && !!thisItems ? `moveHover ${item.className}` : item.className"
  6. @dragleave="dragleave($event, index + 1)"
  7. @dragover="dragover($event, index + 1)"
  8. @drop="drop($event, index + 1)"
  9. v-for="(item, index) in latticeArr"
  10. :key="index"
  11. >
  12. <component :is="componentsIdArr[pageLoction[index + 1]]"></component>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. import comp from '@views/newWorkBench/components/index.js';
  18. export default {
  19. mixins: [comp],
  20. data() {
  21. return {
  22. thisUpper: null,
  23. thisItems: null,
  24. pageLoction: {},
  25. latticeArr: [
  26. {
  27. className: 'list_1-1'
  28. },
  29. {
  30. className: 'list_2-2_3-2'
  31. },
  32. {
  33. className: 'list_1-4'
  34. },
  35. {
  36. className: 'list_2-1'
  37. },
  38. {
  39. className: 'list_2-4'
  40. },
  41. {
  42. className: 'list_3-1'
  43. },
  44. {
  45. className: 'list_3-2'
  46. },
  47. {
  48. className: 'list_3-3'
  49. },
  50. {
  51. className: 'list_3-4'
  52. }
  53. ]
  54. };
  55. },
  56. created() {
  57. if (!!this.$parent.oldValue.positionInfo) {
  58. this.pageLoction =
  59. typeof this.$parent.oldValue.positionInfo == 'object'
  60. ? this.$parent.oldValue.positionInfo
  61. : JSON.parse(this.$parent.oldValue.positionInfo).model == 3
  62. ? JSON.parse(this.$parent.oldValue.positionInfo).pageLoction
  63. : {};
  64. }
  65. },
  66. mounted() {},
  67. computed: {},
  68. methods: {
  69. dragleave(e, index) {
  70. //当拖拽离开这个div时执行的事件
  71. this.thisItems = null;
  72. },
  73. dragover(e, index) {
  74. this.thisUpper = index;
  75. this.thisItems = index;
  76. //拖拽在这个div里面拖拽时执行的事件
  77. //一定要执行preventDefault(),否则drop事件不会被触发
  78. e.preventDefault();
  79. },
  80. drop(e, index) {
  81. //在div里拖拽停止时执行的事件
  82. let itemValue = this.$store.getters['getDragItem'];
  83. for (let k in this.pageLoction) {
  84. if (this.pageLoction[k] == itemValue.data_id) {
  85. this.pageLoction[k] = null;
  86. }
  87. }
  88. this.pageLoction[this.thisUpper] = itemValue.data_id;
  89. this.thisItems = null;
  90. this._watcher.run();
  91. }
  92. }
  93. };
  94. </script>
  95. <style scoped lang="scss">
  96. @import './style.scss';
  97. .contentShow {
  98. border: 1px solid $BackColor;
  99. width: calc(100% - 194px);
  100. border-radius: 4px;
  101. padding: rem(10);
  102. display: grid;
  103. grid-template-columns: 2fr 2fr 2fr 2fr;
  104. grid-template-rows: 1fr 1fr 1fr;
  105. gap: 0px;
  106. height: 100%;
  107. .list_1-1 {
  108. grid-area: 1 / 1 / 1 / 1;
  109. }
  110. .list_2-2_3-2 {
  111. grid-area: 2 span/ 2 / 3 / span 2;
  112. }
  113. .list_1-4 {
  114. grid-area: 1 / 4 / 1 / 4;
  115. }
  116. .list_2-1 {
  117. grid-area: 2 / 1 / 2 / 1;
  118. }
  119. .list_2-4 {
  120. grid-area: 2 / 4 / 2 / 4;
  121. }
  122. .list_3-1 {
  123. grid-area: 3 / 1 / 3 / 1;
  124. }
  125. .list_3-2 {
  126. grid-area: 3 / 2 / 3 / 2;
  127. }
  128. .list_3-3 {
  129. grid-area: 3 / 3 / 3 / 3;
  130. }
  131. .list_3-4 {
  132. grid-area: 3 / 4 / 3 / 4;
  133. }
  134. }
  135. </style>