7fa943eb
梁灏
init
|
1
|
<template>
|
7d5431d8
梁灏
update some style
|
2
|
<div :class="wrapClasses">
|
0f822c9b
梁灏
add Input component
|
3
|
<template v-if="type !== 'textarea'">
|
319f5f86
梁灏
fixed #554
|
4
|
<div :class="[prefixCls + '-group-prepend']" v-if="prepend" v-show="slotReady"><slot name="prepend"></slot></div>
|
a73ae72b
梁灏
fixed #2884
|
5
6
|
<i class="ivu-icon" :class="['ivu-icon-ios-close', prefixCls + '-icon', prefixCls + '-icon-clear' , prefixCls + '-icon-normal']" v-if="clearable" @click="handleClear"></i>
<i class="ivu-icon" :class="['ivu-icon-' + icon, prefixCls + '-icon', prefixCls + '-icon-normal']" v-else-if="icon" @click="handleIconClick"></i>
|
fc7ef072
梁灏
support Input
|
7
8
9
|
<transition name="fade">
<i class="ivu-icon ivu-icon-load-c ivu-load-loop" :class="[prefixCls + '-icon', prefixCls + '-icon-validate']" v-if="!icon"></i>
</transition>
|
0f822c9b
梁灏
add Input component
|
10
|
<input
|
acb79ba3
梁灏
fixed #433
|
11
|
:id="elementId"
|
9968ddea
zero
Input increase au...
|
12
|
:autocomplete="autocomplete"
|
c17c5ad6
Sergio Crisostomo
normalize autocom...
|
13
|
:spellcheck="spellcheck"
|
545add71
yinheli
input 支持 focus 方法
|
14
|
ref="input"
|
6c145a04
梁灏
fixed #77
|
15
|
:type="type"
|
0f822c9b
梁灏
add Input component
|
16
17
18
19
|
:class="inputClasses"
:placeholder="placeholder"
:disabled="disabled"
:maxlength="maxlength"
|
0a48ac45
梁灏
Input add readonl...
|
20
|
:readonly="readonly"
|
731d69a2
梁灏
fixed #101
|
21
|
:name="name"
|
fc7ef072
梁灏
support Input
|
22
|
:value="currentValue"
|
c3a9f389
梁灏
update Input
|
23
|
:number="number"
|
f15c216a
丁强
Input 组件增加autofoc...
|
24
|
:autofocus="autofocus"
|
0a48ac45
梁灏
Input add readonl...
|
25
|
@keyup.enter="handleEnter"
|
9e7a3740
xingbofeng
fix: add keyup, k...
|
26
27
28
|
@keyup="handleKeyup"
@keypress="handleKeypress"
@keydown="handleKeydown"
|
0a48ac45
梁灏
Input add readonl...
|
29
|
@focus="handleFocus"
|
c46f385a
梁灏
update DatePicker
|
30
|
@blur="handleBlur"
|
531cd165
梁灏
support DatePicke...
|
31
32
|
@input="handleInput"
@change="handleChange">
|
319f5f86
梁灏
fixed #554
|
33
|
<div :class="[prefixCls + '-group-append']" v-if="append" v-show="slotReady"><slot name="append"></slot></div>
|
0f822c9b
梁灏
add Input component
|
34
35
|
</template>
<textarea
|
0f822c9b
梁灏
add Input component
|
36
|
v-else
|
acb79ba3
梁灏
fixed #433
|
37
38
|
:id="elementId"
:autocomplete="autocomplete"
|
c17c5ad6
Sergio Crisostomo
normalize autocom...
|
39
|
:spellcheck="spellcheck"
|
fc7ef072
梁灏
support Input
|
40
|
ref="textarea"
|
0f822c9b
梁灏
add Input component
|
41
42
|
:class="textareaClasses"
:style="textareaStyles"
|
7d5431d8
梁灏
update some style
|
43
|
:placeholder="placeholder"
|
0f822c9b
梁灏
add Input component
|
44
45
46
|
:disabled="disabled"
:rows="rows"
:maxlength="maxlength"
|
0a48ac45
梁灏
Input add readonl...
|
47
|
:readonly="readonly"
|
731d69a2
梁灏
fixed #101
|
48
|
:name="name"
|
a2f27a80
Lawrence Lee
fix #1084
|
49
|
:value="currentValue"
|
67a87e8d
Aresn
fixed #1017
|
50
|
:autofocus="autofocus"
|
0a48ac45
梁灏
Input add readonl...
|
51
|
@keyup.enter="handleEnter"
|
9e7a3740
xingbofeng
fix: add keyup, k...
|
52
53
54
|
@keyup="handleKeyup"
@keypress="handleKeypress"
@keydown="handleKeydown"
|
0a48ac45
梁灏
Input add readonl...
|
55
|
@focus="handleFocus"
|
c46f385a
梁灏
update DatePicker
|
56
|
@blur="handleBlur"
|
fc7ef072
梁灏
support Input
|
57
|
@input="handleInput">
|
0f822c9b
梁灏
add Input component
|
58
|
</textarea>
|
7d5431d8
梁灏
update some style
|
59
|
</div>
|
7fa943eb
梁灏
init
|
60
61
|
</template>
<script>
|
21dad188
梁灏
prevent dispatch ...
|
62
|
import { oneOf, findComponentUpward } from '../../utils/assist';
|
0f822c9b
梁灏
add Input component
|
63
|
import calcTextareaHeight from '../../utils/calcTextareaHeight';
|
cd78c9c4
梁灏
some comps suppor...
|
64
|
import Emitter from '../../mixins/emitter';
|
7fa943eb
梁灏
init
|
65
66
67
68
|
const prefixCls = 'ivu-input';
export default {
|
06322514
梁灏
support Radio
|
69
|
name: 'Input',
|
cd78c9c4
梁灏
some comps suppor...
|
70
|
mixins: [ Emitter ],
|
7fa943eb
梁灏
init
|
71
72
|
props: {
type: {
|
0f822c9b
梁灏
add Input component
|
73
|
validator (value) {
|
9bd074d4
Hsiaoming Yang
Support more type...
|
74
|
return oneOf(value, ['text', 'textarea', 'password', 'url', 'email', 'date']);
|
0f822c9b
梁灏
add Input component
|
75
|
},
|
7fa943eb
梁灏
init
|
76
77
78
79
|
default: 'text'
},
value: {
type: [String, Number],
|
fc7ef072
梁灏
support Input
|
80
|
default: ''
|
7fa943eb
梁灏
init
|
81
|
},
|
7fa943eb
梁灏
init
|
82
83
|
size: {
validator (value) {
|
b6bda1dc
梁灏
update ColorPicker
|
84
|
return oneOf(value, ['small', 'large', 'default']);
|
7fa943eb
梁灏
init
|
85
|
}
|
0f822c9b
梁灏
add Input component
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
},
placeholder: {
type: String,
default: ''
},
maxlength: {
type: Number
},
disabled: {
type: Boolean,
default: false
},
icon: String,
autosize: {
type: [Boolean, Object],
default: false
},
rows: {
type: Number,
default: 2
|
0a48ac45
梁灏
Input add readonl...
|
106
107
108
109
|
},
readonly: {
type: Boolean,
default: false
|
731d69a2
梁灏
fixed #101
|
110
111
112
|
},
name: {
type: String
|
c3a9f389
梁灏
update Input
|
113
114
115
116
|
},
number: {
type: Boolean,
default: false
|
f15c216a
丁强
Input 组件增加autofoc...
|
117
118
|
},
autofocus: {
|
8d3a02a5
丁强
修改input组件 autofoc...
|
119
120
|
type: Boolean,
default: false
|
9968ddea
zero
Input increase au...
|
121
|
},
|
c17c5ad6
Sergio Crisostomo
normalize autocom...
|
122
123
124
125
|
spellcheck: {
type: Boolean,
default: false
},
|
9968ddea
zero
Input increase au...
|
126
|
autocomplete: {
|
41918ed8
梁灏
update Input
|
127
128
129
|
validator (value) {
return oneOf(value, ['on', 'off']);
},
|
9968ddea
zero
Input increase au...
|
130
|
default: 'off'
|
acb79ba3
梁灏
fixed #433
|
131
|
},
|
a73ae72b
梁灏
fixed #2884
|
132
133
134
135
|
clearable: {
type: Boolean,
default: false
},
|
acb79ba3
梁灏
fixed #433
|
136
137
|
elementId: {
type: String
|
7fa943eb
梁灏
init
|
138
139
140
141
|
}
},
data () {
return {
|
fc7ef072
梁灏
support Input
|
142
|
currentValue: this.value,
|
0f822c9b
梁灏
add Input component
|
143
144
145
|
prefixCls: prefixCls,
prepend: true,
append: true,
|
6ff31952
梁灏
optimize Input sh...
|
146
|
slotReady: false,
|
0f822c9b
梁灏
add Input component
|
147
|
textareaStyles: {}
|
b0893113
jingsam
add eslint
|
148
|
};
|
7fa943eb
梁灏
init
|
149
150
|
},
computed: {
|
7d5431d8
梁灏
update some style
|
151
|
wrapClasses () {
|
0f822c9b
梁灏
add Input component
|
152
153
154
|
return [
`${prefixCls}-wrapper`,
{
|
12418c6a
梁灏
fixed #74
|
155
|
[`${prefixCls}-wrapper-${this.size}`]: !!this.size,
|
0f822c9b
梁灏
add Input component
|
156
157
|
[`${prefixCls}-type`]: this.type,
[`${prefixCls}-group`]: this.prepend || this.append,
|
f4e462c0
梁灏
#554
|
158
|
[`${prefixCls}-group-${this.size}`]: (this.prepend || this.append) && !!this.size,
|
e2affe49
梁灏
fixed #397
|
159
160
|
[`${prefixCls}-group-with-prepend`]: this.prepend,
[`${prefixCls}-group-with-append`]: this.append,
|
f4e462c0
梁灏
#554
|
161
|
[`${prefixCls}-hide-icon`]: this.append // #554
|
0f822c9b
梁灏
add Input component
|
162
|
}
|
b0893113
jingsam
add eslint
|
163
|
];
|
0f822c9b
梁灏
add Input component
|
164
165
166
167
168
169
170
171
|
},
inputClasses () {
return [
`${prefixCls}`,
{
[`${prefixCls}-${this.size}`]: !!this.size,
[`${prefixCls}-disabled`]: this.disabled
}
|
b0893113
jingsam
add eslint
|
172
|
];
|
7d5431d8
梁灏
update some style
|
173
|
},
|
0f822c9b
梁灏
add Input component
|
174
|
textareaClasses () {
|
7fa943eb
梁灏
init
|
175
176
177
|
return [
`${prefixCls}`,
{
|
0f822c9b
梁灏
add Input component
|
178
|
[`${prefixCls}-disabled`]: this.disabled
|
7fa943eb
梁灏
init
|
179
|
}
|
b0893113
jingsam
add eslint
|
180
|
];
|
7fa943eb
梁灏
init
|
181
|
}
|
0f822c9b
梁灏
add Input component
|
182
183
|
},
methods: {
|
cd50d0d6
young
fix(input): all a...
|
184
185
|
handleEnter (event) {
this.$emit('on-enter', event);
|
0f822c9b
梁灏
add Input component
|
186
|
},
|
9e7a3740
xingbofeng
fix: add keyup, k...
|
187
188
189
190
191
192
193
194
195
|
handleKeydown (event) {
this.$emit('on-keydown', event);
},
handleKeypress(event) {
this.$emit('on-keypress', event);
},
handleKeyup (event) {
this.$emit('on-keyup', event);
},
|
cd50d0d6
young
fix(input): all a...
|
196
197
|
handleIconClick (event) {
this.$emit('on-click', event);
|
0f822c9b
梁灏
add Input component
|
198
|
},
|
cd50d0d6
young
fix(input): all a...
|
199
200
|
handleFocus (event) {
this.$emit('on-focus', event);
|
0a48ac45
梁灏
Input add readonl...
|
201
|
},
|
cd50d0d6
young
fix(input): all a...
|
202
|
handleBlur (event) {
|
57737d74
muei
Update input.vue
|
203
|
this.$emit('on-blur', event);
|
aa9fc758
梁灏
update Transfer
|
204
|
if (!findComponentUpward(this, ['DatePicker', 'TimePicker', 'Cascader', 'Search'])) {
|
21dad188
梁灏
prevent dispatch ...
|
205
206
|
this.dispatch('FormItem', 'on-form-blur', this.currentValue);
}
|
0a48ac45
梁灏
Input add readonl...
|
207
|
},
|
fc7ef072
梁灏
support Input
|
208
|
handleInput (event) {
|
85ed4df8
梁灏
fixed Input bug
|
209
210
|
let value = event.target.value;
if (this.number) value = Number.isNaN(Number(value)) ? value : Number(value);
|
fc7ef072
梁灏
support Input
|
211
212
|
this.$emit('input', value);
this.setCurrentValue(value);
|
e1874103
梁灏
update DatePicker
|
213
|
this.$emit('on-change', event);
|
c46f385a
梁灏
update DatePicker
|
214
|
},
|
531cd165
梁灏
support DatePicke...
|
215
216
217
|
handleChange (event) {
this.$emit('on-input-change', event);
},
|
fc7ef072
梁灏
support Input
|
218
219
220
221
222
223
|
setCurrentValue (value) {
if (value === this.currentValue) return;
this.$nextTick(() => {
this.resizeTextarea();
});
this.currentValue = value;
|
aa9fc758
梁灏
update Transfer
|
224
|
if (!findComponentUpward(this, ['DatePicker', 'TimePicker', 'Cascader', 'Search'])) {
|
21dad188
梁灏
prevent dispatch ...
|
225
226
|
this.dispatch('FormItem', 'on-form-change', value);
}
|
fc7ef072
梁灏
support Input
|
227
|
},
|
0f822c9b
梁灏
add Input component
|
228
229
230
231
232
233
234
235
236
|
resizeTextarea () {
const autosize = this.autosize;
if (!autosize || this.type !== 'textarea') {
return false;
}
const minRows = autosize.minRows;
const maxRows = autosize.maxRows;
|
fc7ef072
梁灏
support Input
|
237
|
this.textareaStyles = calcTextareaHeight(this.$refs.textarea, minRows, maxRows);
|
545add71
yinheli
input 支持 focus 方法
|
238
|
},
|
fed3e09d
梁灏
add AutoComplete ...
|
239
|
focus () {
|
545add71
yinheli
input 支持 focus 方法
|
240
241
242
243
244
|
if (this.type === 'textarea') {
this.$refs.textarea.focus();
} else {
this.$refs.input.focus();
}
|
fed3e09d
梁灏
add AutoComplete ...
|
245
246
247
248
249
250
251
|
},
blur () {
if (this.type === 'textarea') {
this.$refs.textarea.blur();
} else {
this.$refs.input.blur();
}
|
a73ae72b
梁灏
fixed #2884
|
252
253
254
255
256
257
|
},
handleClear () {
const e = { target: { value: '' } };
this.$emit('input', '');
this.setCurrentValue('');
this.$emit('on-change', e);
|
0f822c9b
梁灏
add Input component
|
258
259
260
|
}
},
watch: {
|
fc7ef072
梁灏
support Input
|
261
262
|
value (val) {
this.setCurrentValue(val);
|
0f822c9b
梁灏
add Input component
|
263
264
|
}
},
|
fc7ef072
梁灏
support Input
|
265
266
267
268
269
270
271
272
273
274
|
mounted () {
if (this.type !== 'textarea') {
this.prepend = this.$slots.prepend !== undefined;
this.append = this.$slots.append !== undefined;
} else {
this.prepend = false;
this.append = false;
}
this.slotReady = true;
this.resizeTextarea();
|
7fa943eb
梁灏
init
|
275
|
}
|
b0893113
jingsam
add eslint
|
276
277
|
};
</script>
|