Example04AllowIgnore.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div>
  3. <grid-layout :layout.sync="layout"
  4. :col-num="12"
  5. :row-height="30"
  6. :is-draggable="true"
  7. :is-resizable="true"
  8. :vertical-compact="true"
  9. :use-css-transforms="true"
  10. >
  11. <grid-item v-for="item in layout"
  12. :x="item.x"
  13. :y="item.y"
  14. :w="item.w"
  15. :h="item.h"
  16. :i="item.i"
  17. drag-allow-from=".vue-draggable-handle"
  18. drag-ignore-from=".no-drag"
  19. >
  20. <div class="text">
  21. <div class="vue-draggable-handle"></div>
  22. <div class="no-drag">
  23. <span>{{item.i}}</span>
  24. <br/>
  25. <button>click</button>
  26. </div>
  27. </div>
  28. </grid-item>
  29. </grid-layout>
  30. </div>
  31. </template>
  32. <script>
  33. import { GridLayout, GridItem } from "vue-grid-layout"
  34. export default {
  35. components: {
  36. GridLayout,
  37. GridItem
  38. },
  39. data() {
  40. return {
  41. layout: [
  42. {"x":0,"y":0,"w":2,"h":2,"i":"0"},
  43. {"x":2,"y":0,"w":2,"h":4,"i":"1"},
  44. {"x":4,"y":0,"w":2,"h":5,"i":"2"},
  45. {"x":6,"y":0,"w":2,"h":3,"i":"3"},
  46. {"x":8,"y":0,"w":2,"h":3,"i":"4"},
  47. {"x":10,"y":0,"w":2,"h":3,"i":"5"},
  48. {"x":0,"y":5,"w":2,"h":5,"i":"6"},
  49. {"x":2,"y":5,"w":2,"h":5,"i":"7"},
  50. {"x":4,"y":5,"w":2,"h":5,"i":"8"},
  51. {"x":6,"y":4,"w":2,"h":4,"i":"9"},
  52. {"x":8,"y":4,"w":2,"h":4,"i":"10"},
  53. {"x":10,"y":4,"w":2,"h":4,"i":"11"},
  54. {"x":0,"y":10,"w":2,"h":5,"i":"12"},
  55. {"x":2,"y":10,"w":2,"h":5,"i":"13"},
  56. {"x":4,"y":8,"w":2,"h":4,"i":"14"},
  57. {"x":6,"y":8,"w":2,"h":4,"i":"15"},
  58. {"x":8,"y":10,"w":2,"h":5,"i":"16"},
  59. {"x":10,"y":4,"w":2,"h":2,"i":"17"},
  60. {"x":0,"y":9,"w":2,"h":3,"i":"18"},
  61. {"x":2,"y":6,"w":2,"h":2,"i":"19"}
  62. ],
  63. draggable: true,
  64. resizable: true,
  65. index: 0,
  66. eventLog: []
  67. }
  68. },
  69. watch: {
  70. eventLog: function() {
  71. const eventsDiv = this.$refs.eventsDiv;
  72. eventsDiv.scrollTop = eventsDiv.scrollHeight;
  73. }
  74. },
  75. methods: {
  76. moveEvent: function(i, newX, newY){
  77. const msg = "MOVE i=" + i + ", X=" + newX + ", Y=" + newY;
  78. this.eventLog.push(msg);
  79. console.log(msg);
  80. },
  81. movedEvent: function(i, newX, newY){
  82. const msg = "MOVED i=" + i + ", X=" + newX + ", Y=" + newY;
  83. this.eventLog.push(msg);
  84. console.log(msg);
  85. },
  86. resizeEvent: function(i, newH, newW, newHPx, newWPx){
  87. const msg = "RESIZE i=" + i + ", H=" + newH + ", W=" + newW + ", H(px)=" + newHPx + ", W(px)=" + newWPx;
  88. this.eventLog.push(msg);
  89. console.log(msg);
  90. },
  91. resizedEvent: function(i, newX, newY, newHPx, newWPx){
  92. const msg = "RESIZED i=" + i + ", X=" + newX + ", Y=" + newY + ", H(px)=" + newHPx + ", W(px)=" + newWPx;
  93. this.eventLog.push(msg);
  94. console.log(msg);
  95. },
  96. containerResizedEvent: function(i, newH, newW, newHPx, newWPx){
  97. const msg = "CONTAINER RESIZED i=" + i + ", H=" + newH + ", W=" + newW + ", H(px)=" + newHPx + ", W(px)=" + newWPx;
  98. this.eventLog.push(msg);
  99. console.log(msg);
  100. },
  101. layoutCreatedEvent: function(newLayout){
  102. this.eventLog.push("Created layout");
  103. console.log("Created layout: ", newLayout)
  104. },
  105. layoutBeforeMountEvent: function(newLayout){
  106. this.eventLog.push("beforeMount layout");
  107. console.log("beforeMount layout: ", newLayout)
  108. },
  109. layoutMountedEvent: function(newLayout){
  110. this.eventLog.push("Mounted layout");
  111. console.log("Mounted layout: ", newLayout)
  112. },
  113. layoutReadyEvent: function(newLayout){
  114. this.eventLog.push("Ready layout");
  115. console.log("Ready layout: ", newLayout)
  116. },
  117. layoutUpdatedEvent: function(newLayout){
  118. this.eventLog.push("Updated layout");
  119. console.log("Updated layout: ", newLayout)
  120. },
  121. }
  122. }
  123. </script>
  124. <style scoped>
  125. .vue-grid-layout {
  126. background: #eee;
  127. }
  128. .vue-grid-item:not(.vue-grid-placeholder) {
  129. background: #ccc;
  130. border: 1px solid black;
  131. }
  132. .vue-grid-item .resizing {
  133. opacity: 0.9;
  134. }
  135. .vue-grid-item .static {
  136. background: #cce;
  137. }
  138. .vue-grid-item .text {
  139. font-size: 24px;
  140. text-align: center;
  141. position: absolute;
  142. top: 0;
  143. bottom: 0;
  144. left: 0;
  145. right: 0;
  146. margin: auto;
  147. height: 100%;
  148. width: 100%;
  149. }
  150. .vue-grid-item .no-drag {
  151. height: 100%;
  152. width: 100%;
  153. }
  154. .vue-grid-item .minMax {
  155. font-size: 12px;
  156. }
  157. .vue-grid-item .add {
  158. cursor: pointer;
  159. }
  160. .vue-draggable-handle {
  161. position: absolute;
  162. width: 20px;
  163. height: 20px;
  164. top: 0;
  165. right: 0;
  166. padding: 0 8px 8px 0;
  167. background-origin: content-box;
  168. background-color: black;
  169. box-sizing: border-box;
  170. border-radius: 10px;
  171. cursor: pointer;
  172. }
  173. .layoutJSON {
  174. background: #ddd;
  175. border: 1px solid black;
  176. margin-top: 10px;
  177. padding: 10px;
  178. }
  179. .eventsJSON {
  180. background: #ddd;
  181. border: 1px solid black;
  182. margin-top: 10px;
  183. padding: 10px;
  184. height: 100px;
  185. overflow-y: scroll;
  186. }
  187. </style>