Checkbox.vue
7.46 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<template>
<el-row>
<el-form-item label="控件标题">
<el-input v-model="activeData.__config__.label" placeholder="请输入控件标题" />
</el-form-item>
<el-form-item label="控件栅格">
<el-slider v-model="activeData.__config__.span" :max="24" :min="6" show-stops :step="2"
show-tooltip />
</el-form-item>
<el-form-item label="标题宽度">
<el-input-number v-model="activeData.__config__.labelWidth" placeholder="标题宽度" :min="0"
:precision="0" controls-position="right" />
</el-form-item>
<el-form-item label="默认值">
<el-checkbox-group v-model="activeData.__config__.defaultValue" :min="activeData.min"
:max="activeData.max">
<el-checkbox :label="item[activeData.__config__.props.value]"
v-for="(item,i) in activeData.__slot__.options" :key="i">
{{item[activeData.__config__.props.label]}}</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-divider>选项</el-divider>
<el-form-item label="" label-width="40px">
<el-radio-group v-model="activeData.__config__.dataType" size="small"
style="text-align:center" @change="dataTypeChange">
<el-radio-button label="static">静态数据</el-radio-button>
<el-radio-button label="dictionary">数据字典</el-radio-button>
<el-radio-button label="dynamic">远端数据</el-radio-button>
</el-radio-group>
</el-form-item>
<template v-if="activeData.__config__.dataType==='static'">
<draggable :list="activeData.__slot__.options" :animation="340" group="selectItem"
handle=".option-drag">
<div v-for="(item, index) in activeData.__slot__.options" :key="index" class="select-item">
<div class="select-line-icon option-drag">
<i class="el-icon-s-operation" />
</div>
<el-input v-model="item.fullName" placeholder="选项名" size="small" />
<el-input v-model="item.id" placeholder="选项值" size="small" />
<div class="close-btn select-line-icon"
@click="activeData.__slot__.options.splice(index, 1)">
<i class="el-icon-remove-outline" />
</div>
</div>
</draggable>
<div style="margin-left: 29px;">
<el-button style="padding-bottom: 0" icon="el-icon-circle-plus-outline" type="text"
@click="addSelectItem">
添加选项
</el-button>
</div>
</template>
<NCC-TreeSelect :options="treeData" v-model="activeData.__config__.dictionaryType"
placeholder="选择数据字典" lastLevel v-if="activeData.__config__.dataType==='dictionary'" clearable>
</NCC-TreeSelect>
<template v-if="activeData.__config__.dataType === 'dynamic'">
<el-form-item label="远端数据">
<NCC-TreeSelect :options="dataInterfaceSelector" v-model="activeData.__config__.propsUrl"
placeholder="请选择远端数据" lastLevel lastLevelKey='categoryId' lastLevelValue='1'
@change="propsUrlChange" clearable>
</NCC-TreeSelect>
</el-form-item>
<el-form-item label="存储字段">
<el-input v-model="activeData.__config__.props.value" placeholder="请输入存储字段" />
</el-form-item>
<el-form-item label="显示字段">
<el-input v-model="activeData.__config__.props.label" placeholder="请输入显示字段" />
</el-form-item>
</template>
<el-divider />
<!-- <el-form-item label="显示标签">
<el-switch v-model="activeData.__config__.showLabel" />
</el-form-item> -->
<el-form-item label="选项样式">
<el-radio-group v-model="activeData.__config__.optionType">
<el-radio-button label="default">
默认
</el-radio-button>
<el-radio-button label="button">
按钮
</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-if=" activeData.__config__.optionType === 'default'" label="是否带边框">
<el-switch v-model="activeData.__config__.border" />
</el-form-item>
<el-form-item v-if="activeData.__config__.optionType === 'button' ||
activeData.__config__.border" label="组件尺寸">
<el-radio-group v-model="activeData.size">
<el-radio-button label="medium">
中等
</el-radio-button>
<el-radio-button label="small">
较小
</el-radio-button>
<el-radio-button label="mini">
迷你
</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="是否禁用">
<el-switch v-model="activeData.disabled" />
</el-form-item>
<el-divider>校验</el-divider>
<el-form-item label="是否必填">
<el-switch v-model="activeData.__config__.required" />
</el-form-item>
</el-row>
</template>
<script>
import comMixin from './mixin';
import draggable from 'vuedraggable'
import { getDictionaryTypeSelector, getDictionaryDataSelector } from '@/api/systemData/dictionary'
import { getDataInterfaceSelector, previewDataInterface } from '@/api/systemData/dataInterface'
export default {
props: ['activeData'],
mixins: [comMixin],
components: { draggable },
data() {
return {
treeData: [],
dataInterfaceSelector: []
}
},
created() {
this.getDictionaryType()
this.getDataInterfaceSelector()
},
watch: {
'activeData.__config__.dictionaryType': function (val) {
if (!val) {
this.activeData.__slot__.options = []
return
}
getDictionaryDataSelector(val).then(res => {
this.activeData.__slot__.options = res.data.list
})
}
},
methods: {
getDictionaryType() {
getDictionaryTypeSelector().then(res => {
this.treeData = res.data.list
})
},
getDataInterfaceSelector() {
getDataInterfaceSelector().then(res => {
this.dataInterfaceSelector = res.data
})
},
addSelectItem() {
this.activeData.__slot__.options.push({
fullName: '',
id: ''
})
},
dataTypeChange(val) {
this.activeData.__config__.defaultValue = []
this.activeData.__slot__.options = []
this.activeData.__config__.props.value = 'id'
this.activeData.__config__.props.label = 'fullName'
if (val === 'static') {
this.activeData.__config__.dictionaryType = ''
this.activeData.__config__.propsUrl = ''
}
if (val === 'dynamic') {
this.activeData.__config__.dictionaryType = ''
}
if (val === 'dictionary') {
this.activeData.__config__.propsUrl = ''
}
},
dictionaryTypeChange() {
this.activeData.__config__.defaultValue = []
},
propsUrlChange(val) {
if (!val) {
this.activeData.__slot__.options = []
return
}
this.activeData.__config__.defaultValue = []
previewDataInterface(val).then(res => {
this.activeData.__slot__.options = res.data
}).catch(res => {
this.activeData.__config__.propsUrl = ''
this.activeData.__slot__.options = []
})
}
}
}
</script>
<style lang="scss">
.select-item {
display: flex;
border: 1px dashed #fff;
box-sizing: border-box;
& .close-btn {
cursor: pointer;
color: #f56c6c;
}
& .el-input + .el-input {
margin-left: 4px;
}
}
.select-item + .select-item {
margin-top: 4px;
}
.select-item.sortable-chosen {
border: 1px dashed #409eff;
}
.select-line-icon {
line-height: 32px;
font-size: 22px;
padding: 0 4px;
color: #777;
}
.option-drag {
cursor: move;
}
</style>