iov-design 2.15.60 → 2.15.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -148
- package/lib/alert.js +24 -105
- package/lib/aside.js +24 -34
- package/lib/autocomplete.js +36 -240
- package/lib/avatar.js +21 -20
- package/lib/backtop.js +27 -52
- package/lib/badge.js +30 -58
- package/lib/breadcrumb-item.js +24 -53
- package/lib/breadcrumb.js +24 -37
- package/lib/button-group.js +24 -29
- package/lib/button.js +38 -60
- package/lib/calendar.js +29 -146
- package/lib/card.js +24 -51
- package/lib/carousel-item.js +30 -68
- package/lib/carousel.js +27 -159
- package/lib/cascader-panel.js +41 -64
- package/lib/cascader.js +37 -470
- package/lib/checkbox-button.js +28 -164
- package/lib/checkbox-group.js +24 -37
- package/lib/checkbox.js +35 -189
- package/lib/col.js +1 -0
- package/lib/collapse-item.js +27 -125
- package/lib/collapse.js +24 -37
- package/lib/color-picker.js +104 -424
- package/lib/container.js +24 -34
- package/lib/date-picker.js +126 -1981
- package/lib/descriptions-item.js +1 -0
- package/lib/descriptions.js +1 -0
- package/lib/dialog.js +24 -137
- package/lib/divider.js +29 -64
- package/lib/drawer.js +24 -139
- package/lib/dropdown-item.js +27 -45
- package/lib/dropdown-menu.js +24 -51
- package/lib/dropdown.js +21 -20
- package/lib/empty.js +24 -61
- package/lib/footer.js +24 -34
- package/lib/form-item.js +42 -128
- package/lib/form.js +27 -40
- package/lib/header.js +24 -34
- package/lib/icon.js +24 -29
- package/lib/image.js +36 -220
- package/lib/index.js +1 -1
- package/lib/infinite-scroll.js +1 -0
- package/lib/input-number.js +30 -163
- package/lib/input.js +42 -274
- package/lib/iov-design.common.js +1635 -11132
- package/lib/link.js +31 -56
- package/lib/loading.js +24 -77
- package/lib/locale/format.js +10 -10
- package/lib/main.js +24 -29
- package/lib/menu-item-group.js +24 -40
- package/lib/menu-item.js +27 -83
- package/lib/menu.js +21 -20
- package/lib/message-box.js +24 -321
- package/lib/message.js +30 -82
- package/lib/mixins/migrating.js +20 -20
- package/lib/notification.js +24 -109
- package/lib/option-group.js +24 -50
- package/lib/option.js +27 -76
- package/lib/page-header.js +24 -56
- package/lib/pagination.js +24 -97
- package/lib/popconfirm.js +24 -97
- package/lib/popover.js +24 -89
- package/lib/progress.js +30 -133
- package/lib/radio-button.js +29 -111
- package/lib/radio-group.js +24 -39
- package/lib/radio.js +36 -152
- package/lib/rate.js +24 -94
- package/lib/result.js +72 -187
- package/lib/row.js +1 -0
- package/lib/scrollbar.js +1 -0
- package/lib/select.js +48 -637
- package/lib/skeleton-item.js +36 -68
- package/lib/skeleton.js +28 -70
- package/lib/slider.js +36 -267
- package/lib/spinner.js +24 -51
- package/lib/statistic.js +24 -76
- package/lib/step.js +29 -118
- package/lib/steps.js +27 -40
- package/lib/submenu.js +21 -20
- package/lib/switch.js +24 -130
- package/lib/tab-pane.js +24 -52
- package/lib/table-column.js +1 -0
- package/lib/table.js +93 -633
- package/lib/tabs.js +34 -49
- package/lib/tag.js +21 -20
- package/lib/theme-chalk/autocomplete.css +1 -1
- package/lib/theme-chalk/base.css +1 -1
- package/lib/theme-chalk/cascader.css +1 -1
- package/lib/theme-chalk/date-picker.css +1 -1
- package/lib/theme-chalk/index.css +1 -1
- package/lib/theme-chalk/input-number.css +1 -1
- package/lib/theme-chalk/input.css +1 -1
- package/lib/theme-chalk/iovfont.css +1 -1
- package/lib/theme-chalk/link.css +1 -1
- package/lib/theme-chalk/message-box.css +1 -1
- package/lib/theme-chalk/pagination.css +1 -1
- package/lib/theme-chalk/select.css +1 -1
- package/lib/theme-chalk/slider.css +1 -1
- package/lib/theme-chalk/time-picker.css +1 -1
- package/lib/theme-chalk/transfer.css +1 -1
- package/lib/time-picker.js +58 -820
- package/lib/time-select.js +42 -303
- package/lib/timeline-item.js +29 -75
- package/lib/timeline.js +21 -20
- package/lib/tooltip.js +1 -0
- package/lib/transfer.js +36 -299
- package/lib/tree.js +54 -243
- package/lib/upload.js +86 -654
- package/lib/utils/clickoutside.js +7 -7
- package/lib/utils/vue-popper.js +7 -7
- package/package.json +154 -154
- package/packages/autocomplete/src/autocomplete-suggestions.vue +76 -76
- package/packages/autocomplete/src/autocomplete.vue +285 -285
- package/packages/button/src/button.vue +90 -90
- package/packages/calendar/src/date-table.vue +200 -200
- package/packages/calendar/src/main.vue +280 -280
- package/packages/carousel/src/item.vue +138 -138
- package/packages/carousel/src/main.vue +315 -315
- package/packages/cascader/src/cascader.vue +776 -776
- package/packages/cascader-panel/src/cascader-menu.vue +138 -138
- package/packages/cascader-panel/src/cascader-node.vue +246 -246
- package/packages/cascader-panel/src/cascader-panel.vue +391 -391
- package/packages/cascader-panel/src/node.js +166 -166
- package/packages/cascader-panel/src/store.js +58 -58
- package/packages/checkbox/src/checkbox-button.vue +199 -199
- package/packages/checkbox/src/checkbox-group.vue +49 -49
- package/packages/checkbox/src/checkbox.vue +225 -225
- package/packages/collapse/src/collapse-item.vue +114 -114
- package/packages/color-picker/src/components/picker-dropdown.vue +121 -121
- package/packages/color-picker/src/main.vue +188 -188
- package/packages/date-picker/src/basic/date-table.vue +441 -441
- package/packages/date-picker/src/basic/month-table.vue +269 -269
- package/packages/date-picker/src/basic/time-spinner.vue +304 -304
- package/packages/date-picker/src/basic/year-table.vue +111 -111
- package/packages/date-picker/src/panel/date-range.vue +680 -680
- package/packages/date-picker/src/panel/date.vue +609 -609
- package/packages/date-picker/src/panel/month-range.vue +289 -289
- package/packages/date-picker/src/panel/time-range.vue +248 -248
- package/packages/date-picker/src/panel/time-select.vue +178 -178
- package/packages/date-picker/src/panel/time.vue +186 -186
- package/packages/date-picker/src/picker.vue +967 -967
- package/packages/descriptions/src/index.js +180 -180
- package/packages/dialog/src/component.vue +262 -262
- package/packages/drawer/src/main.vue +205 -205
- package/packages/dropdown/src/dropdown-item.vue +37 -37
- package/packages/dropdown/src/dropdown-menu.vue +63 -63
- package/packages/dropdown/src/dropdown.vue +293 -293
- package/packages/empty/src/index.vue +70 -70
- package/packages/form/src/form-item.vue +324 -324
- package/packages/form/src/form.vue +182 -182
- package/packages/image/src/image-viewer.vue +330 -330
- package/packages/image/src/main.vue +249 -249
- package/packages/infinite-scroll/src/main.js +150 -150
- package/packages/input/src/input.vue +477 -477
- package/packages/input-number/src/input-number.vue +283 -283
- package/packages/loading/src/directive.js +133 -133
- package/packages/loading/src/index.js +106 -106
- package/packages/menu/src/menu-item.vue +112 -112
- package/packages/menu/src/menu.vue +325 -325
- package/packages/menu/src/submenu.vue +349 -349
- package/packages/message/src/main.js +91 -91
- package/packages/message-box/src/main.js +216 -216
- package/packages/message-box/src/main.vue +333 -333
- package/packages/notification/src/main.js +94 -94
- package/packages/page-header/src/main.vue +30 -30
- package/packages/pagination/src/pagination.js +390 -390
- package/packages/popconfirm/src/main.vue +104 -104
- package/packages/popover/src/main.vue +239 -239
- package/packages/radio/src/radio-button.vue +115 -115
- package/packages/radio/src/radio-group.vue +115 -115
- package/packages/radio/src/radio.vue +148 -148
- package/packages/rate/src/main.vue +348 -348
- package/packages/scrollbar/src/bar.js +92 -92
- package/packages/scrollbar/src/main.js +130 -130
- package/packages/select/src/option-group.vue +60 -60
- package/packages/select/src/option.vue +171 -171
- package/packages/select/src/select-dropdown.vue +74 -74
- package/packages/select/src/select.vue +979 -979
- package/packages/slider/src/button.vue +238 -238
- package/packages/slider/src/main.vue +427 -427
- package/packages/statistic/src/main.vue +204 -204
- package/packages/steps/src/steps.vue +68 -68
- package/packages/switch/src/component.vue +182 -182
- package/packages/table/src/config.js +153 -153
- package/packages/table/src/filter-panel.vue +194 -194
- package/packages/table/src/store/current.js +76 -76
- package/packages/table/src/store/helper.js +41 -41
- package/packages/table/src/store/index.js +147 -147
- package/packages/table/src/store/watcher.js +502 -502
- package/packages/table/src/table-body.js +469 -469
- package/packages/table/src/table-column.js +328 -328
- package/packages/table/src/table-header.js +571 -571
- package/packages/table/src/table-layout.js +249 -249
- package/packages/table/src/table-row.js +101 -101
- package/packages/table/src/table.vue +740 -740
- package/packages/table/src/util.js +273 -273
- package/packages/tabs/src/tab-bar.vue +57 -57
- package/packages/tabs/src/tab-nav.vue +294 -294
- package/packages/tabs/src/tabs.vue +201 -201
- package/packages/theme-chalk/src/button.scss +416 -416
- package/packages/theme-chalk/src/cascader.scss +252 -252
- package/packages/theme-chalk/src/checkbox.scss +419 -419
- package/packages/theme-chalk/src/common/var.scss +795 -795
- package/packages/theme-chalk/src/form.scss +201 -201
- package/packages/theme-chalk/src/input.scss +591 -591
- package/packages/theme-chalk/src/iovfont.scss +818 -803
- package/packages/theme-chalk/src/link.scss +8 -8
- package/packages/theme-chalk/src/message-box.scss +207 -207
- package/packages/theme-chalk/src/mixins/_button.scss +136 -136
- package/packages/theme-chalk/src/mixins/mixins.scss +190 -190
- package/packages/theme-chalk/src/radio-button.scss +115 -115
- package/packages/theme-chalk/src/select.scss +270 -270
- package/packages/theme-chalk/src/tabs.scss +755 -755
- package/packages/theme-chalk/src/upload.scss +568 -568
- package/packages/tooltip/src/main.js +242 -242
- package/packages/transfer/src/main.vue +231 -231
- package/packages/transfer/src/transfer-panel.vue +251 -251
- package/packages/tree/src/model/node.js +484 -484
- package/packages/tree/src/tree-node.vue +279 -279
- package/packages/tree/src/tree.vue +496 -496
- package/packages/upload/src/index.vue +420 -420
- package/packages/upload/src/upload-file.vue +98 -98
- package/packages/upload/src/upload-list.vue +115 -115
- package/packages/upload/src/upload-picture.vue +98 -98
- package/packages/upload/src/upload.vue +231 -231
- package/packages/upload/src/utils.js +31 -31
- package/src/directives/repeat-click.js +26 -26
- package/src/index.js +259 -259
- package/src/locale/format.js +46 -46
- package/src/locale/index.js +48 -48
- package/src/locale/lang/lo-LA.js +126 -126
- package/src/mixins/locale.js +9 -9
- package/src/mixins/migrating.js +54 -54
- package/src/transitions/collapse-transition.js +77 -77
- package/src/utils/clickoutside.js +76 -76
- package/src/utils/date-util.js +282 -282
- package/src/utils/popup/index.js +218 -218
- package/src/utils/popup/popup-manager.js +194 -194
- package/src/utils/util.js +245 -245
- package/src/utils/vdom.js +5 -5
- package/src/utils/vue-popper.js +198 -198
|
@@ -1,348 +1,348 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div
|
|
3
|
-
class="el-rate"
|
|
4
|
-
@keydown="handleKey"
|
|
5
|
-
role="slider"
|
|
6
|
-
:aria-valuenow="currentValue"
|
|
7
|
-
:aria-valuetext="text"
|
|
8
|
-
aria-valuemin="0"
|
|
9
|
-
:aria-valuemax="max"
|
|
10
|
-
tabindex="0">
|
|
11
|
-
<span
|
|
12
|
-
v-for="(item, key) in max"
|
|
13
|
-
class="el-rate__item"
|
|
14
|
-
@mousemove="setCurrentValue(item, $event)"
|
|
15
|
-
@mouseleave="resetCurrentValue"
|
|
16
|
-
@click="selectValue(item)"
|
|
17
|
-
:style="{ cursor: rateDisabled ? 'auto' : 'pointer' }"
|
|
18
|
-
:key="key">
|
|
19
|
-
<i
|
|
20
|
-
:class="[classes[item - 1], { 'hover': hoverIndex === item }]"
|
|
21
|
-
class="el-rate__icon"
|
|
22
|
-
:style="getIconStyle(item)">
|
|
23
|
-
<i
|
|
24
|
-
v-if="showDecimalIcon(item)"
|
|
25
|
-
:class="decimalIconClass"
|
|
26
|
-
:style="decimalStyle"
|
|
27
|
-
class="el-rate__decimal">
|
|
28
|
-
</i>
|
|
29
|
-
</i>
|
|
30
|
-
</span>
|
|
31
|
-
<span v-if="showText || showScore" class="el-rate__text" :style="{ color: textColor }">{{ text }}</span>
|
|
32
|
-
</div>
|
|
33
|
-
</template>
|
|
34
|
-
|
|
35
|
-
<script>
|
|
36
|
-
import { hasClass } from 'iov-design/src/utils/dom';
|
|
37
|
-
import { isObject } from 'iov-design/src/utils/types';
|
|
38
|
-
import Migrating from 'iov-design/src/mixins/migrating';
|
|
39
|
-
|
|
40
|
-
export default {
|
|
41
|
-
name: 'ElRate',
|
|
42
|
-
|
|
43
|
-
mixins: [Migrating],
|
|
44
|
-
|
|
45
|
-
inject: {
|
|
46
|
-
elForm: {
|
|
47
|
-
default: ''
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
data() {
|
|
52
|
-
return {
|
|
53
|
-
pointerAtLeftHalf: true,
|
|
54
|
-
currentValue: this.value,
|
|
55
|
-
hoverIndex: -1
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
props: {
|
|
60
|
-
value: {
|
|
61
|
-
type: Number,
|
|
62
|
-
default: 0
|
|
63
|
-
},
|
|
64
|
-
lowThreshold: {
|
|
65
|
-
type: Number,
|
|
66
|
-
default: 2
|
|
67
|
-
},
|
|
68
|
-
highThreshold: {
|
|
69
|
-
type: Number,
|
|
70
|
-
default: 4
|
|
71
|
-
},
|
|
72
|
-
max: {
|
|
73
|
-
type: Number,
|
|
74
|
-
default: 5
|
|
75
|
-
},
|
|
76
|
-
colors: {
|
|
77
|
-
type: [Array, Object],
|
|
78
|
-
default() {
|
|
79
|
-
return ['#F7BA2A', '#F7BA2A', '#F7BA2A'];
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
voidColor: {
|
|
83
|
-
type: String,
|
|
84
|
-
default: '#C6D1DE'
|
|
85
|
-
},
|
|
86
|
-
disabledVoidColor: {
|
|
87
|
-
type: String,
|
|
88
|
-
default: '#EFF2F7'
|
|
89
|
-
},
|
|
90
|
-
iconClasses: {
|
|
91
|
-
type: [Array, Object],
|
|
92
|
-
default() {
|
|
93
|
-
return ['el-icon-star-on', 'el-icon-star-on', 'el-icon-star-on'];
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
voidIconClass: {
|
|
97
|
-
type: String,
|
|
98
|
-
default: 'el-icon-star-off'
|
|
99
|
-
},
|
|
100
|
-
disabledVoidIconClass: {
|
|
101
|
-
type: String,
|
|
102
|
-
default: 'el-icon-star-on'
|
|
103
|
-
},
|
|
104
|
-
disabled: {
|
|
105
|
-
type: Boolean,
|
|
106
|
-
default: false
|
|
107
|
-
},
|
|
108
|
-
allowHalf: {
|
|
109
|
-
type: Boolean,
|
|
110
|
-
default: false
|
|
111
|
-
},
|
|
112
|
-
showText: {
|
|
113
|
-
type: Boolean,
|
|
114
|
-
default: false
|
|
115
|
-
},
|
|
116
|
-
showScore: {
|
|
117
|
-
type: Boolean,
|
|
118
|
-
default: false
|
|
119
|
-
},
|
|
120
|
-
textColor: {
|
|
121
|
-
type: String,
|
|
122
|
-
default: '#1f2d3d'
|
|
123
|
-
},
|
|
124
|
-
texts: {
|
|
125
|
-
type: Array,
|
|
126
|
-
default() {
|
|
127
|
-
return ['极差', '失望', '一般', '满意', '惊喜'];
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
scoreTemplate: {
|
|
131
|
-
type: String,
|
|
132
|
-
default: '{value}'
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
computed: {
|
|
137
|
-
text() {
|
|
138
|
-
let result = '';
|
|
139
|
-
if (this.showScore) {
|
|
140
|
-
result = this.scoreTemplate.replace(/\{\s*value\s*\}/, this.rateDisabled
|
|
141
|
-
? this.value
|
|
142
|
-
: this.currentValue);
|
|
143
|
-
} else if (this.showText) {
|
|
144
|
-
result = this.texts[Math.ceil(this.currentValue) - 1];
|
|
145
|
-
}
|
|
146
|
-
return result;
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
decimalStyle() {
|
|
150
|
-
let width = '';
|
|
151
|
-
if (this.rateDisabled) {
|
|
152
|
-
width = `${ this.valueDecimal }%`;
|
|
153
|
-
} else if (this.allowHalf) {
|
|
154
|
-
width = '50%';
|
|
155
|
-
}
|
|
156
|
-
return {
|
|
157
|
-
color: this.activeColor,
|
|
158
|
-
width
|
|
159
|
-
};
|
|
160
|
-
},
|
|
161
|
-
|
|
162
|
-
valueDecimal() {
|
|
163
|
-
return this.value * 100 - Math.floor(this.value) * 100;
|
|
164
|
-
},
|
|
165
|
-
|
|
166
|
-
classMap() {
|
|
167
|
-
return Array.isArray(this.iconClasses)
|
|
168
|
-
? {
|
|
169
|
-
[this.lowThreshold]: this.iconClasses[0],
|
|
170
|
-
[this.highThreshold]: { value: this.iconClasses[1], excluded: true },
|
|
171
|
-
[this.max]: this.iconClasses[2]
|
|
172
|
-
} : this.iconClasses;
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
decimalIconClass() {
|
|
176
|
-
return this.getValueFromMap(this.value, this.classMap);
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
voidClass() {
|
|
180
|
-
return this.rateDisabled ? this.disabledVoidIconClass : this.voidIconClass;
|
|
181
|
-
},
|
|
182
|
-
|
|
183
|
-
activeClass() {
|
|
184
|
-
return this.getValueFromMap(this.currentValue, this.classMap);
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
colorMap() {
|
|
188
|
-
return Array.isArray(this.colors)
|
|
189
|
-
? {
|
|
190
|
-
[this.lowThreshold]: this.colors[0],
|
|
191
|
-
[this.highThreshold]: { value: this.colors[1], excluded: true },
|
|
192
|
-
[this.max]: this.colors[2]
|
|
193
|
-
} : this.colors;
|
|
194
|
-
},
|
|
195
|
-
|
|
196
|
-
activeColor() {
|
|
197
|
-
return this.getValueFromMap(this.currentValue, this.colorMap);
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
classes() {
|
|
201
|
-
let result = [];
|
|
202
|
-
let i = 0;
|
|
203
|
-
let threshold = this.currentValue;
|
|
204
|
-
if (this.allowHalf && this.currentValue !== Math.floor(this.currentValue)) {
|
|
205
|
-
threshold--;
|
|
206
|
-
}
|
|
207
|
-
for (; i < threshold; i++) {
|
|
208
|
-
result.push(this.activeClass);
|
|
209
|
-
}
|
|
210
|
-
for (; i < this.max; i++) {
|
|
211
|
-
result.push(this.voidClass);
|
|
212
|
-
}
|
|
213
|
-
return result;
|
|
214
|
-
},
|
|
215
|
-
|
|
216
|
-
rateDisabled() {
|
|
217
|
-
return this.disabled || (this.elForm || {}).disabled;
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
|
|
221
|
-
watch: {
|
|
222
|
-
value(val) {
|
|
223
|
-
this.currentValue = val;
|
|
224
|
-
this.pointerAtLeftHalf = this.value !== Math.floor(this.value);
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
|
|
228
|
-
methods: {
|
|
229
|
-
getMigratingConfig() {
|
|
230
|
-
return {
|
|
231
|
-
props: {
|
|
232
|
-
'text-template': 'text-template is renamed to score-template.'
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
},
|
|
236
|
-
|
|
237
|
-
getValueFromMap(value, map) {
|
|
238
|
-
const matchedKeys = Object.keys(map)
|
|
239
|
-
.filter(key => {
|
|
240
|
-
const val = map[key];
|
|
241
|
-
const excluded = isObject(val) ? val.excluded : false;
|
|
242
|
-
return excluded ? value < key : value <= key;
|
|
243
|
-
})
|
|
244
|
-
.sort((a, b) => a - b);
|
|
245
|
-
const matchedValue = map[matchedKeys[0]];
|
|
246
|
-
return isObject(matchedValue) ? matchedValue.value : (matchedValue || '');
|
|
247
|
-
},
|
|
248
|
-
|
|
249
|
-
showDecimalIcon(item) {
|
|
250
|
-
let showWhenDisabled = this.rateDisabled && this.valueDecimal > 0 && item - 1 < this.value && item > this.value;
|
|
251
|
-
/* istanbul ignore next */
|
|
252
|
-
let showWhenAllowHalf = this.allowHalf &&
|
|
253
|
-
this.pointerAtLeftHalf &&
|
|
254
|
-
item - 0.5 <= this.currentValue &&
|
|
255
|
-
item > this.currentValue;
|
|
256
|
-
return showWhenDisabled || showWhenAllowHalf;
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
getIconStyle(item) {
|
|
260
|
-
const voidColor = this.rateDisabled ? this.disabledVoidColor : this.voidColor;
|
|
261
|
-
return {
|
|
262
|
-
color: item <= this.currentValue ? this.activeColor : voidColor
|
|
263
|
-
};
|
|
264
|
-
},
|
|
265
|
-
|
|
266
|
-
selectValue(value) {
|
|
267
|
-
if (this.rateDisabled) {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
if (this.allowHalf && this.pointerAtLeftHalf) {
|
|
271
|
-
this.$emit('input', this.currentValue);
|
|
272
|
-
this.$emit('change', this.currentValue);
|
|
273
|
-
} else {
|
|
274
|
-
this.$emit('input', value);
|
|
275
|
-
this.$emit('change', value);
|
|
276
|
-
}
|
|
277
|
-
},
|
|
278
|
-
|
|
279
|
-
handleKey(e) {
|
|
280
|
-
if (this.rateDisabled) {
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
let currentValue = this.currentValue;
|
|
284
|
-
const keyCode = e.keyCode;
|
|
285
|
-
if (keyCode === 38 || keyCode === 39) { // left / down
|
|
286
|
-
if (this.allowHalf) {
|
|
287
|
-
currentValue += 0.5;
|
|
288
|
-
} else {
|
|
289
|
-
currentValue += 1;
|
|
290
|
-
}
|
|
291
|
-
e.stopPropagation();
|
|
292
|
-
e.preventDefault();
|
|
293
|
-
} else if (keyCode === 37 || keyCode === 40) {
|
|
294
|
-
if (this.allowHalf) {
|
|
295
|
-
currentValue -= 0.5;
|
|
296
|
-
} else {
|
|
297
|
-
currentValue -= 1;
|
|
298
|
-
}
|
|
299
|
-
e.stopPropagation();
|
|
300
|
-
e.preventDefault();
|
|
301
|
-
}
|
|
302
|
-
currentValue = currentValue < 0 ? 0 : currentValue;
|
|
303
|
-
currentValue = currentValue > this.max ? this.max : currentValue;
|
|
304
|
-
|
|
305
|
-
this.$emit('input', currentValue);
|
|
306
|
-
this.$emit('change', currentValue);
|
|
307
|
-
},
|
|
308
|
-
|
|
309
|
-
setCurrentValue(value, event) {
|
|
310
|
-
if (this.rateDisabled) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
/* istanbul ignore if */
|
|
314
|
-
if (this.allowHalf) {
|
|
315
|
-
let target = event.target;
|
|
316
|
-
if (hasClass(target, 'el-rate__item')) {
|
|
317
|
-
target = target.querySelector('.el-rate__icon');
|
|
318
|
-
}
|
|
319
|
-
if (hasClass(target, 'el-rate__decimal')) {
|
|
320
|
-
target = target.parentNode;
|
|
321
|
-
}
|
|
322
|
-
this.pointerAtLeftHalf = event.offsetX * 2 <= target.clientWidth;
|
|
323
|
-
this.currentValue = this.pointerAtLeftHalf ? value - 0.5 : value;
|
|
324
|
-
} else {
|
|
325
|
-
this.currentValue = value;
|
|
326
|
-
}
|
|
327
|
-
this.hoverIndex = value;
|
|
328
|
-
},
|
|
329
|
-
|
|
330
|
-
resetCurrentValue() {
|
|
331
|
-
if (this.rateDisabled) {
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
if (this.allowHalf) {
|
|
335
|
-
this.pointerAtLeftHalf = this.value !== Math.floor(this.value);
|
|
336
|
-
}
|
|
337
|
-
this.currentValue = this.value;
|
|
338
|
-
this.hoverIndex = -1;
|
|
339
|
-
}
|
|
340
|
-
},
|
|
341
|
-
|
|
342
|
-
created() {
|
|
343
|
-
if (!this.value) {
|
|
344
|
-
this.$emit('input', 0);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="el-rate"
|
|
4
|
+
@keydown="handleKey"
|
|
5
|
+
role="slider"
|
|
6
|
+
:aria-valuenow="currentValue"
|
|
7
|
+
:aria-valuetext="text"
|
|
8
|
+
aria-valuemin="0"
|
|
9
|
+
:aria-valuemax="max"
|
|
10
|
+
tabindex="0">
|
|
11
|
+
<span
|
|
12
|
+
v-for="(item, key) in max"
|
|
13
|
+
class="el-rate__item"
|
|
14
|
+
@mousemove="setCurrentValue(item, $event)"
|
|
15
|
+
@mouseleave="resetCurrentValue"
|
|
16
|
+
@click="selectValue(item)"
|
|
17
|
+
:style="{ cursor: rateDisabled ? 'auto' : 'pointer' }"
|
|
18
|
+
:key="key">
|
|
19
|
+
<i
|
|
20
|
+
:class="[classes[item - 1], { 'hover': hoverIndex === item }]"
|
|
21
|
+
class="el-rate__icon"
|
|
22
|
+
:style="getIconStyle(item)">
|
|
23
|
+
<i
|
|
24
|
+
v-if="showDecimalIcon(item)"
|
|
25
|
+
:class="decimalIconClass"
|
|
26
|
+
:style="decimalStyle"
|
|
27
|
+
class="el-rate__decimal">
|
|
28
|
+
</i>
|
|
29
|
+
</i>
|
|
30
|
+
</span>
|
|
31
|
+
<span v-if="showText || showScore" class="el-rate__text" :style="{ color: textColor }">{{ text }}</span>
|
|
32
|
+
</div>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<script>
|
|
36
|
+
import { hasClass } from 'iov-design/src/utils/dom';
|
|
37
|
+
import { isObject } from 'iov-design/src/utils/types';
|
|
38
|
+
import Migrating from 'iov-design/src/mixins/migrating';
|
|
39
|
+
|
|
40
|
+
export default {
|
|
41
|
+
name: 'ElRate',
|
|
42
|
+
|
|
43
|
+
mixins: [Migrating],
|
|
44
|
+
|
|
45
|
+
inject: {
|
|
46
|
+
elForm: {
|
|
47
|
+
default: ''
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
data() {
|
|
52
|
+
return {
|
|
53
|
+
pointerAtLeftHalf: true,
|
|
54
|
+
currentValue: this.value,
|
|
55
|
+
hoverIndex: -1
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
props: {
|
|
60
|
+
value: {
|
|
61
|
+
type: Number,
|
|
62
|
+
default: 0
|
|
63
|
+
},
|
|
64
|
+
lowThreshold: {
|
|
65
|
+
type: Number,
|
|
66
|
+
default: 2
|
|
67
|
+
},
|
|
68
|
+
highThreshold: {
|
|
69
|
+
type: Number,
|
|
70
|
+
default: 4
|
|
71
|
+
},
|
|
72
|
+
max: {
|
|
73
|
+
type: Number,
|
|
74
|
+
default: 5
|
|
75
|
+
},
|
|
76
|
+
colors: {
|
|
77
|
+
type: [Array, Object],
|
|
78
|
+
default() {
|
|
79
|
+
return ['#F7BA2A', '#F7BA2A', '#F7BA2A'];
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
voidColor: {
|
|
83
|
+
type: String,
|
|
84
|
+
default: '#C6D1DE'
|
|
85
|
+
},
|
|
86
|
+
disabledVoidColor: {
|
|
87
|
+
type: String,
|
|
88
|
+
default: '#EFF2F7'
|
|
89
|
+
},
|
|
90
|
+
iconClasses: {
|
|
91
|
+
type: [Array, Object],
|
|
92
|
+
default() {
|
|
93
|
+
return ['el-icon-star-on', 'el-icon-star-on', 'el-icon-star-on'];
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
voidIconClass: {
|
|
97
|
+
type: String,
|
|
98
|
+
default: 'el-icon-star-off'
|
|
99
|
+
},
|
|
100
|
+
disabledVoidIconClass: {
|
|
101
|
+
type: String,
|
|
102
|
+
default: 'el-icon-star-on'
|
|
103
|
+
},
|
|
104
|
+
disabled: {
|
|
105
|
+
type: Boolean,
|
|
106
|
+
default: false
|
|
107
|
+
},
|
|
108
|
+
allowHalf: {
|
|
109
|
+
type: Boolean,
|
|
110
|
+
default: false
|
|
111
|
+
},
|
|
112
|
+
showText: {
|
|
113
|
+
type: Boolean,
|
|
114
|
+
default: false
|
|
115
|
+
},
|
|
116
|
+
showScore: {
|
|
117
|
+
type: Boolean,
|
|
118
|
+
default: false
|
|
119
|
+
},
|
|
120
|
+
textColor: {
|
|
121
|
+
type: String,
|
|
122
|
+
default: '#1f2d3d'
|
|
123
|
+
},
|
|
124
|
+
texts: {
|
|
125
|
+
type: Array,
|
|
126
|
+
default() {
|
|
127
|
+
return ['极差', '失望', '一般', '满意', '惊喜'];
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
scoreTemplate: {
|
|
131
|
+
type: String,
|
|
132
|
+
default: '{value}'
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
computed: {
|
|
137
|
+
text() {
|
|
138
|
+
let result = '';
|
|
139
|
+
if (this.showScore) {
|
|
140
|
+
result = this.scoreTemplate.replace(/\{\s*value\s*\}/, this.rateDisabled
|
|
141
|
+
? this.value
|
|
142
|
+
: this.currentValue);
|
|
143
|
+
} else if (this.showText) {
|
|
144
|
+
result = this.texts[Math.ceil(this.currentValue) - 1];
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
decimalStyle() {
|
|
150
|
+
let width = '';
|
|
151
|
+
if (this.rateDisabled) {
|
|
152
|
+
width = `${ this.valueDecimal }%`;
|
|
153
|
+
} else if (this.allowHalf) {
|
|
154
|
+
width = '50%';
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
color: this.activeColor,
|
|
158
|
+
width
|
|
159
|
+
};
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
valueDecimal() {
|
|
163
|
+
return this.value * 100 - Math.floor(this.value) * 100;
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
classMap() {
|
|
167
|
+
return Array.isArray(this.iconClasses)
|
|
168
|
+
? {
|
|
169
|
+
[this.lowThreshold]: this.iconClasses[0],
|
|
170
|
+
[this.highThreshold]: { value: this.iconClasses[1], excluded: true },
|
|
171
|
+
[this.max]: this.iconClasses[2]
|
|
172
|
+
} : this.iconClasses;
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
decimalIconClass() {
|
|
176
|
+
return this.getValueFromMap(this.value, this.classMap);
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
voidClass() {
|
|
180
|
+
return this.rateDisabled ? this.disabledVoidIconClass : this.voidIconClass;
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
activeClass() {
|
|
184
|
+
return this.getValueFromMap(this.currentValue, this.classMap);
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
colorMap() {
|
|
188
|
+
return Array.isArray(this.colors)
|
|
189
|
+
? {
|
|
190
|
+
[this.lowThreshold]: this.colors[0],
|
|
191
|
+
[this.highThreshold]: { value: this.colors[1], excluded: true },
|
|
192
|
+
[this.max]: this.colors[2]
|
|
193
|
+
} : this.colors;
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
activeColor() {
|
|
197
|
+
return this.getValueFromMap(this.currentValue, this.colorMap);
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
classes() {
|
|
201
|
+
let result = [];
|
|
202
|
+
let i = 0;
|
|
203
|
+
let threshold = this.currentValue;
|
|
204
|
+
if (this.allowHalf && this.currentValue !== Math.floor(this.currentValue)) {
|
|
205
|
+
threshold--;
|
|
206
|
+
}
|
|
207
|
+
for (; i < threshold; i++) {
|
|
208
|
+
result.push(this.activeClass);
|
|
209
|
+
}
|
|
210
|
+
for (; i < this.max; i++) {
|
|
211
|
+
result.push(this.voidClass);
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
},
|
|
215
|
+
|
|
216
|
+
rateDisabled() {
|
|
217
|
+
return this.disabled || (this.elForm || {}).disabled;
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
watch: {
|
|
222
|
+
value(val) {
|
|
223
|
+
this.currentValue = val;
|
|
224
|
+
this.pointerAtLeftHalf = this.value !== Math.floor(this.value);
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
|
|
228
|
+
methods: {
|
|
229
|
+
getMigratingConfig() {
|
|
230
|
+
return {
|
|
231
|
+
props: {
|
|
232
|
+
'text-template': 'text-template is renamed to score-template.'
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
getValueFromMap(value, map) {
|
|
238
|
+
const matchedKeys = Object.keys(map)
|
|
239
|
+
.filter(key => {
|
|
240
|
+
const val = map[key];
|
|
241
|
+
const excluded = isObject(val) ? val.excluded : false;
|
|
242
|
+
return excluded ? value < key : value <= key;
|
|
243
|
+
})
|
|
244
|
+
.sort((a, b) => a - b);
|
|
245
|
+
const matchedValue = map[matchedKeys[0]];
|
|
246
|
+
return isObject(matchedValue) ? matchedValue.value : (matchedValue || '');
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
showDecimalIcon(item) {
|
|
250
|
+
let showWhenDisabled = this.rateDisabled && this.valueDecimal > 0 && item - 1 < this.value && item > this.value;
|
|
251
|
+
/* istanbul ignore next */
|
|
252
|
+
let showWhenAllowHalf = this.allowHalf &&
|
|
253
|
+
this.pointerAtLeftHalf &&
|
|
254
|
+
item - 0.5 <= this.currentValue &&
|
|
255
|
+
item > this.currentValue;
|
|
256
|
+
return showWhenDisabled || showWhenAllowHalf;
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
getIconStyle(item) {
|
|
260
|
+
const voidColor = this.rateDisabled ? this.disabledVoidColor : this.voidColor;
|
|
261
|
+
return {
|
|
262
|
+
color: item <= this.currentValue ? this.activeColor : voidColor
|
|
263
|
+
};
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
selectValue(value) {
|
|
267
|
+
if (this.rateDisabled) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (this.allowHalf && this.pointerAtLeftHalf) {
|
|
271
|
+
this.$emit('input', this.currentValue);
|
|
272
|
+
this.$emit('change', this.currentValue);
|
|
273
|
+
} else {
|
|
274
|
+
this.$emit('input', value);
|
|
275
|
+
this.$emit('change', value);
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
handleKey(e) {
|
|
280
|
+
if (this.rateDisabled) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
let currentValue = this.currentValue;
|
|
284
|
+
const keyCode = e.keyCode;
|
|
285
|
+
if (keyCode === 38 || keyCode === 39) { // left / down
|
|
286
|
+
if (this.allowHalf) {
|
|
287
|
+
currentValue += 0.5;
|
|
288
|
+
} else {
|
|
289
|
+
currentValue += 1;
|
|
290
|
+
}
|
|
291
|
+
e.stopPropagation();
|
|
292
|
+
e.preventDefault();
|
|
293
|
+
} else if (keyCode === 37 || keyCode === 40) {
|
|
294
|
+
if (this.allowHalf) {
|
|
295
|
+
currentValue -= 0.5;
|
|
296
|
+
} else {
|
|
297
|
+
currentValue -= 1;
|
|
298
|
+
}
|
|
299
|
+
e.stopPropagation();
|
|
300
|
+
e.preventDefault();
|
|
301
|
+
}
|
|
302
|
+
currentValue = currentValue < 0 ? 0 : currentValue;
|
|
303
|
+
currentValue = currentValue > this.max ? this.max : currentValue;
|
|
304
|
+
|
|
305
|
+
this.$emit('input', currentValue);
|
|
306
|
+
this.$emit('change', currentValue);
|
|
307
|
+
},
|
|
308
|
+
|
|
309
|
+
setCurrentValue(value, event) {
|
|
310
|
+
if (this.rateDisabled) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
/* istanbul ignore if */
|
|
314
|
+
if (this.allowHalf) {
|
|
315
|
+
let target = event.target;
|
|
316
|
+
if (hasClass(target, 'el-rate__item')) {
|
|
317
|
+
target = target.querySelector('.el-rate__icon');
|
|
318
|
+
}
|
|
319
|
+
if (hasClass(target, 'el-rate__decimal')) {
|
|
320
|
+
target = target.parentNode;
|
|
321
|
+
}
|
|
322
|
+
this.pointerAtLeftHalf = event.offsetX * 2 <= target.clientWidth;
|
|
323
|
+
this.currentValue = this.pointerAtLeftHalf ? value - 0.5 : value;
|
|
324
|
+
} else {
|
|
325
|
+
this.currentValue = value;
|
|
326
|
+
}
|
|
327
|
+
this.hoverIndex = value;
|
|
328
|
+
},
|
|
329
|
+
|
|
330
|
+
resetCurrentValue() {
|
|
331
|
+
if (this.rateDisabled) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (this.allowHalf) {
|
|
335
|
+
this.pointerAtLeftHalf = this.value !== Math.floor(this.value);
|
|
336
|
+
}
|
|
337
|
+
this.currentValue = this.value;
|
|
338
|
+
this.hoverIndex = -1;
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
|
|
342
|
+
created() {
|
|
343
|
+
if (!this.value) {
|
|
344
|
+
this.$emit('input', 0);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
</script>
|