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>
|
ef090131
梁灏
optimize Input va...
|
5
|
<i class="ivu-icon" :class="['ivu-icon-' + icon, prefixCls + '-icon', prefixCls + '-icon-normal']" v-if="icon" @click="handleIconClick"></i>
|
fc7ef072
梁灏
support Input
|
6
7
8
|
<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
|
9
|
<input
|
545add71
yinheli
input 支持 focus 方法
|
10
|
ref="input"
|
6c145a04
梁灏
fixed #77
|
11
|
:type="type"
|
0f822c9b
梁灏
add Input component
|
12
13
14
15
|
:class="inputClasses"
:placeholder="placeholder"
:disabled="disabled"
:maxlength="maxlength"
|
0a48ac45
梁灏
Input add readonl...
|
16
|
:readonly="readonly"
|
731d69a2
梁灏
fixed #101
|
17
|
:name="name"
|
fc7ef072
梁灏
support Input
|
18
|
:value="currentValue"
|
c3a9f389
梁灏
update Input
|
19
|
:number="number"
|
f15c216a
丁强
Input 组件增加autofoc...
|
20
|
:autofocus="autofocus"
|
0a48ac45
梁灏
Input add readonl...
|
21
22
|
@keyup.enter="handleEnter"
@focus="handleFocus"
|
c46f385a
梁灏
update DatePicker
|
23
|
@blur="handleBlur"
|
531cd165
梁灏
support DatePicke...
|
24
25
|
@input="handleInput"
@change="handleChange">
|
319f5f86
梁灏
fixed #554
|
26
|
<div :class="[prefixCls + '-group-append']" v-if="append" v-show="slotReady"><slot name="append"></slot></div>
|
0f822c9b
梁灏
add Input component
|
27
28
29
|
</template>
<textarea
v-else
|
fc7ef072
梁灏
support Input
|
30
|
ref="textarea"
|
0f822c9b
梁灏
add Input component
|
31
32
|
:class="textareaClasses"
:style="textareaStyles"
|
7d5431d8
梁灏
update some style
|
33
|
:placeholder="placeholder"
|
0f822c9b
梁灏
add Input component
|
34
35
36
|
:disabled="disabled"
:rows="rows"
:maxlength="maxlength"
|
0a48ac45
梁灏
Input add readonl...
|
37
|
:readonly="readonly"
|
731d69a2
梁灏
fixed #101
|
38
|
:name="name"
|
fc7ef072
梁灏
support Input
|
39
|
:value="value"
|
67a87e8d
Aresn
fixed #1017
|
40
|
:autofocus="autofocus"
|
0a48ac45
梁灏
Input add readonl...
|
41
42
|
@keyup.enter="handleEnter"
@focus="handleFocus"
|
c46f385a
梁灏
update DatePicker
|
43
|
@blur="handleBlur"
|
fc7ef072
梁灏
support Input
|
44
|
@input="handleInput">
|
0f822c9b
梁灏
add Input component
|
45
|
</textarea>
|
7d5431d8
梁灏
update some style
|
46
|
</div>
|
7fa943eb
梁灏
init
|
47
48
|
</template>
<script>
|
21dad188
梁灏
prevent dispatch ...
|
49
|
import { oneOf, findComponentUpward } from '../../utils/assist';
|
0f822c9b
梁灏
add Input component
|
50
|
import calcTextareaHeight from '../../utils/calcTextareaHeight';
|
cd78c9c4
梁灏
some comps suppor...
|
51
|
import Emitter from '../../mixins/emitter';
|
7fa943eb
梁灏
init
|
52
53
54
55
|
const prefixCls = 'ivu-input';
export default {
|
06322514
梁灏
support Radio
|
56
|
name: 'Input',
|
cd78c9c4
梁灏
some comps suppor...
|
57
|
mixins: [ Emitter ],
|
7fa943eb
梁灏
init
|
58
59
|
props: {
type: {
|
0f822c9b
梁灏
add Input component
|
60
|
validator (value) {
|
6c145a04
梁灏
fixed #77
|
61
|
return oneOf(value, ['text', 'textarea', 'password']);
|
0f822c9b
梁灏
add Input component
|
62
|
},
|
7fa943eb
梁灏
init
|
63
64
65
66
|
default: 'text'
},
value: {
type: [String, Number],
|
fc7ef072
梁灏
support Input
|
67
|
default: ''
|
7fa943eb
梁灏
init
|
68
|
},
|
7fa943eb
梁灏
init
|
69
70
71
72
|
size: {
validator (value) {
return oneOf(value, ['small', 'large']);
}
|
0f822c9b
梁灏
add Input component
|
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
},
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...
|
93
94
95
96
|
},
readonly: {
type: Boolean,
default: false
|
731d69a2
梁灏
fixed #101
|
97
98
99
|
},
name: {
type: String
|
c3a9f389
梁灏
update Input
|
100
101
102
103
|
},
number: {
type: Boolean,
default: false
|
f15c216a
丁强
Input 组件增加autofoc...
|
104
105
|
},
autofocus: {
|
8d3a02a5
丁强
修改input组件 autofoc...
|
106
107
|
type: Boolean,
default: false
|
7fa943eb
梁灏
init
|
108
109
110
111
|
}
},
data () {
return {
|
fc7ef072
梁灏
support Input
|
112
|
currentValue: this.value,
|
0f822c9b
梁灏
add Input component
|
113
114
115
|
prefixCls: prefixCls,
prepend: true,
append: true,
|
6ff31952
梁灏
optimize Input sh...
|
116
|
slotReady: false,
|
0f822c9b
梁灏
add Input component
|
117
|
textareaStyles: {}
|
b0893113
jingsam
add eslint
|
118
|
};
|
7fa943eb
梁灏
init
|
119
120
|
},
computed: {
|
7d5431d8
梁灏
update some style
|
121
|
wrapClasses () {
|
0f822c9b
梁灏
add Input component
|
122
123
124
|
return [
`${prefixCls}-wrapper`,
{
|
12418c6a
梁灏
fixed #74
|
125
|
[`${prefixCls}-wrapper-${this.size}`]: !!this.size,
|
0f822c9b
梁灏
add Input component
|
126
127
|
[`${prefixCls}-type`]: this.type,
[`${prefixCls}-group`]: this.prepend || this.append,
|
f4e462c0
梁灏
#554
|
128
|
[`${prefixCls}-group-${this.size}`]: (this.prepend || this.append) && !!this.size,
|
e2affe49
梁灏
fixed #397
|
129
130
|
[`${prefixCls}-group-with-prepend`]: this.prepend,
[`${prefixCls}-group-with-append`]: this.append,
|
f4e462c0
梁灏
#554
|
131
|
[`${prefixCls}-hide-icon`]: this.append // #554
|
0f822c9b
梁灏
add Input component
|
132
|
}
|
b0893113
jingsam
add eslint
|
133
|
];
|
0f822c9b
梁灏
add Input component
|
134
135
136
137
138
139
140
141
|
},
inputClasses () {
return [
`${prefixCls}`,
{
[`${prefixCls}-${this.size}`]: !!this.size,
[`${prefixCls}-disabled`]: this.disabled
}
|
b0893113
jingsam
add eslint
|
142
|
];
|
7d5431d8
梁灏
update some style
|
143
|
},
|
0f822c9b
梁灏
add Input component
|
144
|
textareaClasses () {
|
7fa943eb
梁灏
init
|
145
146
147
|
return [
`${prefixCls}`,
{
|
0f822c9b
梁灏
add Input component
|
148
|
[`${prefixCls}-disabled`]: this.disabled
|
7fa943eb
梁灏
init
|
149
|
}
|
b0893113
jingsam
add eslint
|
150
|
];
|
7fa943eb
梁灏
init
|
151
|
}
|
0f822c9b
梁灏
add Input component
|
152
153
|
},
methods: {
|
cd50d0d6
young
fix(input): all a...
|
154
155
|
handleEnter (event) {
this.$emit('on-enter', event);
|
0f822c9b
梁灏
add Input component
|
156
|
},
|
cd50d0d6
young
fix(input): all a...
|
157
158
|
handleIconClick (event) {
this.$emit('on-click', event);
|
0f822c9b
梁灏
add Input component
|
159
|
},
|
cd50d0d6
young
fix(input): all a...
|
160
161
|
handleFocus (event) {
this.$emit('on-focus', event);
|
0a48ac45
梁灏
Input add readonl...
|
162
|
},
|
cd50d0d6
young
fix(input): all a...
|
163
|
handleBlur (event) {
|
57737d74
muei
Update input.vue
|
164
|
this.$emit('on-blur', event);
|
aa9fc758
梁灏
update Transfer
|
165
|
if (!findComponentUpward(this, ['DatePicker', 'TimePicker', 'Cascader', 'Search'])) {
|
21dad188
梁灏
prevent dispatch ...
|
166
167
|
this.dispatch('FormItem', 'on-form-blur', this.currentValue);
}
|
0a48ac45
梁灏
Input add readonl...
|
168
|
},
|
fc7ef072
梁灏
support Input
|
169
|
handleInput (event) {
|
85ed4df8
梁灏
fixed Input bug
|
170
171
|
let value = event.target.value;
if (this.number) value = Number.isNaN(Number(value)) ? value : Number(value);
|
fc7ef072
梁灏
support Input
|
172
173
|
this.$emit('input', value);
this.setCurrentValue(value);
|
e1874103
梁灏
update DatePicker
|
174
|
this.$emit('on-change', event);
|
c46f385a
梁灏
update DatePicker
|
175
|
},
|
531cd165
梁灏
support DatePicke...
|
176
177
178
|
handleChange (event) {
this.$emit('on-input-change', event);
},
|
fc7ef072
梁灏
support Input
|
179
180
181
182
183
184
|
setCurrentValue (value) {
if (value === this.currentValue) return;
this.$nextTick(() => {
this.resizeTextarea();
});
this.currentValue = value;
|
aa9fc758
梁灏
update Transfer
|
185
|
if (!findComponentUpward(this, ['DatePicker', 'TimePicker', 'Cascader', 'Search'])) {
|
21dad188
梁灏
prevent dispatch ...
|
186
187
|
this.dispatch('FormItem', 'on-form-change', value);
}
|
fc7ef072
梁灏
support Input
|
188
|
},
|
0f822c9b
梁灏
add Input component
|
189
190
191
192
193
194
195
196
197
|
resizeTextarea () {
const autosize = this.autosize;
if (!autosize || this.type !== 'textarea') {
return false;
}
const minRows = autosize.minRows;
const maxRows = autosize.maxRows;
|
fc7ef072
梁灏
support Input
|
198
|
this.textareaStyles = calcTextareaHeight(this.$refs.textarea, minRows, maxRows);
|
545add71
yinheli
input 支持 focus 方法
|
199
200
201
202
203
204
205
|
},
focus() {
if (this.type === 'textarea') {
this.$refs.textarea.focus();
} else {
this.$refs.input.focus();
}
|
0f822c9b
梁灏
add Input component
|
206
207
208
|
}
},
watch: {
|
fc7ef072
梁灏
support Input
|
209
210
|
value (val) {
this.setCurrentValue(val);
|
0f822c9b
梁灏
add Input component
|
211
212
|
}
},
|
fc7ef072
梁灏
support Input
|
213
214
215
216
217
218
219
220
221
222
|
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
|
223
|
}
|
b0893113
jingsam
add eslint
|
224
225
|
};
</script>
|