|
| 1 | +<template> |
| 2 | + <div id="app"> |
| 3 | + <h1>Vue Grid Layout</h1> |
| 4 | + <!--<pre>{{ layout | json }}</pre>--> |
| 5 | + <div> |
| 6 | + <div class="layoutJSON"> |
| 7 | + Displayed as <code>[x, y, w, h]</code>: |
| 8 | + <div class="columns"> |
| 9 | + <div class="layoutItem" v-for="item in layout"> |
| 10 | + <b>{{item.i}}</b>: [{{item.x}}, {{item.y}}, {{item.w}}, {{item.h}}] |
| 11 | + </div> |
| 12 | + </div> |
| 13 | + </div> |
| 14 | + <div class="layoutJSON"> |
| 15 | + Displayed as <code>[x, y, w, h]</code>: |
| 16 | + <div class="columns"> |
| 17 | + <div class="layoutItem" v-for="item in layout2"> |
| 18 | + <b>{{item.i}}</b>: [{{item.x}}, {{item.y}}, {{item.w}}, {{item.h}}] |
| 19 | + </div> |
| 20 | + </div> |
| 21 | + </div> |
| 22 | + </div> |
| 23 | + <div id="content"> |
| 24 | + <button @click="decreaseWidth">Decrease Width</button> |
| 25 | + <button @click="increaseWidth">Increase Width</button> |
| 26 | + <button @click="addItem">Add an item</button> |
| 27 | + <!-- Add to show rtl support --> |
| 28 | + <button @click="changeDirection">Change Direction</button> |
| 29 | + <input type="checkbox" v-model="draggable"/> Draggable |
| 30 | + <input type="checkbox" v-model="resizable"/> Resizable |
| 31 | + <input type="checkbox" v-model="mirrored"/> Mirrored |
| 32 | + <br/> |
| 33 | + Row Height: <input type="number" v-model="rowHeight"/> Col nums: <input type="number" v-model="colNum"/> |
| 34 | + <br/> |
| 35 | + <grid-layout |
| 36 | + :layout="layout" |
| 37 | + :col-num="parseInt(colNum)" |
| 38 | + :row-height="rowHeight" |
| 39 | + :is-draggable="draggable" |
| 40 | + :is-resizable="resizable" |
| 41 | + :is-mirrored="mirrored" |
| 42 | + :vertical-compact="true" |
| 43 | + :use-css-transforms="true" |
| 44 | + > |
| 45 | + <grid-item v-for="item in layout" :key="item.i" |
| 46 | + :x="item.x" |
| 47 | + :y="item.y" |
| 48 | + :w="item.w" |
| 49 | + :h="item.h" |
| 50 | + :i="item.i" |
| 51 | + @resize="resize" |
| 52 | + @move="move" |
| 53 | + @resized="resized" |
| 54 | + @moved="moved" |
| 55 | + > |
| 56 | + <!--<custom-drag-element :text="item.i"></custom-drag-element>--> |
| 57 | + <test-element :text="item.i"></test-element> |
| 58 | + <!--<button @click="clicked">CLICK ME!</button>--> |
| 59 | + </grid-item> |
| 60 | + </grid-layout> |
| 61 | + <hr/> |
| 62 | + <!--<grid-layout |
| 63 | + :layout="layout2" |
| 64 | + :col-num="12" |
| 65 | + :row-height="rowHeight" |
| 66 | + :is-draggable="draggable" |
| 67 | + :is-resizable="resizable" |
| 68 | + :vertical-compact="true" |
| 69 | + :use-css-transforms="true" |
| 70 | + > |
| 71 | + <grid-item v-for="item in layout2" :key="item.i" |
| 72 | + :x="item.x" |
| 73 | + :y="item.y" |
| 74 | + :w="item.w" |
| 75 | + :h="item.h" |
| 76 | + :min-w="2" |
| 77 | + :min-h="2" |
| 78 | + :i="item.i" |
| 79 | + :is-draggable="item.draggable" |
| 80 | + :is-resizable="item.resizable" |
| 81 | + > |
| 82 | + <test-element :text="item.i"></test-element> |
| 83 | + </grid-item> |
| 84 | + </grid-layout>--> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | +</template> |
| 88 | + |
| 89 | +<script> |
| 90 | + import GridItem from './GridItem.vue'; |
| 91 | + import GridLayout from './GridLayout.vue'; |
| 92 | + //import ResponsiveGridLayout from './ResponsiveGridLayout.vue'; |
| 93 | + import TestElement from './TestElement.vue'; |
| 94 | + import CustomDragElement from './CustomDragElement.vue'; |
| 95 | + import {getDocumentDir, setDocumentDir} from "./DOM"; |
| 96 | + //var eventBus = require('./eventBus'); |
| 97 | +
|
| 98 | + let testLayout = [ |
| 99 | + {"x":0,"y":0,"w":2,"h":2,"i":"0", resizable: true, draggable: true}, |
| 100 | + {"x":2,"y":0,"w":2,"h":4,"i":"1", resizable: null, draggable: null}, |
| 101 | + {"x":4,"y":0,"w":2,"h":5,"i":"2", resizable: false, draggable: false}, |
| 102 | + {"x":6,"y":0,"w":2,"h":3,"i":"3", resizable: false, draggable: false}, |
| 103 | + {"x":8,"y":0,"w":2,"h":3,"i":"4", resizable: false, draggable: false}, |
| 104 | + {"x":10,"y":0,"w":2,"h":3,"i":"5", resizable: false, draggable: false}, |
| 105 | + {"x":0,"y":5,"w":2,"h":5,"i":"6", resizable: false, draggable: false}, |
| 106 | + {"x":2,"y":5,"w":2,"h":5,"i":"7", resizable: false, draggable: false}, |
| 107 | + {"x":4,"y":5,"w":2,"h":5,"i":"8", resizable: false, draggable: false}, |
| 108 | + {"x":6,"y":4,"w":2,"h":4,"i":"9", resizable: false, draggable: false}, |
| 109 | + {"x":8,"y":4,"w":2,"h":4,"i":"10", resizable: false, draggable: false}, |
| 110 | + {"x":10,"y":4,"w":2,"h":4,"i":"11", resizable: false, draggable: false}, |
| 111 | + {"x":0,"y":10,"w":2,"h":5,"i":"12", resizable: false, draggable: false}, |
| 112 | + {"x":2,"y":10,"w":2,"h":5,"i":"13", resizable: false, draggable: false}, |
| 113 | + {"x":4,"y":8,"w":2,"h":4,"i":"14", resizable: false, draggable: false}, |
| 114 | + {"x":6,"y":8,"w":2,"h":4,"i":"15", resizable: false, draggable: false}, |
| 115 | + {"x":8,"y":10,"w":2,"h":5,"i":"16", resizable: false, draggable: false}, |
| 116 | + {"x":10,"y":4,"w":2,"h":2,"i":"17", resizable: false, draggable: false}, |
| 117 | + {"x":0,"y":9,"w":2,"h":3,"i":"18", resizable: false, draggable: false}, |
| 118 | + {"x":2,"y":6,"w":2,"h":2,"i":"19", resizable: false, draggable: false} |
| 119 | + ]; |
| 120 | +
|
| 121 | + export default { |
| 122 | + name: 'app', |
| 123 | + components: { |
| 124 | + //ResponsiveGridLayout, |
| 125 | + GridLayout, |
| 126 | + GridItem, |
| 127 | + TestElement, |
| 128 | + CustomDragElement, |
| 129 | + }, |
| 130 | + data () { |
| 131 | + return { |
| 132 | + layout: JSON.parse(JSON.stringify(testLayout)), |
| 133 | + layout2: JSON.parse(JSON.stringify(testLayout)), |
| 134 | + draggable: true, |
| 135 | + resizable: true, |
| 136 | + mirrored: false, |
| 137 | + rowHeight: 30, |
| 138 | + colNum: 12, |
| 139 | + index: 0 |
| 140 | + } |
| 141 | + }, |
| 142 | + mounted: function () { |
| 143 | + this.index = this.layout.length; |
| 144 | + }, |
| 145 | + methods: { |
| 146 | + clicked: function() { |
| 147 | + window.alert("CLICK!"); |
| 148 | + }, |
| 149 | + increaseWidth: function(item) { |
| 150 | + var width = document.getElementById("content").offsetWidth; |
| 151 | + width += 20; |
| 152 | + document.getElementById("content").style.width = width+"px"; |
| 153 | + }, |
| 154 | + decreaseWidth: function(item) { |
| 155 | +
|
| 156 | + var width = document.getElementById("content").offsetWidth; |
| 157 | + width -= 20; |
| 158 | + document.getElementById("content").style.width = width+"px"; |
| 159 | + }, |
| 160 | + removeItem: function(item) { |
| 161 | + //console.log("### REMOVE " + item.i); |
| 162 | + this.layout.splice(this.layout.indexOf(item), 1); |
| 163 | + }, |
| 164 | + addItem: function() { |
| 165 | + let self = this; |
| 166 | + //console.log("### LENGTH: " + this.layout.length); |
| 167 | + let item = {"x":0,"y":0,"w":2,"h":2,"i":this.index+"", whatever: "bbb"}; |
| 168 | + this.index++; |
| 169 | + this.layout.push(item); |
| 170 | + }, |
| 171 | + move: function(i, newX, newY){ |
| 172 | + // console.log("MOVE i=" + i + ", X=" + newX + ", Y=" + newY); |
| 173 | + }, |
| 174 | + resize: function(i, newH, newW, newHPx, newWPx){ |
| 175 | + console.log("RESIZE i=" + i + ", H=" + newH + ", W=" + newW + ", H(px)=" + newHPx + ", W(px)=" + newWPx); |
| 176 | + }, |
| 177 | + moved: function(i, newX, newY){ |
| 178 | + console.log("### MOVED i=" + i + ", X=" + newX + ", Y=" + newY); |
| 179 | + }, |
| 180 | + resized: function(i, newH, newW, newHPx, newWPx){ |
| 181 | + console.log("### RESIZED i=" + i + ", H=" + newH + ", W=" + newW + ", H(px)=" + newHPx + ", W(px)=" + newWPx); |
| 182 | + }, |
| 183 | + /** |
| 184 | + * Add change direction button |
| 185 | + */ |
| 186 | + changeDirection() { |
| 187 | + let documentDirection = getDocumentDir(); |
| 188 | + let toggle = ""; |
| 189 | + if (documentDirection === "rtl") { |
| 190 | + toggle = "ltr" |
| 191 | + } else { |
| 192 | + toggle = "rtl" |
| 193 | + } |
| 194 | + setDocumentDir(toggle); |
| 195 | + //eventBus.$emit('directionchange'); |
| 196 | + } |
| 197 | + }, |
| 198 | + } |
| 199 | +</script> |
| 200 | + |
| 201 | +<style> |
| 202 | +/* #app { |
| 203 | + font-family: 'Avenir', Helvetica, Arial, sans-serif; |
| 204 | + -webkit-font-smoothing: antialiased; |
| 205 | + -moz-osx-font-smoothing: grayscale; |
| 206 | + text-align: center; |
| 207 | + color: #2c3e50; |
| 208 | + margin-top: 60px; |
| 209 | + } |
| 210 | +
|
| 211 | + h1, h2 { |
| 212 | + font-weight: normal; |
| 213 | + } |
| 214 | +
|
| 215 | + ul { |
| 216 | + list-style-type: none; |
| 217 | + padding: 0; |
| 218 | + } |
| 219 | +
|
| 220 | + li { |
| 221 | + display: inline-block; |
| 222 | + margin: 0 10px; |
| 223 | + } |
| 224 | +
|
| 225 | + a { |
| 226 | + color: #42b983; |
| 227 | + }*/ |
| 228 | +</style> |
0 commit comments