setting.vue
1.97 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
64
65
66
67
68
69
70
71
72
73
74
75
76
<template>
<div class="setting">
<a-button size="small" shape="circle" icon="plus" @click="() => visible = true" v-show="isLock"></a-button>
<a-button size="small" shape="circle" :icon="isLock?'unlock':'lock'" @click="setLock()"></a-button>
<a-modal
title="添加小部件"
centered
v-model="visible"
@ok="add"
:destroyOnClose="true"
:maskClosable="false"
:okButtonProps="{ props: {disabled: selectItem===null?true:false} }"
>
<a-select
showSearch
placeholder="搜索小部件"
optionFilterProp="children"
style="width: 100%"
:filterOption="filterOption"
@change="handleChange"
>
<a-select-option v-for="item in list" :key="item" :value="item">{{item}}</a-select-option>
</a-select>
<component :is="configSelect"></component>
</a-modal>
</div>
</template>
<script>
import { mapState } from "vuex";
export default {
computed: mapState({ isLock: state => state.layout.isLock }),
data() {
return {
visible: false,
list: window.componentList,
selectItem: null,
configSelect: null
};
},
methods: {
setLock() {
this.$store.commit("layout/setLock", !this.isLock);
this.$message.success(this.isLock ? "编辑已解锁" : "编辑已锁定");
},
filterOption(input, option) {
return (
option.componentOptions.children[0].text
.toLowerCase()
.indexOf(input.toLowerCase()) >= 0
);
},
handleChange: function(value) {
this.selectItem = value;
if (window.componentAll.indexOf(value + "Config") > -1) {
this.configSelect = value + "Config";
} else {
this.configSelect = value;
}
},
add: function() {
this.$store.commit("layout/setLatout", this.selectItem);
this.visible = false;
}
}
};
</script>
<style lang="less" scoped>
.setting {
position: fixed;
top: 10px;
right: 30px;
z-index: 1;
}
</style>