/
App.vue
137 lines (126 loc) · 3.59 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<template>
<div id="app">
<VueResponsiveGridLayout
:style="{border: '1px solid #000'}"
@layout-update="onLayoutUpdate"
@layout-change="onLayoutChange"
@layout-init="onLayoutInit"
@width-change="onWidthChange"
@breakpoint-change="onBreakpointChange"
:layouts="layouts"
:compactType="'vertical'"
:breakpoint="breakpoint"
:cols="cols"
ref="layout"
>
<template slot-scope="props">
<VueGridItem v-for="item in props.layout"
:i="item.i"
:key="item.i"
:w.sync="item.w"
:h.sync="item.h"
:x="item.x"
:y="item.y"
:containerWidth="props.containerWidth"
:rowHeight="props.rowHeight"
:isDraggable="true"
:isResizable="true"
:className="'grid-item'"
:cols="props.cols"
:heightFromChildren="false"
:maxRows="props.maxRows"
>
<div>Test</div>
</VueGridItem>
</template>
</VueResponsiveGridLayout>
</div>
</template>
<script lang="ts">
import {Component, Vue} from 'vue-property-decorator';
import VueResponsiveGridLayout from './components/VueResponsiveGridLayout.vue';
import VueGridItem from './components/VueGridItem.vue';
import ComponentItem from './components/ComponentItem.vue';
import {namespace} from 'vuex-class';
import {Breakpoint, ResponsiveLayout} from './lib/responsiveUtils';
import {Layout} from './lib/utils';
const layoutModule = namespace('layout');
@Component({
name: 'app',
components: {
VueResponsiveGridLayout,
VueGridItem,
ComponentItem,
},
})
export default class App extends Vue {
@layoutModule.State('layouts') public layouts;
@layoutModule.State('breakpoint') public breakpoint;
@layoutModule.State('cols') public cols;
@layoutModule.Action('updateLayout') public updateLayout;
@layoutModule.Action('updateBreakpoint') public updateBreakpoint;
@layoutModule.Action('updateCols') public updateCols;
public onLayoutUpdate(layout: Layout, layouts: ResponsiveLayout, last) {
this.updateLayout({layout, breakpoint: this.breakpoint});
}
public onLayoutChange(layout: Layout, layouts: ResponsiveLayout, breakpoint: Breakpoint) {
this.updateLayout({layout, breakpoint});
}
public onLayoutInit(layout, currentLayouts, cols, breakpoint) {
this.updateCols({cols});
this.updateBreakpoint({breakpoint});
this.updateLayout({layout, breakpoint});
}
public onBreakpointChange(breakpoint: Breakpoint) {
this.updateBreakpoint({breakpoint});
}
public onWidthChange(width: number, cols: number) {
this.updateCols({cols});
}
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
width: 100%;
height: 100%;
}
.resizable-handle {
position:absolute;
width:20px;
height:20px;
bottom:0;
right:0px;
text-align:right;
}
.resizable-handle::after {
content: "";
position: absolute;
right: 3px;
bottom: 3px;
width: 5px;
height: 5px;
border-right: 2px solid #000000;
border-bottom: 2px solid #000000;
}
.vue-grid-draggable-container {
width: 100%;
height: 100%;
}
.grid-item {
border: 1px dotted #000;
}
.vue-grid-placeholder {
background: #ddd; border: 2px dashed #aaa;
}
.vue-grid-layout {
width: 100%;
display:block;
position:relative;
height: 100%;
}
</style>