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
<template>
<div>
<el-form-item label="默认值">
<el-input v-model="data.value"
clearable
placeholder="默认值"></el-input>
</el-form-item>
<el-form-item label="最大星数">
<el-input-number v-model="data.max"
controls-position="right"
placeholder="最大星数"></el-input-number>
</el-form-item>
<el-form-item label="是否显示文本"
label-width="110px">
<el-switch v-model="data.showText"></el-switch>
</el-form-item>
<el-form-item label="自定义文本"
label-width="110px"
v-if="data.showText">
<el-tag :key="index"
size="small"
v-for="(tag,index) in data.texts"
closable
@close="handleTextClose(tag)">{{tag}}
</el-tag>
<el-input class="input-new-tag"
v-if="textVisible"
v-model="textValue"
size="mini"
ref="textTag"
clearable
@keyup.enter.native="handleTextConfirm"
@blur="handleTextConfirm">
</el-input>
<el-button v-if="!textVisible && data.texts.length < data.max"
@click="showTextInput"
size="mini"
icon="el-icon-plus"
circle
style="margin-left: 5px;"></el-button>
</el-form-item>
<el-form-item label="自定义颜色"
label-width="110px">
<el-tag :key="index"
v-for="(tag,index) in data.colors"
closable
size="small"
@close="handleColorClose(tag)"
:style="{color: tag}">{{tag}}
</el-tag>
<el-color-picker v-model="colorValue"
size="mini"
@change="handleColorConfirm"
class="color-picker"></el-color-picker>
</el-form-item>
<!-- <el-form-item label="自定义图标">-->
<!-- <el-tag :key="index" v-for="(tag,index) in data.iconClasses" closable @close="handleIconClose(tag)">{{tag}}-->
<!-- </el-tag>-->
<!-- <el-input class="input-new-tag"-->
<!-- v-if="iconVisible"-->
<!-- v-model="iconValue"-->
<!-- size="mini"-->
<!-- ref="iconTag"-->
<!-- @keyup.enter.native="handleIconConfirm"-->
<!-- @blur="handleIconConfirm">-->
<!-- </el-input>-->
<!-- <el-button v-else @click="showIconInput" size="mini" icon="el-icon-plus" circle-->
<!-- style="margin-left: 5px;"></el-button>-->
<!-- </el-form-item>-->
<el-form-item label="是否禁用">
<el-switch v-model="data.disabled"></el-switch>
</el-form-item>
<el-form-item label="是否可见">
<el-switch v-model="data.display"></el-switch>
</el-form-item>
<el-form-item label="是否必填">
<el-switch v-model="data.required"></el-switch>
</el-form-item>
</div>
</template>
<script>
export default {
name: "config-rate",
props: ['data'],
data() {
return {
validator: {
type: null,
required: null,
pattern: null,
length: null
},
textVisible: false,
textValue: '',
colorVisible: false,
colorValue: '',
iconVisible: false,
iconValue: ''
}
},
methods: {
generateRule() {
const rules = [];
Object.keys(this.validator).forEach(key => {
if (this.validator[key]) rules.push(this.validator[key])
})
this.data.rules = rules
},
handleTextClose(tag) {
this.data.texts.splice(this.data.texts.indexOf(tag), 1);
},
showTextInput() {
this.textVisible = true;
this.$nextTick(() => {
this.$refs.textTag.$refs.input.focus();
});
},
handleTextConfirm() {
if (this.textValue) this.data.texts.push(this.textValue);
this.textVisible = false;
this.textValue = '';
},
handleColorClose(tag) {
this.data.colors.splice(this.data.colors.indexOf(tag), 1);
},
handleColorConfirm() {
if (this.colorValue) this.data.colors.push(this.colorValue);
this.colorValue = '';
},
// handleIconClose(tag) {
// this.data.iconClasses.splice(this.data.iconClasses.indexOf(tag), 1);
// },
// showIconInput() {
// this.iconVisible = true;
// this.$nextTick(() => {
// this.$refs.iconTag.$refs.input.focus();
// });
// },
// handleIconConfirm() {
// if (this.iconValue) this.data.iconClasses.push(this.iconValue);
// this.iconVisible = false;
// this.iconValue = '';
// }
},
watch: {
'data.required': function (val) {
if (val) this.validator.required = { required: true, message: `${this.data.label}必须填写` }
else this.validator.required = null
this.generateRule()
},
}
}
</script>
<style lang="scss" scoped>
.el-tag {
vertical-align: top;
}
.el-tag + .el-tag {
margin-left: 5px;
}
.input-new-tag {
width: 90px;
margin-left: 5px;
vertical-align: bottom;
}
.color-picker {
left: 10px;
vertical-align: top;
}
</style>