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