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