Example02Events.vue 6.6 KB

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