waibao

完成vuex转换

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
...@@ -27,7 +27,7 @@ export default { ...@@ -27,7 +27,7 @@ export default {
27 "dashboard!name!home": {} 27 "dashboard!name!home": {}
28 }) 28 })
29 .then(detail => { 29 .then(detail => {
30 - this.$store.commit("setDashboardId", detail.id); 30 + this.$store.commit("layout/setDashboardId", detail.id);
31 }); 31 });
32 } else { 32 } else {
33 this.$store.commit( 33 this.$store.commit(
...@@ -36,16 +36,6 @@ export default { ...@@ -36,16 +36,6 @@ export default {
36 ); 36 );
37 } 37 }
38 }); 38 });
39 - },
40 - 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 } 39 }
50 }; 40 };
51 </script> 41 </script>
......
...@@ -5,15 +5,10 @@ ...@@ -5,15 +5,10 @@
5 size="small" 5 size="small"
6 shape="circle" 6 shape="circle"
7 icon="close" 7 icon="close"
8 - @click="close" 8 + @click="close(index)"
9 - v-show="this.$store.state.layout.isDraggable&&this.$store.state.layout.isResizable" 9 + v-show="this.$store.state.layout.isLock"
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> 10 ></a-button>
11 + <a-button size="small" shape="circle" icon="setting" v-show="this.$store.state.layout.isLock"></a-button>
17 </div> 12 </div>
18 <component :is="layout.name" :isConfig="isConfig"></component> 13 <component :is="layout.name" :isConfig="isConfig"></component>
19 </div> 14 </div>
...@@ -30,12 +25,12 @@ ...@@ -30,12 +25,12 @@
30 </style> 25 </style>
31 26
32 <script> 27 <script>
28 +import { mapMutations } from "vuex";
29 +
33 export default { 30 export default {
34 props: { 31 props: {
35 layout: Object, 32 layout: Object,
36 - index: Number, 33 + index: Number
37 - // isDraggable: Boolean,
38 - // isResizable: Boolean
39 }, 34 },
40 data() { 35 data() {
41 return { 36 return {
...@@ -43,9 +38,9 @@ export default { ...@@ -43,9 +38,9 @@ export default {
43 }; 38 };
44 }, 39 },
45 methods: { 40 methods: {
46 - close: function() { 41 + ...mapMutations({
47 - this.$emit("close", this.index); 42 + close: "layout/delLayout"
48 - } 43 + })
49 } 44 }
50 }; 45 };
51 </script> 46 </script>
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
3 :layout.sync="this.$store.state.layout.layout" 3 :layout.sync="this.$store.state.layout.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="this.$store.state.layout.isLock"
7 - :is-resizable="this.$store.state.layout.isResizable" 7 + :is-resizable="this.$store.state.layout.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]"
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
23 :maxH="item.maxH" 23 :maxH="item.maxH"
24 :key="item.i" 24 :key="item.i"
25 > 25 >
26 - <gridComponent :layout="item" :index="index" @close="close"/> 26 + <gridComponent :layout="item" :index="index"/>
27 </grid-item> 27 </grid-item>
28 </grid-layout> 28 </grid-layout>
29 </template> 29 </template>
...@@ -36,11 +36,6 @@ export default { ...@@ -36,11 +36,6 @@ export default {
36 GridLayout: VueGridLayout.GridLayout, 36 GridLayout: VueGridLayout.GridLayout,
37 GridItem: VueGridLayout.GridItem, 37 GridItem: VueGridLayout.GridItem,
38 gridComponent 38 gridComponent
39 - },
40 - methods:{
41 - close:function(val){
42 - // this.layout.splice(val,1)
43 - }
44 } 39 }
45 }; 40 };
46 </script> 41 </script>
......
...@@ -5,19 +5,20 @@ ...@@ -5,19 +5,20 @@
5 shape="circle" 5 shape="circle"
6 icon="plus" 6 icon="plus"
7 @click="() => visible = true" 7 @click="() => visible = true"
8 - v-show="this.$store.state.layout.isDraggable&&this.$store.state.layout.isResizable" 8 + v-show="this.$store.state.layout.isLock"
9 ></a-button> 9 ></a-button>
10 <a-button 10 <a-button
11 size="small" 11 size="small"
12 shape="circle" 12 shape="circle"
13 icon="lock" 13 icon="lock"
14 - @click="isLock(!this.$store.state.layout.isDraggable)" 14 + @click="isLock"
15 ></a-button> 15 ></a-button>
16 <a-modal 16 <a-modal
17 title="添加小部件" 17 title="添加小部件"
18 centered 18 centered
19 v-model="visible" 19 v-model="visible"
20 @ok="add" 20 @ok="add"
21 + @cancel="cancel"
21 :destroyOnClose="true" 22 :destroyOnClose="true"
22 :maskClosable="false" 23 :maskClosable="false"
23 :okButtonProps="{ props: {disabled: selectItem===null?true:false} }" 24 :okButtonProps="{ props: {disabled: selectItem===null?true:false} }"
...@@ -48,7 +49,6 @@ ...@@ -48,7 +49,6 @@
48 49
49 50
50 <script> 51 <script>
51 -import { mapMutations } from "vuex";
52 export default { 52 export default {
53 data() { 53 data() {
54 return { 54 return {
...@@ -59,9 +59,6 @@ export default { ...@@ -59,9 +59,6 @@ export default {
59 }; 59 };
60 }, 60 },
61 methods: { 61 methods: {
62 - ...mapMutations({
63 - isLock: "setLock"
64 - }),
65 filterOption(input, option) { 62 filterOption(input, option) {
66 return ( 63 return (
67 option.componentOptions.children[0].text 64 option.componentOptions.children[0].text
...@@ -78,8 +75,20 @@ export default { ...@@ -78,8 +75,20 @@ export default {
78 } 75 }
79 }, 76 },
80 add: function() { 77 add: function() {
81 - this.$store.commit("setLatout", this.selectItem); 78 + this.$store.commit("layout/addLayout", this.selectItem);
82 this.visible = false; 79 this.visible = false;
80 + this.selectItem = null;
81 + this.configSelect = null;
82 + },
83 + cancel: function() {
84 + this.selectItem = null;
85 + this.configSelect = null;
86 + },
87 + isLock: function() {
88 + this.$store.commit("layout/setLock", !this.$store.state.layout.isLock);
89 + this.$message.success(
90 + this.$store.state.layout.isLock ? "编辑已解锁" : "编辑已锁定"
91 + );
83 } 92 }
84 } 93 }
85 }; 94 };
......
1 const state = { 1 const state = {
2 layout: [], 2 layout: [],
3 - isDraggable: true, 3 + isLock: true,
4 - isResizable: true, 4 + dashboardId: null
5 - dashboardId: null,
6 }; 5 };
7 6
8 const mutations = { 7 const mutations = {
...@@ -10,23 +9,25 @@ const mutations = { ...@@ -10,23 +9,25 @@ const mutations = {
10 state.dashboardId = id; 9 state.dashboardId = id;
11 }, 10 },
12 setLock(state, value) { 11 setLock(state, value) {
13 - state.isDraggable = value; 12 + state.isLock = value;
14 - state.isResizable = value;
15 }, 13 },
16 - setLatout(state, name) { 14 + addLayout(state, name) {
17 state.layout.push({ 15 state.layout.push({
18 - x: 0, 16 + x: 0,
19 - y: 0, 17 + y: 0,
20 - w: 10, 18 + w: 10,
21 - h: 2, 19 + h: 2,
22 - i: state.layout.length + 1, 20 + i: state.layout.length + 1,
23 - name 21 + name
24 }); 22 });
25 }, 23 },
24 + delLayout(state, index) {
25 + state.layout.splice(index, 1);
26 + }
26 }; 27 };
27 28
28 export default { 29 export default {
29 namespaced: true, 30 namespaced: true,
30 state, 31 state,
31 - mutations, 32 + mutations
32 }; 33 };
......
...@@ -11,11 +11,7 @@ ...@@ -11,11 +11,7 @@
11 </style> 11 </style>
12 12
13 <script> 13 <script>
14 -import config from "./config";
15 export default { 14 export default {
16 name: "index1", 15 name: "index1",
17 - components: {
18 - config
19 - }
20 }; 16 };
21 </script> 17 </script>
......