iov-design 2.15.59 → 2.15.61
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 +1638 -11132
- package/lib/link.js +33 -55
- 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 +22 -21
- package/lib/theme-chalk/base.css +1 -1
- package/lib/theme-chalk/button.css +1 -1
- package/lib/theme-chalk/calendar.css +1 -1
- package/lib/theme-chalk/cascader-panel.css +1 -1
- package/lib/theme-chalk/cascader.css +1 -1
- package/lib/theme-chalk/dropdown.css +1 -1
- package/lib/theme-chalk/index.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/radio.css +1 -1
- package/lib/theme-chalk/select.css +1 -1
- package/lib/theme-chalk/table-column.css +1 -1
- package/lib/theme-chalk/table.css +1 -1
- package/lib/theme-chalk/tabs.css +1 -1
- package/lib/theme-chalk/tag.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/link/src/main.vue +2 -0
- 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/tag/src/tag.vue +1 -1
- 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 -816
- 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 +803 -784
- package/packages/theme-chalk/src/link.scss +36 -19
- 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/radio.scss +1 -0
- package/packages/theme-chalk/src/select.scss +270 -270
- package/packages/theme-chalk/src/table.scss +1 -2
- package/packages/theme-chalk/src/tabs.scss +755 -750
- package/packages/theme-chalk/src/tag.scss +4 -4
- 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,283 +1,283 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div
|
|
3
|
-
@dragstart.prevent
|
|
4
|
-
:class="[
|
|
5
|
-
'el-input-number',
|
|
6
|
-
inputNumberSize ? 'el-input-number--' + inputNumberSize : '',
|
|
7
|
-
{ 'is-disabled': inputNumberDisabled },
|
|
8
|
-
{ 'is-without-controls': !controls },
|
|
9
|
-
{ 'is-controls-right': controlsAtRight }
|
|
10
|
-
]">
|
|
11
|
-
<span
|
|
12
|
-
class="el-input-number__decrease"
|
|
13
|
-
role="button"
|
|
14
|
-
v-if="controls"
|
|
15
|
-
v-repeat-click="decrease"
|
|
16
|
-
:class="{'is-disabled': minDisabled}"
|
|
17
|
-
@keydown.enter="decrease">
|
|
18
|
-
<i :class="`el-icon-${controlsAtRight ? 'arrow-down' : 'minus'}`"></i>
|
|
19
|
-
</span>
|
|
20
|
-
<span
|
|
21
|
-
class="el-input-number__increase"
|
|
22
|
-
role="button"
|
|
23
|
-
v-if="controls"
|
|
24
|
-
v-repeat-click="increase"
|
|
25
|
-
:class="{'is-disabled': maxDisabled}"
|
|
26
|
-
@keydown.enter="increase">
|
|
27
|
-
<i :class="`el-icon-${controlsAtRight ? 'arrow-up' : 'plus'}`"></i>
|
|
28
|
-
</span>
|
|
29
|
-
<el-input
|
|
30
|
-
ref="input"
|
|
31
|
-
:value="displayValue"
|
|
32
|
-
:placeholder="placeholder"
|
|
33
|
-
:disabled="inputNumberDisabled"
|
|
34
|
-
:size="inputNumberSize"
|
|
35
|
-
:max="max"
|
|
36
|
-
:min="min"
|
|
37
|
-
:name="name"
|
|
38
|
-
:label="label"
|
|
39
|
-
@keydown.up.native.prevent="increase"
|
|
40
|
-
@keydown.down.native.prevent="decrease"
|
|
41
|
-
@blur="handleBlur"
|
|
42
|
-
@focus="handleFocus"
|
|
43
|
-
@input="handleInput"
|
|
44
|
-
@change="handleInputChange">
|
|
45
|
-
</el-input>
|
|
46
|
-
</div>
|
|
47
|
-
</template>
|
|
48
|
-
<script>
|
|
49
|
-
import ElInput from 'iov-design/packages/input';
|
|
50
|
-
import Focus from 'iov-design/src/mixins/focus';
|
|
51
|
-
import RepeatClick from 'iov-design/src/directives/repeat-click';
|
|
52
|
-
|
|
53
|
-
export default {
|
|
54
|
-
name: 'ElInputNumber',
|
|
55
|
-
mixins: [Focus('input')],
|
|
56
|
-
inject: {
|
|
57
|
-
elForm: {
|
|
58
|
-
default: ''
|
|
59
|
-
},
|
|
60
|
-
elFormItem: {
|
|
61
|
-
default: ''
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
directives: {
|
|
65
|
-
repeatClick: RepeatClick
|
|
66
|
-
},
|
|
67
|
-
components: {
|
|
68
|
-
ElInput
|
|
69
|
-
},
|
|
70
|
-
props: {
|
|
71
|
-
step: {
|
|
72
|
-
type: Number,
|
|
73
|
-
default: 1
|
|
74
|
-
},
|
|
75
|
-
stepStrictly: {
|
|
76
|
-
type: Boolean,
|
|
77
|
-
default: false
|
|
78
|
-
},
|
|
79
|
-
max: {
|
|
80
|
-
type: Number,
|
|
81
|
-
default: Infinity
|
|
82
|
-
},
|
|
83
|
-
min: {
|
|
84
|
-
type: Number,
|
|
85
|
-
default: -Infinity
|
|
86
|
-
},
|
|
87
|
-
value: {},
|
|
88
|
-
disabled: Boolean,
|
|
89
|
-
size: String,
|
|
90
|
-
controls: {
|
|
91
|
-
type: Boolean,
|
|
92
|
-
default: true
|
|
93
|
-
},
|
|
94
|
-
controlsPosition: {
|
|
95
|
-
type: String,
|
|
96
|
-
default: ''
|
|
97
|
-
},
|
|
98
|
-
name: String,
|
|
99
|
-
label: String,
|
|
100
|
-
placeholder: String,
|
|
101
|
-
precision: {
|
|
102
|
-
type: Number,
|
|
103
|
-
validator(val) {
|
|
104
|
-
return val >= 0 && val === parseInt(val, 10);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
data() {
|
|
109
|
-
return {
|
|
110
|
-
currentValue: 0,
|
|
111
|
-
userInput: null
|
|
112
|
-
};
|
|
113
|
-
},
|
|
114
|
-
watch: {
|
|
115
|
-
value: {
|
|
116
|
-
immediate: true,
|
|
117
|
-
handler(value) {
|
|
118
|
-
let newVal = value === undefined ? value : Number(value);
|
|
119
|
-
if (newVal !== undefined) {
|
|
120
|
-
if (isNaN(newVal)) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (this.stepStrictly) {
|
|
125
|
-
const stepPrecision = this.getPrecision(this.step);
|
|
126
|
-
const precisionFactor = Math.pow(10, stepPrecision);
|
|
127
|
-
newVal = Math.round(newVal / this.step) * precisionFactor * this.step / precisionFactor;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (this.precision !== undefined) {
|
|
131
|
-
newVal = this.toPrecision(newVal, this.precision);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (newVal >= this.max) newVal = this.max;
|
|
135
|
-
if (newVal <= this.min) newVal = this.min;
|
|
136
|
-
this.currentValue = newVal;
|
|
137
|
-
this.userInput = null;
|
|
138
|
-
this.$emit('input', newVal);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
computed: {
|
|
143
|
-
minDisabled() {
|
|
144
|
-
return this._decrease(this.value, this.step) < this.min;
|
|
145
|
-
},
|
|
146
|
-
maxDisabled() {
|
|
147
|
-
return this._increase(this.value, this.step) > this.max;
|
|
148
|
-
},
|
|
149
|
-
numPrecision() {
|
|
150
|
-
const { value, step, getPrecision, precision } = this;
|
|
151
|
-
const stepPrecision = getPrecision(step);
|
|
152
|
-
if (precision !== undefined) {
|
|
153
|
-
if (stepPrecision > precision) {
|
|
154
|
-
console.warn('[Element Warn][InputNumber]precision should not be less than the decimal places of step');
|
|
155
|
-
}
|
|
156
|
-
return precision;
|
|
157
|
-
} else {
|
|
158
|
-
return Math.max(getPrecision(value), stepPrecision);
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
controlsAtRight() {
|
|
162
|
-
return this.controls && this.controlsPosition === 'right';
|
|
163
|
-
},
|
|
164
|
-
_elFormItemSize() {
|
|
165
|
-
return (this.elFormItem || {}).elFormItemSize;
|
|
166
|
-
},
|
|
167
|
-
inputNumberSize() {
|
|
168
|
-
return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size;
|
|
169
|
-
},
|
|
170
|
-
inputNumberDisabled() {
|
|
171
|
-
return this.disabled || !!(this.elForm || {}).disabled;
|
|
172
|
-
},
|
|
173
|
-
displayValue() {
|
|
174
|
-
if (this.userInput !== null) {
|
|
175
|
-
return this.userInput;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
let currentValue = this.currentValue;
|
|
179
|
-
|
|
180
|
-
if (typeof currentValue === 'number') {
|
|
181
|
-
if (this.stepStrictly) {
|
|
182
|
-
const stepPrecision = this.getPrecision(this.step);
|
|
183
|
-
const precisionFactor = Math.pow(10, stepPrecision);
|
|
184
|
-
currentValue = Math.round(currentValue / this.step) * precisionFactor * this.step / precisionFactor;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (this.precision !== undefined) {
|
|
188
|
-
currentValue = currentValue.toFixed(this.precision);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return currentValue;
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
methods: {
|
|
196
|
-
toPrecision(num, precision) {
|
|
197
|
-
if (precision === undefined) precision = this.numPrecision;
|
|
198
|
-
return parseFloat(Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision));
|
|
199
|
-
},
|
|
200
|
-
getPrecision(value) {
|
|
201
|
-
if (value === undefined) return 0;
|
|
202
|
-
const valueString = value.toString();
|
|
203
|
-
const dotPosition = valueString.indexOf('.');
|
|
204
|
-
let precision = 0;
|
|
205
|
-
if (dotPosition !== -1) {
|
|
206
|
-
precision = valueString.length - dotPosition - 1;
|
|
207
|
-
}
|
|
208
|
-
return precision;
|
|
209
|
-
},
|
|
210
|
-
_increase(val, step) {
|
|
211
|
-
if (typeof val !== 'number' && val !== undefined) return this.currentValue;
|
|
212
|
-
|
|
213
|
-
const precisionFactor = Math.pow(10, this.numPrecision);
|
|
214
|
-
// Solve the accuracy problem of JS decimal calculation by converting the value to integer.
|
|
215
|
-
return this.toPrecision((precisionFactor * val + precisionFactor * step) / precisionFactor);
|
|
216
|
-
},
|
|
217
|
-
_decrease(val, step) {
|
|
218
|
-
if (typeof val !== 'number' && val !== undefined) return this.currentValue;
|
|
219
|
-
|
|
220
|
-
const precisionFactor = Math.pow(10, this.numPrecision);
|
|
221
|
-
|
|
222
|
-
return this.toPrecision((precisionFactor * val - precisionFactor * step) / precisionFactor);
|
|
223
|
-
},
|
|
224
|
-
increase() {
|
|
225
|
-
if (this.inputNumberDisabled || this.maxDisabled) return;
|
|
226
|
-
const value = this.value || 0;
|
|
227
|
-
const newVal = this._increase(value, this.step);
|
|
228
|
-
this.setCurrentValue(newVal);
|
|
229
|
-
},
|
|
230
|
-
decrease() {
|
|
231
|
-
if (this.inputNumberDisabled || this.minDisabled) return;
|
|
232
|
-
const value = this.value || 0;
|
|
233
|
-
const newVal = this._decrease(value, this.step);
|
|
234
|
-
this.setCurrentValue(newVal);
|
|
235
|
-
},
|
|
236
|
-
handleBlur(event) {
|
|
237
|
-
this.$emit('blur', event);
|
|
238
|
-
},
|
|
239
|
-
handleFocus(event) {
|
|
240
|
-
this.$emit('focus', event);
|
|
241
|
-
},
|
|
242
|
-
setCurrentValue(newVal) {
|
|
243
|
-
const oldVal = this.currentValue;
|
|
244
|
-
if (typeof newVal === 'number' && this.precision !== undefined) {
|
|
245
|
-
newVal = this.toPrecision(newVal, this.precision);
|
|
246
|
-
}
|
|
247
|
-
if (newVal >= this.max) newVal = this.max;
|
|
248
|
-
if (newVal <= this.min) newVal = this.min;
|
|
249
|
-
if (oldVal === newVal) return;
|
|
250
|
-
this.userInput = null;
|
|
251
|
-
this.$emit('input', newVal);
|
|
252
|
-
this.$emit('change', newVal, oldVal);
|
|
253
|
-
this.currentValue = newVal;
|
|
254
|
-
},
|
|
255
|
-
handleInput(value) {
|
|
256
|
-
this.userInput = value;
|
|
257
|
-
},
|
|
258
|
-
handleInputChange(value) {
|
|
259
|
-
const newVal = value === '' ? undefined : Number(value);
|
|
260
|
-
if (!isNaN(newVal) || value === '') {
|
|
261
|
-
this.setCurrentValue(newVal);
|
|
262
|
-
}
|
|
263
|
-
this.userInput = null;
|
|
264
|
-
},
|
|
265
|
-
select() {
|
|
266
|
-
this.$refs.input.select();
|
|
267
|
-
}
|
|
268
|
-
},
|
|
269
|
-
mounted() {
|
|
270
|
-
let innerInput = this.$refs.input.$refs.input;
|
|
271
|
-
innerInput.setAttribute('role', 'spinbutton');
|
|
272
|
-
innerInput.setAttribute('aria-valuemax', this.max);
|
|
273
|
-
innerInput.setAttribute('aria-valuemin', this.min);
|
|
274
|
-
innerInput.setAttribute('aria-valuenow', this.currentValue);
|
|
275
|
-
innerInput.setAttribute('aria-disabled', this.inputNumberDisabled);
|
|
276
|
-
},
|
|
277
|
-
updated() {
|
|
278
|
-
if (!this.$refs || !this.$refs.input) return;
|
|
279
|
-
const innerInput = this.$refs.input.$refs.input;
|
|
280
|
-
innerInput.setAttribute('aria-valuenow', this.currentValue);
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
@dragstart.prevent
|
|
4
|
+
:class="[
|
|
5
|
+
'el-input-number',
|
|
6
|
+
inputNumberSize ? 'el-input-number--' + inputNumberSize : '',
|
|
7
|
+
{ 'is-disabled': inputNumberDisabled },
|
|
8
|
+
{ 'is-without-controls': !controls },
|
|
9
|
+
{ 'is-controls-right': controlsAtRight }
|
|
10
|
+
]">
|
|
11
|
+
<span
|
|
12
|
+
class="el-input-number__decrease"
|
|
13
|
+
role="button"
|
|
14
|
+
v-if="controls"
|
|
15
|
+
v-repeat-click="decrease"
|
|
16
|
+
:class="{'is-disabled': minDisabled}"
|
|
17
|
+
@keydown.enter="decrease">
|
|
18
|
+
<i :class="`el-icon-${controlsAtRight ? 'arrow-down' : 'minus'}`"></i>
|
|
19
|
+
</span>
|
|
20
|
+
<span
|
|
21
|
+
class="el-input-number__increase"
|
|
22
|
+
role="button"
|
|
23
|
+
v-if="controls"
|
|
24
|
+
v-repeat-click="increase"
|
|
25
|
+
:class="{'is-disabled': maxDisabled}"
|
|
26
|
+
@keydown.enter="increase">
|
|
27
|
+
<i :class="`el-icon-${controlsAtRight ? 'arrow-up' : 'plus'}`"></i>
|
|
28
|
+
</span>
|
|
29
|
+
<el-input
|
|
30
|
+
ref="input"
|
|
31
|
+
:value="displayValue"
|
|
32
|
+
:placeholder="placeholder"
|
|
33
|
+
:disabled="inputNumberDisabled"
|
|
34
|
+
:size="inputNumberSize"
|
|
35
|
+
:max="max"
|
|
36
|
+
:min="min"
|
|
37
|
+
:name="name"
|
|
38
|
+
:label="label"
|
|
39
|
+
@keydown.up.native.prevent="increase"
|
|
40
|
+
@keydown.down.native.prevent="decrease"
|
|
41
|
+
@blur="handleBlur"
|
|
42
|
+
@focus="handleFocus"
|
|
43
|
+
@input="handleInput"
|
|
44
|
+
@change="handleInputChange">
|
|
45
|
+
</el-input>
|
|
46
|
+
</div>
|
|
47
|
+
</template>
|
|
48
|
+
<script>
|
|
49
|
+
import ElInput from 'iov-design/packages/input';
|
|
50
|
+
import Focus from 'iov-design/src/mixins/focus';
|
|
51
|
+
import RepeatClick from 'iov-design/src/directives/repeat-click';
|
|
52
|
+
|
|
53
|
+
export default {
|
|
54
|
+
name: 'ElInputNumber',
|
|
55
|
+
mixins: [Focus('input')],
|
|
56
|
+
inject: {
|
|
57
|
+
elForm: {
|
|
58
|
+
default: ''
|
|
59
|
+
},
|
|
60
|
+
elFormItem: {
|
|
61
|
+
default: ''
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
directives: {
|
|
65
|
+
repeatClick: RepeatClick
|
|
66
|
+
},
|
|
67
|
+
components: {
|
|
68
|
+
ElInput
|
|
69
|
+
},
|
|
70
|
+
props: {
|
|
71
|
+
step: {
|
|
72
|
+
type: Number,
|
|
73
|
+
default: 1
|
|
74
|
+
},
|
|
75
|
+
stepStrictly: {
|
|
76
|
+
type: Boolean,
|
|
77
|
+
default: false
|
|
78
|
+
},
|
|
79
|
+
max: {
|
|
80
|
+
type: Number,
|
|
81
|
+
default: Infinity
|
|
82
|
+
},
|
|
83
|
+
min: {
|
|
84
|
+
type: Number,
|
|
85
|
+
default: -Infinity
|
|
86
|
+
},
|
|
87
|
+
value: {},
|
|
88
|
+
disabled: Boolean,
|
|
89
|
+
size: String,
|
|
90
|
+
controls: {
|
|
91
|
+
type: Boolean,
|
|
92
|
+
default: true
|
|
93
|
+
},
|
|
94
|
+
controlsPosition: {
|
|
95
|
+
type: String,
|
|
96
|
+
default: ''
|
|
97
|
+
},
|
|
98
|
+
name: String,
|
|
99
|
+
label: String,
|
|
100
|
+
placeholder: String,
|
|
101
|
+
precision: {
|
|
102
|
+
type: Number,
|
|
103
|
+
validator(val) {
|
|
104
|
+
return val >= 0 && val === parseInt(val, 10);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
data() {
|
|
109
|
+
return {
|
|
110
|
+
currentValue: 0,
|
|
111
|
+
userInput: null
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
watch: {
|
|
115
|
+
value: {
|
|
116
|
+
immediate: true,
|
|
117
|
+
handler(value) {
|
|
118
|
+
let newVal = value === undefined ? value : Number(value);
|
|
119
|
+
if (newVal !== undefined) {
|
|
120
|
+
if (isNaN(newVal)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (this.stepStrictly) {
|
|
125
|
+
const stepPrecision = this.getPrecision(this.step);
|
|
126
|
+
const precisionFactor = Math.pow(10, stepPrecision);
|
|
127
|
+
newVal = Math.round(newVal / this.step) * precisionFactor * this.step / precisionFactor;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (this.precision !== undefined) {
|
|
131
|
+
newVal = this.toPrecision(newVal, this.precision);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (newVal >= this.max) newVal = this.max;
|
|
135
|
+
if (newVal <= this.min) newVal = this.min;
|
|
136
|
+
this.currentValue = newVal;
|
|
137
|
+
this.userInput = null;
|
|
138
|
+
this.$emit('input', newVal);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
computed: {
|
|
143
|
+
minDisabled() {
|
|
144
|
+
return this._decrease(this.value, this.step) < this.min;
|
|
145
|
+
},
|
|
146
|
+
maxDisabled() {
|
|
147
|
+
return this._increase(this.value, this.step) > this.max;
|
|
148
|
+
},
|
|
149
|
+
numPrecision() {
|
|
150
|
+
const { value, step, getPrecision, precision } = this;
|
|
151
|
+
const stepPrecision = getPrecision(step);
|
|
152
|
+
if (precision !== undefined) {
|
|
153
|
+
if (stepPrecision > precision) {
|
|
154
|
+
console.warn('[Element Warn][InputNumber]precision should not be less than the decimal places of step');
|
|
155
|
+
}
|
|
156
|
+
return precision;
|
|
157
|
+
} else {
|
|
158
|
+
return Math.max(getPrecision(value), stepPrecision);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
controlsAtRight() {
|
|
162
|
+
return this.controls && this.controlsPosition === 'right';
|
|
163
|
+
},
|
|
164
|
+
_elFormItemSize() {
|
|
165
|
+
return (this.elFormItem || {}).elFormItemSize;
|
|
166
|
+
},
|
|
167
|
+
inputNumberSize() {
|
|
168
|
+
return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size;
|
|
169
|
+
},
|
|
170
|
+
inputNumberDisabled() {
|
|
171
|
+
return this.disabled || !!(this.elForm || {}).disabled;
|
|
172
|
+
},
|
|
173
|
+
displayValue() {
|
|
174
|
+
if (this.userInput !== null) {
|
|
175
|
+
return this.userInput;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let currentValue = this.currentValue;
|
|
179
|
+
|
|
180
|
+
if (typeof currentValue === 'number') {
|
|
181
|
+
if (this.stepStrictly) {
|
|
182
|
+
const stepPrecision = this.getPrecision(this.step);
|
|
183
|
+
const precisionFactor = Math.pow(10, stepPrecision);
|
|
184
|
+
currentValue = Math.round(currentValue / this.step) * precisionFactor * this.step / precisionFactor;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (this.precision !== undefined) {
|
|
188
|
+
currentValue = currentValue.toFixed(this.precision);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return currentValue;
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
methods: {
|
|
196
|
+
toPrecision(num, precision) {
|
|
197
|
+
if (precision === undefined) precision = this.numPrecision;
|
|
198
|
+
return parseFloat(Math.round(num * Math.pow(10, precision)) / Math.pow(10, precision));
|
|
199
|
+
},
|
|
200
|
+
getPrecision(value) {
|
|
201
|
+
if (value === undefined) return 0;
|
|
202
|
+
const valueString = value.toString();
|
|
203
|
+
const dotPosition = valueString.indexOf('.');
|
|
204
|
+
let precision = 0;
|
|
205
|
+
if (dotPosition !== -1) {
|
|
206
|
+
precision = valueString.length - dotPosition - 1;
|
|
207
|
+
}
|
|
208
|
+
return precision;
|
|
209
|
+
},
|
|
210
|
+
_increase(val, step) {
|
|
211
|
+
if (typeof val !== 'number' && val !== undefined) return this.currentValue;
|
|
212
|
+
|
|
213
|
+
const precisionFactor = Math.pow(10, this.numPrecision);
|
|
214
|
+
// Solve the accuracy problem of JS decimal calculation by converting the value to integer.
|
|
215
|
+
return this.toPrecision((precisionFactor * val + precisionFactor * step) / precisionFactor);
|
|
216
|
+
},
|
|
217
|
+
_decrease(val, step) {
|
|
218
|
+
if (typeof val !== 'number' && val !== undefined) return this.currentValue;
|
|
219
|
+
|
|
220
|
+
const precisionFactor = Math.pow(10, this.numPrecision);
|
|
221
|
+
|
|
222
|
+
return this.toPrecision((precisionFactor * val - precisionFactor * step) / precisionFactor);
|
|
223
|
+
},
|
|
224
|
+
increase() {
|
|
225
|
+
if (this.inputNumberDisabled || this.maxDisabled) return;
|
|
226
|
+
const value = this.value || 0;
|
|
227
|
+
const newVal = this._increase(value, this.step);
|
|
228
|
+
this.setCurrentValue(newVal);
|
|
229
|
+
},
|
|
230
|
+
decrease() {
|
|
231
|
+
if (this.inputNumberDisabled || this.minDisabled) return;
|
|
232
|
+
const value = this.value || 0;
|
|
233
|
+
const newVal = this._decrease(value, this.step);
|
|
234
|
+
this.setCurrentValue(newVal);
|
|
235
|
+
},
|
|
236
|
+
handleBlur(event) {
|
|
237
|
+
this.$emit('blur', event);
|
|
238
|
+
},
|
|
239
|
+
handleFocus(event) {
|
|
240
|
+
this.$emit('focus', event);
|
|
241
|
+
},
|
|
242
|
+
setCurrentValue(newVal) {
|
|
243
|
+
const oldVal = this.currentValue;
|
|
244
|
+
if (typeof newVal === 'number' && this.precision !== undefined) {
|
|
245
|
+
newVal = this.toPrecision(newVal, this.precision);
|
|
246
|
+
}
|
|
247
|
+
if (newVal >= this.max) newVal = this.max;
|
|
248
|
+
if (newVal <= this.min) newVal = this.min;
|
|
249
|
+
if (oldVal === newVal) return;
|
|
250
|
+
this.userInput = null;
|
|
251
|
+
this.$emit('input', newVal);
|
|
252
|
+
this.$emit('change', newVal, oldVal);
|
|
253
|
+
this.currentValue = newVal;
|
|
254
|
+
},
|
|
255
|
+
handleInput(value) {
|
|
256
|
+
this.userInput = value;
|
|
257
|
+
},
|
|
258
|
+
handleInputChange(value) {
|
|
259
|
+
const newVal = value === '' ? undefined : Number(value);
|
|
260
|
+
if (!isNaN(newVal) || value === '') {
|
|
261
|
+
this.setCurrentValue(newVal);
|
|
262
|
+
}
|
|
263
|
+
this.userInput = null;
|
|
264
|
+
},
|
|
265
|
+
select() {
|
|
266
|
+
this.$refs.input.select();
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
mounted() {
|
|
270
|
+
let innerInput = this.$refs.input.$refs.input;
|
|
271
|
+
innerInput.setAttribute('role', 'spinbutton');
|
|
272
|
+
innerInput.setAttribute('aria-valuemax', this.max);
|
|
273
|
+
innerInput.setAttribute('aria-valuemin', this.min);
|
|
274
|
+
innerInput.setAttribute('aria-valuenow', this.currentValue);
|
|
275
|
+
innerInput.setAttribute('aria-disabled', this.inputNumberDisabled);
|
|
276
|
+
},
|
|
277
|
+
updated() {
|
|
278
|
+
if (!this.$refs || !this.$refs.input) return;
|
|
279
|
+
const innerInput = this.$refs.input.$refs.input;
|
|
280
|
+
innerInput.setAttribute('aria-valuenow', this.currentValue);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
</script>
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
'el-link',
|
|
5
5
|
type ? `el-link--${type}` : '',
|
|
6
6
|
size ? `el-link--${size}` : '',
|
|
7
|
+
text ? `is-text` : '',
|
|
7
8
|
disabled && 'is-disabled',
|
|
8
9
|
underline && !disabled && 'is-underline'
|
|
9
10
|
]"
|
|
@@ -39,6 +40,7 @@ export default {
|
|
|
39
40
|
disabled: Boolean,
|
|
40
41
|
href: String,
|
|
41
42
|
icon: String,
|
|
43
|
+
text: Boolean,
|
|
42
44
|
size: {
|
|
43
45
|
type: String,
|
|
44
46
|
default: 'small'
|