layout.vue
1.45 KB
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
<template>
<grid-layout
:layout.sync="layout"
:col-num="100"
:row-height="30"
:is-draggable="isLock"
:is-resizable="isLock"
:is-mirrored="false"
:vertical-compact="true"
:margin="[0, 0]"
:use-css-transforms="true"
@layout-updated="layoutUpdatedEvent"
>
<grid-item
v-for="(item,index) in layout"
:x="item.x"
:y="item.y"
:w="item.w"
:h="item.h"
:i="item.i"
:minW="item.minW"
:maxW="item.maxW"
:minH="item.minH"
:maxH="item.maxH"
:key="item.i"
>
<grid-component :layout="item" :index="index"/>
</grid-item>
</grid-layout>
</template>
<script>
import { mapState } from "vuex";
import VueGridLayout from "vue-grid-layout";
import GridComponent from "./GridComponent";
export default {
computed: { ...mapState("layout", ["layout", "isLock", "isUpdate"]) },
components: {
GridLayout: VueGridLayout.GridLayout,
GridItem: VueGridLayout.GridItem,
GridComponent
},
methods: {
layoutUpdatedEvent: function(newLayout) {
let updateLayout;
updateLayout = Array.from(newLayout, item => {
return {
x: item.x,
y: item.y,
w: item.w,
h: item.h,
i: item.i,
name: item.name
};
});
this.$store.commit("layout/updateLayout", updateLayout);
if (!this.isUpdate) {
this.$store.commit("layout/setUpdate", true);
}
}
}
};
</script>