7fa943eb
梁灏
init
|
1
|
<template>
|
7d5431d8
梁灏
update some style
|
2
|
<div :class="wrapClasses">
|
0f822c9b
梁灏
add Input component
|
3
|
<template v-if="type !== 'textarea'">
|
fc7ef072
梁灏
support Input
|
4
|
<div :class="[prefixCls + '-group-prepend']" v-if="prepend" v-show="slotReady" ref="prepend"><slot name="prepend"></slot></div>
|
0f822c9b
梁灏
add Input component
|
5
|
<i class="ivu-icon" :class="['ivu-icon-' + icon, prefixCls + '-icon']" 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
|
6c145a04
梁灏
fixed #77
|
10
|
:type="type"
|
0f822c9b
梁灏
add Input component
|
11
12
13
14
|
:class="inputClasses"
:placeholder="placeholder"
:disabled="disabled"
:maxlength="maxlength"
|
0a48ac45
梁灏
Input add readonl...
|
15
|
:readonly="readonly"
|
731d69a2
梁灏
fixed #101
|
16
|
:name="name"
|
fc7ef072
梁灏
support Input
|
17
|
:value="currentValue"
|
c3a9f389
梁灏
update Input
|
18
|
:number="number"
|
0a48ac45
梁灏
Input add readonl...
|
19
20
|
@keyup.enter="handleEnter"
@focus="handleFocus"
|
c46f385a
梁灏
update DatePicker
|
21
|
@blur="handleBlur"
|
531cd165
梁灏
support DatePicke...
|
22
23
|
@input="handleInput"
@change="handleChange">
|
fc7ef072
梁灏
support Input
|
24
|
<div :class="[prefixCls + '-group-append']" v-if="append" v-show="slotReady" ref="append"><slot name="append"></slot></div>
|
0f822c9b
梁灏
add Input component
|
25
26
27
|
</template>
<textarea
v-else
|
fc7ef072
梁灏
support Input
|
28
|
ref="textarea"
|
0f822c9b
梁灏
add Input component
|
29
30
|
:class="textareaClasses"
:style="textareaStyles"
|
7d5431d8
梁灏
update some style
|
31
|
:placeholder="placeholder"
|
0f822c9b
梁灏
add Input component
|
32
33
34
|
:disabled="disabled"
:rows="rows"
:maxlength="maxlength"
|
0a48ac45
梁灏
Input add readonl...
|
35
|
:readonly="readonly"
|
731d69a2
梁灏
fixed #101
|
36
|
:name="name"
|
fc7ef072
梁灏
support Input
|
37
|
:value="value"
|
0a48ac45
梁灏
Input add readonl...
|
38
39
|
@keyup.enter="handleEnter"
@focus="handleFocus"
|
c46f385a
梁灏
update DatePicker
|
40
|
@blur="handleBlur"
|
fc7ef072
梁灏
support Input
|
41
|
@input="handleInput">
|
0f822c9b
梁灏
add Input component
|
42
|
</textarea>
|
7d5431d8
梁灏
update some style
|
43
|
</div>
|
7fa943eb
梁灏
init
|
44
45
46
|
</template>
<script>
import { oneOf } from '../../utils/assist';
|
0f822c9b
梁灏
add Input component
|
47
|
import calcTextareaHeight from '../../utils/calcTextareaHeight';
|
7fa943eb
梁灏
init
|
48
49
50
51
|
const prefixCls = 'ivu-input';
export default {
|
06322514
梁灏
support Radio
|
52
|
name: 'Input',
|
7fa943eb
梁灏
init
|
53
54
|
props: {
type: {
|
0f822c9b
梁灏
add Input component
|
55
|
validator (value) {
|
6c145a04
梁灏
fixed #77
|
56
|
return oneOf(value, ['text', 'textarea', 'password']);
|
0f822c9b
梁灏
add Input component
|
57
|
},
|
7fa943eb
梁灏
init
|
58
59
60
61
|
default: 'text'
},
value: {
type: [String, Number],
|
fc7ef072
梁灏
support Input
|
62
|
default: ''
|
7fa943eb
梁灏
init
|
63
|
},
|
7fa943eb
梁灏
init
|
64
65
66
67
|
size: {
validator (value) {
return oneOf(value, ['small', 'large']);
}
|
0f822c9b
梁灏
add Input component
|
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
},
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...
|
88
89
90
91
|
},
readonly: {
type: Boolean,
default: false
|
731d69a2
梁灏
fixed #101
|
92
93
94
|
},
name: {
type: String
|
c3a9f389
梁灏
update Input
|
95
96
97
98
|
},
number: {
type: Boolean,
default: false
|
7fa943eb
梁灏
init
|
99
100
101
102
|
}
},
data () {
return {
|
fc7ef072
梁灏
support Input
|
103
|
currentValue: this.value,
|
0f822c9b
梁灏
add Input component
|
104
105
106
|
prefixCls: prefixCls,
prepend: true,
append: true,
|
6ff31952
梁灏
optimize Input sh...
|
107
|
slotReady: false,
|
0f822c9b
梁灏
add Input component
|
108
|
textareaStyles: {}
|
b0893113
jingsam
add eslint
|
109
|
};
|
7fa943eb
梁灏
init
|
110
111
|
},
computed: {
|
7d5431d8
梁灏
update some style
|
112
|
wrapClasses () {
|
0f822c9b
梁灏
add Input component
|
113
114
115
|
return [
`${prefixCls}-wrapper`,
{
|
12418c6a
梁灏
fixed #74
|
116
|
[`${prefixCls}-wrapper-${this.size}`]: !!this.size,
|
0f822c9b
梁灏
add Input component
|
117
118
119
120
|
[`${prefixCls}-type`]: this.type,
[`${prefixCls}-group`]: this.prepend || this.append,
[`${prefixCls}-group-${this.size}`]: (this.prepend || this.append) && !!this.size
}
|
b0893113
jingsam
add eslint
|
121
|
];
|
0f822c9b
梁灏
add Input component
|
122
123
124
125
126
127
128
129
|
},
inputClasses () {
return [
`${prefixCls}`,
{
[`${prefixCls}-${this.size}`]: !!this.size,
[`${prefixCls}-disabled`]: this.disabled
}
|
b0893113
jingsam
add eslint
|
130
|
];
|
7d5431d8
梁灏
update some style
|
131
|
},
|
0f822c9b
梁灏
add Input component
|
132
|
textareaClasses () {
|
7fa943eb
梁灏
init
|
133
134
135
|
return [
`${prefixCls}`,
{
|
0f822c9b
梁灏
add Input component
|
136
|
[`${prefixCls}-disabled`]: this.disabled
|
7fa943eb
梁灏
init
|
137
|
}
|
b0893113
jingsam
add eslint
|
138
|
];
|
7fa943eb
梁灏
init
|
139
|
}
|
0f822c9b
梁灏
add Input component
|
140
141
142
143
144
145
146
147
|
},
methods: {
handleEnter () {
this.$emit('on-enter');
},
handleIconClick () {
this.$emit('on-click');
},
|
0a48ac45
梁灏
Input add readonl...
|
148
149
150
151
152
|
handleFocus () {
this.$emit('on-focus');
},
handleBlur () {
this.$emit('on-blur');
|
fc7ef072
梁灏
support Input
|
153
154
|
// todo 事件
// this.$dispatch('on-form-blur', this.currentValue);
|
0a48ac45
梁灏
Input add readonl...
|
155
|
},
|
fc7ef072
梁灏
support Input
|
156
157
158
159
|
handleInput (event) {
const value = event.target.value;
this.$emit('input', value);
this.setCurrentValue(value);
|
e1874103
梁灏
update DatePicker
|
160
|
this.$emit('on-change', event);
|
c46f385a
梁灏
update DatePicker
|
161
|
},
|
531cd165
梁灏
support DatePicke...
|
162
163
164
|
handleChange (event) {
this.$emit('on-input-change', event);
},
|
fc7ef072
梁灏
support Input
|
165
166
167
168
169
170
171
172
173
|
setCurrentValue (value) {
if (value === this.currentValue) return;
this.$nextTick(() => {
this.resizeTextarea();
});
this.currentValue = value;
// todo 事件
// this.$dispatch('on-form-change', value);
},
|
0f822c9b
梁灏
add Input component
|
174
175
176
177
178
179
180
181
182
|
resizeTextarea () {
const autosize = this.autosize;
if (!autosize || this.type !== 'textarea') {
return false;
}
const minRows = autosize.minRows;
const maxRows = autosize.maxRows;
|
fc7ef072
梁灏
support Input
|
183
|
this.textareaStyles = calcTextareaHeight(this.$refs.textarea, minRows, maxRows);
|
0f822c9b
梁灏
add Input component
|
184
185
186
|
}
},
watch: {
|
fc7ef072
梁灏
support Input
|
187
188
|
value (val) {
this.setCurrentValue(val);
|
0f822c9b
梁灏
add Input component
|
189
190
|
}
},
|
fc7ef072
梁灏
support Input
|
191
192
193
194
195
196
197
198
199
200
|
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
|
201
|
}
|
b0893113
jingsam
add eslint
|
202
203
|
};
</script>
|