孙玉明

添加新建时支持输入宽高,修复model关闭报错bug

...@@ -2,13 +2,17 @@ ...@@ -2,13 +2,17 @@
2 <a-modal 2 <a-modal
3 title="添加小部件" 3 title="添加小部件"
4 centered 4 centered
5 - v-model="this.visible" 5 + :visible="this.visible"
6 @ok="add" 6 @ok="add"
7 @cancel="cancel" 7 @cancel="cancel"
8 :destroyOnClose="true" 8 :destroyOnClose="true"
9 :maskClosable="false" 9 :maskClosable="false"
10 + :afterClose="afterClose"
10 :okButtonProps="{ props: {disabled: selectItem===null?true:false} }" 11 :okButtonProps="{ props: {disabled: selectItem===null?true:false} }"
11 > 12 >
13 + 宽度:
14 + <a-input-number :min="1" :max="100" v-model="width" />高度:
15 + <a-input-number :min="1" v-model="height" />选择小部件:
12 <a-select 16 <a-select
13 showSearch 17 showSearch
14 placeholder="搜索小部件" 18 placeholder="搜索小部件"
...@@ -32,7 +36,9 @@ export default { ...@@ -32,7 +36,9 @@ export default {
32 return { 36 return {
33 list: window.componentList, 37 list: window.componentList,
34 selectItem: null, 38 selectItem: null,
35 - configSelect: null 39 + configSelect: null,
40 + width: 10,
41 + height: 1
36 }; 42 };
37 }, 43 },
38 methods: { 44 methods: {
...@@ -51,19 +57,26 @@ export default { ...@@ -51,19 +57,26 @@ export default {
51 this.configSelect = value; 57 this.configSelect = value;
52 } 58 }
53 }, 59 },
60 + afterClose: function() {
61 + this.selectItem = null;
62 + this.configSelect = null;
63 + this.width = 10;
64 + this.height = 1;
65 + },
54 add: function() { 66 add: function() {
55 if (!this.isUpdate) { 67 if (!this.isUpdate) {
56 this.$store.commit("layout/setUpdate", true); 68 this.$store.commit("layout/setUpdate", true);
57 } 69 }
58 - this.$store.commit("layout/addLayout", this.selectItem); 70 + this.$store.commit("layout/addLayout", {
59 - this.selectItem = null; 71 + name: this.selectItem,
60 - this.configSelect = null; 72 + width: this.width,
61 - this.$emit('closeAddGrid'); 73 + height: this.height
74 + });
75 +
76 + this.$emit("closeAddGrid");
62 }, 77 },
63 cancel: function() { 78 cancel: function() {
64 - this.selectItem = null; 79 + this.$emit("closeAddGrid");
65 - this.configSelect = null;
66 - this.$emit('closeAddGrid');
67 } 80 }
68 } 81 }
69 }; 82 };
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
8 @click="() => visible = true" 8 @click="() => visible = true"
9 v-if="isLock" 9 v-if="isLock"
10 ></a-button> 10 ></a-button>
11 - <a-button size="small" shape="circle" :icon="isLock?'unlock':'lock'" @click="setLock()"></a-button> 11 + <a-button size="small" shape="circle" :icon="isLock?'unlock':'lock'" @click="setLock"></a-button>
12 - <add-grid :visible="visible" @closeAddGrid="setVisible()"/> 12 + <add-grid :visible="visible" @closeAddGrid="setVisible"/>
13 </div> 13 </div>
14 </template> 14 </template>
15 15
......
1 -import Vue from 'vue'; 1 +import Vue from "vue";
2 -import App from './App.vue'; 2 +import App from "./App.vue";
3 -import store from './store'; 3 +import store from "./store";
4 -import './autoImport'; 4 +import "./autoImport";
5 -import { Modal, Button, Select, message } from 'ant-design-vue'; 5 +import { Modal, Button, Select, message, InputNumber } from "ant-design-vue";
6 -import { inventory } from './api'; 6 +import { inventory } from "./api";
7 7
8 Vue.config.productionTip = false; 8 Vue.config.productionTip = false;
9 Vue.use(Modal); 9 Vue.use(Modal);
10 Vue.use(Button); 10 Vue.use(Button);
11 Vue.use(Select); 11 Vue.use(Select);
12 +Vue.use(InputNumber);
12 13
13 Vue.prototype.$message = message; 14 Vue.prototype.$message = message;
14 Vue.prototype.$inventory = inventory; 15 Vue.prototype.$inventory = inventory;
15 16
16 new Vue({ 17 new Vue({
17 - el: '#app', 18 + el: "#app",
18 store, 19 store,
19 - render: (h) => h(App), 20 + render: h => h(App)
20 }); 21 });
......
...@@ -2,7 +2,7 @@ const state = { ...@@ -2,7 +2,7 @@ const state = {
2 layout: [], 2 layout: [],
3 isLock: true, 3 isLock: true,
4 dashboardId: null, 4 dashboardId: null,
5 - isUpdate: false, 5 + isUpdate: false
6 }; 6 };
7 7
8 const mutations = { 8 const mutations = {
...@@ -15,14 +15,14 @@ const mutations = { ...@@ -15,14 +15,14 @@ const mutations = {
15 setUpdate(state, value) { 15 setUpdate(state, value) {
16 state.isUpdate = value; 16 state.isUpdate = value;
17 }, 17 },
18 - addLayout(state, name) { 18 + addLayout(state, obj) {
19 state.layout.push({ 19 state.layout.push({
20 x: 0, 20 x: 0,
21 y: 0, 21 y: 0,
22 - w: 10, 22 + w: obj.width,
23 - h: 2, 23 + h: obj.height,
24 i: state.layout.length + 1, 24 i: state.layout.length + 1,
25 - name, 25 + name: obj.name
26 }); 26 });
27 }, 27 },
28 updateLayout(state, array) { 28 updateLayout(state, array) {
...@@ -30,7 +30,7 @@ const mutations = { ...@@ -30,7 +30,7 @@ const mutations = {
30 }, 30 },
31 removeLayout(state, index) { 31 removeLayout(state, index) {
32 state.layout.splice(index, 1); 32 state.layout.splice(index, 1);
33 - }, 33 + }
34 }; 34 };
35 35
36 export default { 36 export default {
......