孙玉明

添加修改布局钩子,保存到网络

1 <template> 1 <template>
2 <div id="app"> 2 <div id="app">
3 <setting/> 3 <setting/>
4 - <!-- <layout/> --> 4 + <layout/>
5 </div> 5 </div>
6 </template> 6 </template>
7 7
8 <script> 8 <script>
9 import setting from "./components/setting"; 9 import setting from "./components/setting";
10 -// import layout from "./components/layout"; 10 +import layout from "./components/layout";
11 11
12 export default { 12 export default {
13 name: "app", 13 name: "app",
14 components: { 14 components: {
15 setting, 15 setting,
16 - // layout 16 + layout
17 }, 17 },
18 mounted() { 18 mounted() {
19 this.$inventory 19 this.$inventory
...@@ -34,19 +34,16 @@ export default { ...@@ -34,19 +34,16 @@ export default {
34 "layout/setDashboardId", 34 "layout/setDashboardId",
35 list.managedObjects[0].id 35 list.managedObjects[0].id
36 ); 36 );
37 + if (list.managedObjects[0].dashLayout) {
38 + this.$store.commit(
39 + "layout/updateLayout",
40 + list.managedObjects[0].dashLayout
41 + );
42 + }
37 } 43 }
38 }); 44 });
39 }, 45 },
40 - methods: { 46 + methods: {}
41 - // isLock: function(val) {
42 - // this.$store.commit("setLock", detail.id);
43 - // this.isDraggable = val.isDraggable;
44 - // this.isResizable = val.isResizable;
45 - // this.$message.success(
46 - // val.isResizable && val.isDraggable ? "编辑已解锁" : "编辑已锁定"
47 - // );
48 - // }
49 - }
50 }; 47 };
51 </script> 48 </script>
52 49
......
1 <template> 1 <template>
2 <div class="gridComponent"> 2 <div class="gridComponent">
3 <div class="setting"> 3 <div class="setting">
4 - <a-button 4 + <a-button size="small" shape="circle" icon="close" @click="close()" v-if="isLock"></a-button>
5 - size="small" 5 + <a-button size="small" shape="circle" icon="setting" v-if="isLock"></a-button>
6 - shape="circle"
7 - icon="close"
8 - @click="close"
9 - v-show="this.$store.state.layout.isDraggable&&this.$store.state.layout.isResizable"
10 - ></a-button>
11 - <a-button
12 - size="small"
13 - shape="circle"
14 - icon="setting"
15 - v-show="this.$store.state.layout.isDraggable&&this.$store.state.layout.isResizable"
16 - ></a-button>
17 </div> 6 </div>
18 <component :is="layout.name" :isConfig="isConfig"></component> 7 <component :is="layout.name" :isConfig="isConfig"></component>
19 </div> 8 </div>
...@@ -30,12 +19,15 @@ ...@@ -30,12 +19,15 @@
30 </style> 19 </style>
31 20
32 <script> 21 <script>
22 +import { mapState } from "vuex";
33 export default { 23 export default {
24 + computed: mapState({
25 + isLock: state => state.layout.isLock,
26 + isUpdate: state => state.layout.isUpdate
27 + }),
34 props: { 28 props: {
35 layout: Object, 29 layout: Object,
36 - index: Number, 30 + index: Number
37 - // isDraggable: Boolean,
38 - // isResizable: Boolean
39 }, 31 },
40 data() { 32 data() {
41 return { 33 return {
...@@ -44,7 +36,10 @@ export default { ...@@ -44,7 +36,10 @@ export default {
44 }, 36 },
45 methods: { 37 methods: {
46 close: function() { 38 close: function() {
47 - this.$emit("close", this.index); 39 + if (!this.isUpdate) {
40 + this.$store.commit("layout/setUpdate", true);
41 + }
42 + this.$store.commit("layout/removeLayout", this.index);
48 } 43 }
49 } 44 }
50 }; 45 };
......
1 <template> 1 <template>
2 <grid-layout 2 <grid-layout
3 - :layout.sync="this.$store.state.layout.layout" 3 + :layout.sync="layout"
4 :col-num="100" 4 :col-num="100"
5 :row-height="30" 5 :row-height="30"
6 - :is-draggable="this.$store.state.layout.isDraggable" 6 + :is-draggable="isLock"
7 - :is-resizable="this.$store.state.layout.isResizable" 7 + :is-resizable="isLock"
8 :is-mirrored="false" 8 :is-mirrored="false"
9 :vertical-compact="true" 9 :vertical-compact="true"
10 :margin="[0, 0]" 10 :margin="[0, 0]"
11 :use-css-transforms="true" 11 :use-css-transforms="true"
12 + @layout-updated="layoutUpdatedEvent"
12 > 13 >
13 <grid-item 14 <grid-item
14 - v-for="(item,index) in this.$store.state.layout.layout" 15 + v-for="(item,index) in layout"
15 :x="item.x" 16 :x="item.x"
16 :y="item.y" 17 :y="item.y"
17 :w="item.w" 18 :w="item.w"
...@@ -23,23 +24,43 @@ ...@@ -23,23 +24,43 @@
23 :maxH="item.maxH" 24 :maxH="item.maxH"
24 :key="item.i" 25 :key="item.i"
25 > 26 >
26 - <gridComponent :layout="item" :index="index" @close="close"/> 27 + <gridComponent :layout="item" :index="index"/>
27 </grid-item> 28 </grid-item>
28 </grid-layout> 29 </grid-layout>
29 </template> 30 </template>
30 31
31 <script> 32 <script>
33 +import { mapState } from "vuex";
32 import VueGridLayout from "vue-grid-layout"; 34 import VueGridLayout from "vue-grid-layout";
33 import gridComponent from "./gridComponent"; 35 import gridComponent from "./gridComponent";
34 export default { 36 export default {
37 + computed: mapState({
38 + layout: state => state.layout.layout,
39 + isLock: state => state.layout.isLock,
40 + isUpdate: state => state.layout.isUpdate
41 + }),
35 components: { 42 components: {
36 GridLayout: VueGridLayout.GridLayout, 43 GridLayout: VueGridLayout.GridLayout,
37 GridItem: VueGridLayout.GridItem, 44 GridItem: VueGridLayout.GridItem,
38 gridComponent 45 gridComponent
39 }, 46 },
40 - methods:{ 47 + methods: {
41 - close:function(val){ 48 + layoutUpdatedEvent: function(newLayout) {
42 - // this.layout.splice(val,1) 49 + let updateLayout;
50 + updateLayout = Array.from(newLayout, item => {
51 + return {
52 + x: item.x,
53 + y: item.y,
54 + w: item.w,
55 + h: item.h,
56 + i: item.i,
57 + name: item.name
58 + };
59 + });
60 + this.$store.commit("layout/updateLayout", updateLayout);
61 + if (!this.isUpdate) {
62 + this.$store.commit("layout/setUpdate", true);
63 + }
43 } 64 }
44 } 65 }
45 }; 66 };
......
1 <template> 1 <template>
2 <div class="setting"> 2 <div class="setting">
3 - <a-button size="small" shape="circle" icon="plus" @click="() => visible = true" v-show="isLock"></a-button> 3 + <a-button size="small" shape="circle" icon="save" @click="save()" v-if="isLock&&isUpdate"></a-button>
4 + <a-button size="small" shape="circle" icon="plus" @click="() => visible = true" v-if="isLock"></a-button>
4 <a-button size="small" shape="circle" :icon="isLock?'unlock':'lock'" @click="setLock()"></a-button> 5 <a-button size="small" shape="circle" :icon="isLock?'unlock':'lock'" @click="setLock()"></a-button>
5 <a-modal 6 <a-modal
6 title="添加小部件" 7 title="添加小部件"
7 centered 8 centered
8 v-model="visible" 9 v-model="visible"
9 @ok="add" 10 @ok="add"
11 + @cancel="cancel"
10 :destroyOnClose="true" 12 :destroyOnClose="true"
11 :maskClosable="false" 13 :maskClosable="false"
12 :okButtonProps="{ props: {disabled: selectItem===null?true:false} }" 14 :okButtonProps="{ props: {disabled: selectItem===null?true:false} }"
...@@ -29,7 +31,12 @@ ...@@ -29,7 +31,12 @@
29 <script> 31 <script>
30 import { mapState } from "vuex"; 32 import { mapState } from "vuex";
31 export default { 33 export default {
32 - computed: mapState({ isLock: state => state.layout.isLock }), 34 + computed: mapState({
35 + isLock: state => state.layout.isLock,
36 + isUpdate: state => state.layout.isUpdate,
37 + dashboardId: state => state.layout.dashboardId,
38 + layout: state => state.layout.layout
39 + }),
33 data() { 40 data() {
34 return { 41 return {
35 visible: false, 42 visible: false,
...@@ -59,8 +66,24 @@ export default { ...@@ -59,8 +66,24 @@ export default {
59 } 66 }
60 }, 67 },
61 add: function() { 68 add: function() {
62 - this.$store.commit("layout/setLatout", this.selectItem); 69 + if (!this.isUpdate) {
70 + this.$store.commit("layout/setUpdate", true);
71 + }
72 + this.$store.commit("layout/addLayout", this.selectItem);
63 this.visible = false; 73 this.visible = false;
74 + this.selectItem = null;
75 + this.configSelect = null;
76 + },
77 + cancel: function() {
78 + this.selectItem = null;
79 + this.configSelect = null;
80 + },
81 + save: function() {
82 + this.$store.commit("layout/setUpdate", false);
83 + this.$inventory.update({
84 + id: this.dashboardId,
85 + dashLayout: this.layout
86 + });
64 } 87 }
65 } 88 }
66 }; 89 };
......
...@@ -2,6 +2,7 @@ const state = { ...@@ -2,6 +2,7 @@ const state = {
2 layout: [], 2 layout: [],
3 isLock: true, 3 isLock: true,
4 dashboardId: null, 4 dashboardId: null,
5 + isUpdate: false,
5 }; 6 };
6 7
7 const mutations = { 8 const mutations = {
...@@ -11,16 +12,25 @@ const mutations = { ...@@ -11,16 +12,25 @@ const mutations = {
11 setLock(state, value) { 12 setLock(state, value) {
12 state.isLock = value; 13 state.isLock = value;
13 }, 14 },
14 - setLatout(state, name) { 15 + setUpdate(state, value) {
16 + state.isUpdate = value;
17 + },
18 + addLayout(state, name) {
15 state.layout.push({ 19 state.layout.push({
16 - x: 0, 20 + x: 0,
17 - y: 0, 21 + y: 0,
18 - w: 10, 22 + w: 10,
19 - h: 2, 23 + h: 2,
20 - i: state.layout.length + 1, 24 + i: state.layout.length + 1,
21 - name 25 + name,
22 }); 26 });
23 }, 27 },
28 + updateLayout(state, array) {
29 + state.layout = array;
30 + },
31 + removeLayout(state, index) {
32 + state.layout.splice(index, 1);
33 + },
24 }; 34 };
25 35
26 export default { 36 export default {
......