Example07PreventCollision.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div>
  3. <grid-layout :layout.sync="layout"
  4. :col-num="12"
  5. :row-height="30"
  6. :is-draggable="draggable"
  7. :is-resizable="resizable"
  8. :responsive="false"
  9. :vertical-compact="false"
  10. :prevent-collision="true"
  11. :use-css-transforms="true"
  12. >
  13. <grid-item v-for="item in layout"
  14. :static="item.static"
  15. :x="item.x"
  16. :y="item.y"
  17. :w="item.w"
  18. :h="item.h"
  19. :i="item.i"
  20. >
  21. <span class="text">{{item.i}}</span>
  22. </grid-item>
  23. </grid-layout>
  24. </div>
  25. </template>
  26. <script>
  27. import { GridLayout, GridItem } from "vue-grid-layout"
  28. export default {
  29. components: {
  30. GridLayout,
  31. GridItem
  32. },
  33. data() {
  34. return {
  35. layout: [
  36. {"x":0,"y":0,"w":2,"h":2,"i":"0", static: false},
  37. {"x":2,"y":0,"w":2,"h":4,"i":"1", static: true},
  38. {"x":4,"y":0,"w":2,"h":5,"i":"2", static: false},
  39. {"x":6,"y":0,"w":2,"h":3,"i":"3", static: false},
  40. {"x":8,"y":0,"w":2,"h":3,"i":"4", static: false},
  41. {"x":10,"y":0,"w":2,"h":3,"i":"5", static: false},
  42. {"x":0,"y":5,"w":2,"h":5,"i":"6", static: false},
  43. {"x":2,"y":5,"w":2,"h":5,"i":"7", static: false},
  44. {"x":4,"y":5,"w":2,"h":5,"i":"8", static: false},
  45. {"x":6,"y":3,"w":2,"h":4,"i":"9", static: true},
  46. {"x":8,"y":4,"w":2,"h":4,"i":"10", static: false},
  47. {"x":10,"y":4,"w":2,"h":4,"i":"11", static: false},
  48. {"x":0,"y":10,"w":2,"h":5,"i":"12", static: false},
  49. {"x":2,"y":10,"w":2,"h":5,"i":"13", static: false},
  50. {"x":4,"y":8,"w":2,"h":4,"i":"14", static: false},
  51. {"x":6,"y":8,"w":2,"h":4,"i":"15", static: false},
  52. {"x":8,"y":10,"w":2,"h":5,"i":"16", static: false},
  53. {"x":10,"y":4,"w":2,"h":2,"i":"17", static: false},
  54. {"x":0,"y":9,"w":2,"h":3,"i":"18", static: false},
  55. {"x":2,"y":6,"w":2,"h":2,"i":"19", static: false}
  56. ],
  57. draggable: true,
  58. resizable: true,
  59. }
  60. },
  61. methods: {
  62. }
  63. }
  64. </script>
  65. <style scoped>
  66. .vue-grid-layout {
  67. background: #eee;
  68. }
  69. .vue-grid-item:not(.vue-grid-placeholder) {
  70. background: #ccc;
  71. border: 1px solid black;
  72. }
  73. .vue-grid-item .resizing {
  74. opacity: 0.9;
  75. }
  76. .vue-grid-item .static {
  77. background: #cce;
  78. }
  79. .vue-grid-item .text {
  80. font-size: 24px;
  81. text-align: center;
  82. position: absolute;
  83. top: 0;
  84. bottom: 0;
  85. left: 0;
  86. right: 0;
  87. margin: auto;
  88. height: 100%;
  89. width: 100%;
  90. }
  91. .vue-grid-item .no-drag {
  92. height: 100%;
  93. width: 100%;
  94. }
  95. .vue-grid-item .minMax {
  96. font-size: 12px;
  97. }
  98. .vue-grid-item .add {
  99. cursor: pointer;
  100. }
  101. .vue-draggable-handle {
  102. position: absolute;
  103. width: 20px;
  104. height: 20px;
  105. top: 0;
  106. left: 0;
  107. background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><circle cx='5' cy='5' r='5' fill='#999999'/></svg>") no-repeat;
  108. background-position: bottom right;
  109. padding: 0 8px 8px 0;
  110. background-repeat: no-repeat;
  111. background-origin: content-box;
  112. box-sizing: border-box;
  113. cursor: pointer;
  114. }
  115. </style>