vdesign-ui 0.2.11 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -78
- package/dist/components/actionbar/index.js +8 -8
- package/dist/components/actionbar/index.vue +39 -39
- package/dist/components/actionbar/style.less +44 -44
- package/dist/components/actionbar-cell/index.js +7 -7
- package/dist/components/actionbar-cell/index.vue +38 -38
- package/dist/components/actions/index.js +6 -6
- package/dist/components/actions/index.vue +76 -76
- package/dist/components/actions/style.less +109 -109
- package/dist/components/actions-cell/index.js +6 -6
- package/dist/components/actions-cell/index.vue +94 -94
- package/dist/components/actions-cell/style.less +38 -38
- package/dist/components/activityviews/index.js +8 -8
- package/dist/components/activityviews/index.vue +192 -192
- package/dist/components/activityviews/style.less +151 -151
- package/dist/components/badge/index.js +8 -8
- package/dist/components/badge/index.vue +49 -49
- package/dist/components/badge/style.less +54 -54
- package/dist/components/button/index.js +8 -8
- package/dist/components/button/index.vue +93 -93
- package/dist/components/button/style.less +558 -558
- package/dist/components/calendar/index-element.vue +84 -84
- package/dist/components/calendar/index.js +7 -7
- package/dist/components/calendar/index.vue +52 -52
- package/dist/components/calendar/style.less +138 -138
- package/dist/components/checkbox/index.js +8 -8
- package/dist/components/checkbox/index.vue +161 -161
- package/dist/components/checkbox/style.less +288 -288
- package/dist/components/checkbox-group/index.js +7 -7
- package/dist/components/checkbox-group/index.vue +69 -69
- package/dist/components/common/state/index.vue +33 -33
- package/dist/components/common/state/style.less +47 -47
- package/dist/components/data-list/index.js +10 -10
- package/dist/components/data-list/index.vue +19 -19
- package/dist/components/data-list/style.less +623 -623
- package/dist/components/datetime-picker/index.js +7 -7
- package/dist/components/datetime-picker/index.vue +37 -37
- package/dist/components/datetime-picker/style.less +23 -23
- package/dist/components/dialog/index.js +8 -8
- package/dist/components/dialog/index.vue +164 -164
- package/dist/components/dialog/overlay-manager.js +18 -18
- package/dist/components/dialog/style.less +138 -138
- package/dist/components/divider/index.js +8 -8
- package/dist/components/divider/index.vue +54 -54
- package/dist/components/divider/style.less +92 -92
- package/dist/components/dropdown/index.js +8 -8
- package/dist/components/dropdown/index.vue +218 -218
- package/dist/components/dropdown/style.less +432 -432
- package/dist/components/empty/index.js +8 -8
- package/dist/components/empty/index.vue +138 -138
- package/dist/components/empty/style.less +60 -60
- package/dist/components/footer/index.js +6 -6
- package/dist/components/footer/index.vue +33 -33
- package/dist/components/footer/style.less +20 -20
- package/dist/components/footnav/index.js +6 -6
- package/dist/components/footnav/index.vue +93 -93
- package/dist/components/footnav/style.less +22 -22
- package/dist/components/footnav-item/index.js +6 -6
- package/dist/components/footnav-item/index.vue +50 -50
- package/dist/components/footnav-item/style.less +39 -39
- package/dist/components/form/index.js +6 -6
- package/dist/components/form/index.vue +12 -12
- package/dist/components/headnav/index.js +6 -6
- package/dist/components/headnav/index.vue +185 -185
- package/dist/components/headnav/style.less +231 -231
- package/dist/components/icon/font/iconfont.css +163 -163
- package/dist/components/icon/font/iconfont.js +5 -5
- package/dist/components/icon/index.js +9 -9
- package/dist/components/icon/index.vue +96 -96
- package/dist/components/icon/style.less +44 -44
- package/dist/components/input/calcTextareaHeight.js +162 -162
- package/dist/components/input/index.js +8 -8
- package/dist/components/input/index.vue +345 -345
- package/dist/components/input/style.less +470 -470
- package/dist/components/list/index.js +8 -8
- package/dist/components/list/index.vue +152 -152
- package/dist/components/list/style.less +213 -213
- package/dist/components/loading/index.js +6 -6
- package/dist/components/loading/index.vue +68 -68
- package/dist/components/loading/style.less +53 -53
- package/dist/components/mixins/clickoutside.js +81 -81
- package/dist/components/mixins/languageMixin.js +41 -41
- package/dist/components/mixins/outlineConfigPlugin.js +45 -45
- package/dist/components/mixins/themeMixin.js +43 -43
- package/dist/components/noticebar/index.js +8 -8
- package/dist/components/noticebar/index.vue +258 -258
- package/dist/components/noticebar/style.less +328 -328
- package/dist/components/overlay/index.js +8 -8
- package/dist/components/overlay/index.vue +184 -184
- package/dist/components/overlay/style.less +23 -23
- package/dist/components/pagebreak/index.js +6 -6
- package/dist/components/pagebreak/index.vue +67 -67
- package/dist/components/pagebreak/style.less +41 -41
- package/dist/components/password/index.js +8 -8
- package/dist/components/password/index.vue +60 -60
- package/dist/components/popover/index.js +8 -8
- package/dist/components/popover/index.vue +100 -100
- package/dist/components/popover/style.less +346 -346
- package/dist/components/popover/vue-popover.vue +314 -314
- package/dist/components/popup/index.js +7 -7
- package/dist/components/popup/index.vue +243 -243
- package/dist/components/radio/index.js +8 -8
- package/dist/components/radio/index.vue +184 -184
- package/dist/components/radio/style.less +293 -293
- package/dist/components/radio-group/index.js +6 -6
- package/dist/components/radio-group/index.vue +58 -58
- package/dist/components/result/index.js +8 -8
- package/dist/components/result/index.vue +73 -73
- package/dist/components/result/style.less +43 -43
- package/dist/components/search/index.js +8 -8
- package/dist/components/search/index.vue +66 -66
- package/dist/components/selector/index.js +8 -8
- package/dist/components/selector/index.vue +161 -161
- package/dist/components/selector/style.less +484 -484
- package/dist/components/skeleton/index.js +6 -6
- package/dist/components/skeleton/index.vue +207 -206
- package/dist/components/skeleton/style.less +196 -196
- package/dist/components/slider/draggable.js +49 -49
- package/dist/components/slider/index.js +6 -6
- package/dist/components/slider/index.vue +167 -167
- package/dist/components/slider/style.less +99 -99
- package/dist/components/slider/utils.js +59 -59
- package/dist/components/step/index.js +7 -7
- package/dist/components/step/index.vue +48 -48
- package/dist/components/step/style.less +57 -57
- package/dist/components/step-item/index.js +7 -7
- package/dist/components/step-item/index.vue +126 -126
- package/dist/components/step-item/style.less +362 -362
- package/dist/components/stepper/index.js +8 -8
- package/dist/components/stepper/index.vue +146 -146
- package/dist/components/style/index.vue +42 -42
- package/dist/components/switch/index.js +8 -8
- package/dist/components/switch/index.vue +72 -72
- package/dist/components/switch/style.less +56 -56
- package/dist/components/tab/index.js +7 -7
- package/dist/components/tab/index.vue +94 -93
- package/dist/components/tabs/index.js +8 -8
- package/dist/components/tabs/index.vue +281 -281
- package/dist/components/tabs/style.less +408 -404
- package/dist/components/tag/index.js +6 -6
- package/dist/components/tag/index.vue +64 -64
- package/dist/components/tag/style.less +210 -210
- package/dist/components/title/index.js +8 -8
- package/dist/components/title/index.vue +99 -99
- package/dist/components/title/style.less +187 -187
- package/dist/components/toast/index.js +97 -97
- package/dist/components/toast/index.vue +49 -49
- package/dist/components/toast/style.less +57 -57
- package/dist/components/transition/index.js +8 -8
- package/dist/components/transition/index.vue +13 -13
- package/dist/components/transition/style.less +208 -208
- package/dist/components/upload/index.js +6 -6
- package/dist/components/upload/index.vue +106 -106
- package/dist/components/upload/style.less +147 -147
- package/dist/components/utils/assist.js +34 -34
- package/dist/components/utils/env.js +21 -21
- package/dist/locale/ar.js +97 -97
- package/dist/locale/en.js +97 -97
- package/dist/locale/zh.js +97 -97
- package/dist/token.css +2988 -2988
- package/dist/vdesign-ui.common.js +104 -102
- package/dist/vdesign-ui.css +1 -1
- package/dist/vdesign-ui.umd.js +104 -102
- package/dist/vdesign-ui.umd.min.js +2 -2
- package/package.json +113 -113
|
@@ -1,345 +1,345 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div :class="wrapClasses" class="vd-input">
|
|
3
|
-
<!-- 前缀,还有前缀右边框 -->
|
|
4
|
-
<span v-if="hasPrefix" class="vd-input-form__prefix" :class="borderRightClasses">
|
|
5
|
-
<slot name="prefix">{{ prefix }}</slot>
|
|
6
|
-
</span>
|
|
7
|
-
<textarea
|
|
8
|
-
v-if="type === 'textarea'"
|
|
9
|
-
ref="textarea"
|
|
10
|
-
v-bind="$attrs"
|
|
11
|
-
:rows="rows"
|
|
12
|
-
:class="inputClasses"
|
|
13
|
-
:disabled="disabled"
|
|
14
|
-
:readonly="readonly"
|
|
15
|
-
:value="currentValue"
|
|
16
|
-
@focus="handleFocus"
|
|
17
|
-
@blur="handleBlur"
|
|
18
|
-
@input="handleInput"
|
|
19
|
-
:style="textareaStyles"
|
|
20
|
-
>
|
|
21
|
-
</textarea>
|
|
22
|
-
<input
|
|
23
|
-
v-else
|
|
24
|
-
ref="input"
|
|
25
|
-
v-bind="$attrs"
|
|
26
|
-
:type="passwordIcon ? (passwordVisible ? 'text' : 'password') : type"
|
|
27
|
-
:class="inputClasses"
|
|
28
|
-
:disabled="disabled"
|
|
29
|
-
:readonly="readonly"
|
|
30
|
-
:value="currentValue"
|
|
31
|
-
@input="handleInput"
|
|
32
|
-
@focus="handleFocus"
|
|
33
|
-
@blur="handleBlur"
|
|
34
|
-
/>
|
|
35
|
-
|
|
36
|
-
<!-- 右侧功能区域 -->
|
|
37
|
-
|
|
38
|
-
<div
|
|
39
|
-
v-if="showRightSection"
|
|
40
|
-
class="vd-input-form__right"
|
|
41
|
-
>
|
|
42
|
-
<!-- 清除按钮 -->
|
|
43
|
-
<span v-if="showClear" class="vd-input-form__suffix">
|
|
44
|
-
<vd-icon name="icon_btn_clean" @mousedown.prevent.native="handleClear"></vd-icon>
|
|
45
|
-
</span>
|
|
46
|
-
<!-- (大数字的时候)设计要求的自定义文字 -->
|
|
47
|
-
<span v-if="hasAppend" class="vd-input-form__append">
|
|
48
|
-
<slot name="append">{{ append }}</slot>
|
|
49
|
-
</span>
|
|
50
|
-
<!-- 字数限制 -->
|
|
51
|
-
<div
|
|
52
|
-
v-if="isWordLimitVisible"
|
|
53
|
-
:class="wordLimitClasses"
|
|
54
|
-
>
|
|
55
|
-
<span>{{ textLength }}</span
|
|
56
|
-
>/<span>{{ upperLimit }}</span>
|
|
57
|
-
</div>
|
|
58
|
-
</div>
|
|
59
|
-
<!-- 密码的时候,单独的清空按钮 -->
|
|
60
|
-
<span
|
|
61
|
-
v-if="showPasswordControls"
|
|
62
|
-
class="vd-input-form__password"
|
|
63
|
-
>
|
|
64
|
-
<span v-if="showPasswordClear" class="vd-input-form__password--close">
|
|
65
|
-
<vd-icon name="icon_btn_close" @mousedown.prevent.native="handleClear"></vd-icon>
|
|
66
|
-
</span>
|
|
67
|
-
<span v-if="showPasswordIcon" class="vd-input-form__password--password">
|
|
68
|
-
<vd-icon
|
|
69
|
-
:name="passwordVisible ? 'icon_btn_eye' : 'icon_btn_eye_close'"
|
|
70
|
-
@click="handlePasswordVisible"
|
|
71
|
-
></vd-icon>
|
|
72
|
-
</span>
|
|
73
|
-
</span>
|
|
74
|
-
</div>
|
|
75
|
-
</template>
|
|
76
|
-
|
|
77
|
-
<script>
|
|
78
|
-
import VdIcon from '../icon';
|
|
79
|
-
import calcTextareaHeight from "./calcTextareaHeight";
|
|
80
|
-
const prefixCls = "vd-input";
|
|
81
|
-
|
|
82
|
-
export default {
|
|
83
|
-
name: "vd-input",
|
|
84
|
-
components: {
|
|
85
|
-
VdIcon,
|
|
86
|
-
},
|
|
87
|
-
props: {
|
|
88
|
-
value: {
|
|
89
|
-
type: [String, Number],
|
|
90
|
-
default: "",
|
|
91
|
-
},
|
|
92
|
-
type: {
|
|
93
|
-
type: String,
|
|
94
|
-
default: "text",
|
|
95
|
-
},
|
|
96
|
-
prefix: {
|
|
97
|
-
type: [Boolean, String],
|
|
98
|
-
default: ''
|
|
99
|
-
},
|
|
100
|
-
borderRight: {
|
|
101
|
-
type: Boolean,
|
|
102
|
-
default: true
|
|
103
|
-
},
|
|
104
|
-
// 设计如此,单独的文字
|
|
105
|
-
append: {
|
|
106
|
-
type: [Boolean, String],
|
|
107
|
-
default: ''
|
|
108
|
-
},
|
|
109
|
-
error: {
|
|
110
|
-
type: Boolean,
|
|
111
|
-
},
|
|
112
|
-
bigSize: {
|
|
113
|
-
type: Boolean,
|
|
114
|
-
},
|
|
115
|
-
passwordIcon: {
|
|
116
|
-
type: Boolean,
|
|
117
|
-
},
|
|
118
|
-
passwordClose: {
|
|
119
|
-
type: Boolean,
|
|
120
|
-
},
|
|
121
|
-
// 输入框类型 表单类型,常规输入库,搜索框
|
|
122
|
-
form: {
|
|
123
|
-
type: String,
|
|
124
|
-
},
|
|
125
|
-
disabled: {
|
|
126
|
-
type: Boolean,
|
|
127
|
-
},
|
|
128
|
-
rows: {
|
|
129
|
-
type: Number,
|
|
130
|
-
default: 2,
|
|
131
|
-
},
|
|
132
|
-
// 设计如此多行textarea,跟input属性一样
|
|
133
|
-
inputTextArea: {
|
|
134
|
-
type: Boolean,
|
|
135
|
-
},
|
|
136
|
-
warning: {
|
|
137
|
-
type: Boolean,
|
|
138
|
-
},
|
|
139
|
-
hairline: {
|
|
140
|
-
type: Boolean,
|
|
141
|
-
default: true,
|
|
142
|
-
},
|
|
143
|
-
autosize: {
|
|
144
|
-
type: [Boolean, Object],
|
|
145
|
-
default: false,
|
|
146
|
-
},
|
|
147
|
-
// 新增0118
|
|
148
|
-
showWordLimit: {
|
|
149
|
-
type: Boolean,
|
|
150
|
-
default: false,
|
|
151
|
-
},
|
|
152
|
-
clearable:Boolean,
|
|
153
|
-
readonly:Boolean
|
|
154
|
-
},
|
|
155
|
-
data() {
|
|
156
|
-
return {
|
|
157
|
-
focusClass: false,
|
|
158
|
-
currentValue: this.value,
|
|
159
|
-
textareaStyles: {},
|
|
160
|
-
passwordVisible: false,
|
|
161
|
-
focused: false,
|
|
162
|
-
};
|
|
163
|
-
},
|
|
164
|
-
computed: {
|
|
165
|
-
hasPrefix() {
|
|
166
|
-
return (this.prefix !== undefined && this.prefix !== '') || this.$slots.prefix;
|
|
167
|
-
},
|
|
168
|
-
// 是否显示右侧区域
|
|
169
|
-
showRightSection() {
|
|
170
|
-
return this.showClear || this.hasAppend || this.isWordLimitVisible;
|
|
171
|
-
},
|
|
172
|
-
// 是否有附加内容
|
|
173
|
-
hasAppend() {
|
|
174
|
-
return (this.append !== undefined && this.append !== '') || this.$slots.append;
|
|
175
|
-
},
|
|
176
|
-
// 是否显示清除按钮(假设已经在 computed 中定义)
|
|
177
|
-
showClear() {
|
|
178
|
-
return (
|
|
179
|
-
this.clearable &&
|
|
180
|
-
this.focused &&
|
|
181
|
-
this.currentValue !== '' &&
|
|
182
|
-
!this.disabled &&
|
|
183
|
-
!this.readonly
|
|
184
|
-
);
|
|
185
|
-
},
|
|
186
|
-
wordLimitClasses() {
|
|
187
|
-
return [
|
|
188
|
-
'vd-input__word-limit',
|
|
189
|
-
{ 'vd-input__word-limit--error': this.isOverLimit },
|
|
190
|
-
];
|
|
191
|
-
},
|
|
192
|
-
showPasswordClear() {
|
|
193
|
-
return (
|
|
194
|
-
this.passwordClose &&
|
|
195
|
-
this.focused &&
|
|
196
|
-
this.currentValue !== '' &&
|
|
197
|
-
!this.disabled &&
|
|
198
|
-
!this.readonly
|
|
199
|
-
);
|
|
200
|
-
},
|
|
201
|
-
showPasswordIcon() {
|
|
202
|
-
return this.passwordIcon && this.type === 'password';
|
|
203
|
-
},
|
|
204
|
-
showPasswordControls() {
|
|
205
|
-
return this.showPasswordClear || this.showPasswordIcon;
|
|
206
|
-
},
|
|
207
|
-
wrapClasses() {
|
|
208
|
-
return [
|
|
209
|
-
{
|
|
210
|
-
[`${prefixCls}-${this.form}`]: this.form,
|
|
211
|
-
[`${prefixCls}--disabled`]: this.disabled,
|
|
212
|
-
[`${prefixCls}-${this.type}`]: this.type,
|
|
213
|
-
[`${prefixCls}-${this.type}--warning`]: this.warning,
|
|
214
|
-
[`${prefixCls}--bigsize`]: this.bigSize,
|
|
215
|
-
[`${prefixCls}--error`]: this.error,
|
|
216
|
-
[`${prefixCls}--active`]: this.focused,
|
|
217
|
-
[`${prefixCls}-inputarea`]: this.inputTextArea,
|
|
218
|
-
"vd-hairline--bottom": this.hairline,
|
|
219
|
-
"vd-textarea-auto": this.inputTextArea,
|
|
220
|
-
},
|
|
221
|
-
];
|
|
222
|
-
},
|
|
223
|
-
borderRightClasses(){
|
|
224
|
-
return [
|
|
225
|
-
"vd-hairline--right",
|
|
226
|
-
{
|
|
227
|
-
[`${prefixCls}--border`]: this.borderRight,
|
|
228
|
-
}
|
|
229
|
-
]
|
|
230
|
-
},
|
|
231
|
-
inputClasses() {
|
|
232
|
-
return [
|
|
233
|
-
`${prefixCls}__control`,
|
|
234
|
-
{
|
|
235
|
-
[`${prefixCls}-${this.type}__control`]: this.type,
|
|
236
|
-
},
|
|
237
|
-
];
|
|
238
|
-
},
|
|
239
|
-
// 当前输入的文本长度
|
|
240
|
-
textLength() {
|
|
241
|
-
if (typeof this.value === "number") {
|
|
242
|
-
return String(this.value).length;
|
|
243
|
-
}
|
|
244
|
-
return (this.value || "").length;
|
|
245
|
-
},
|
|
246
|
-
upperLimit() {
|
|
247
|
-
return this.$attrs.maxlength;
|
|
248
|
-
},
|
|
249
|
-
isWordLimitVisible() {
|
|
250
|
-
return (
|
|
251
|
-
this.showWordLimit &&
|
|
252
|
-
this.$attrs.maxlength &&
|
|
253
|
-
(this.type === "text" || this.type === "textarea")
|
|
254
|
-
);
|
|
255
|
-
},
|
|
256
|
-
isOverLimit() {
|
|
257
|
-
return this.textLength >= this.upperLimit;
|
|
258
|
-
},
|
|
259
|
-
},
|
|
260
|
-
methods: {
|
|
261
|
-
handleFocus(event) {
|
|
262
|
-
this.focused = true;
|
|
263
|
-
this.$emit("focus", event);
|
|
264
|
-
|
|
265
|
-
if (this.readonly) {
|
|
266
|
-
this.blur();
|
|
267
|
-
}
|
|
268
|
-
},
|
|
269
|
-
handleBlur(event) {
|
|
270
|
-
this.focused = false;
|
|
271
|
-
this.$emit("blur", event);
|
|
272
|
-
},
|
|
273
|
-
focus() {
|
|
274
|
-
if (this.type === "textarea") {
|
|
275
|
-
this.$refs.textarea && this.$refs.textarea.focus();
|
|
276
|
-
} else {
|
|
277
|
-
this.$refs.input && this.$refs.input.focus();
|
|
278
|
-
}
|
|
279
|
-
},
|
|
280
|
-
blur() {
|
|
281
|
-
if (this.type === "textarea") {
|
|
282
|
-
this.$refs.textarea && this.$refs.textarea.blur();
|
|
283
|
-
} else {
|
|
284
|
-
this.$refs.input && this.$refs.input.blur();
|
|
285
|
-
}
|
|
286
|
-
},
|
|
287
|
-
|
|
288
|
-
handleInput(event) {
|
|
289
|
-
let value = event.target.value;
|
|
290
|
-
this.$emit("input", value);
|
|
291
|
-
this.setCurrentValue(value);
|
|
292
|
-
this.$emit("change", event);
|
|
293
|
-
},
|
|
294
|
-
|
|
295
|
-
setCurrentValue(value) {
|
|
296
|
-
if (value === this.currentValue) return;
|
|
297
|
-
this.currentValue = value;
|
|
298
|
-
this.$nextTick(() => {
|
|
299
|
-
this.resizeTextarea();
|
|
300
|
-
});
|
|
301
|
-
},
|
|
302
|
-
resizeTextarea() {
|
|
303
|
-
if (!this.autosize || this.type !== "textarea") {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
const { minRows, maxRows } = this.autosize;
|
|
307
|
-
this.textareaStyles = calcTextareaHeight(
|
|
308
|
-
this.$refs.textarea,
|
|
309
|
-
minRows,
|
|
310
|
-
maxRows
|
|
311
|
-
);
|
|
312
|
-
},
|
|
313
|
-
handleClear() {
|
|
314
|
-
const e = { target: { value: "" } };
|
|
315
|
-
this.$emit("input", "");
|
|
316
|
-
this.setCurrentValue("");
|
|
317
|
-
this.$emit("change", e);
|
|
318
|
-
this.$emit("clear");
|
|
319
|
-
this.$nextTick(() => {
|
|
320
|
-
this.focus();
|
|
321
|
-
});
|
|
322
|
-
},
|
|
323
|
-
|
|
324
|
-
// 切换密码显示状态
|
|
325
|
-
handlePasswordVisible() {
|
|
326
|
-
this.passwordVisible = !this.passwordVisible;
|
|
327
|
-
this.$nextTick(() => {
|
|
328
|
-
this.focus();
|
|
329
|
-
});
|
|
330
|
-
},
|
|
331
|
-
},
|
|
332
|
-
watch: {
|
|
333
|
-
value(val) {
|
|
334
|
-
this.setCurrentValue(val);
|
|
335
|
-
},
|
|
336
|
-
},
|
|
337
|
-
mounted() {
|
|
338
|
-
this.resizeTextarea();
|
|
339
|
-
},
|
|
340
|
-
};
|
|
341
|
-
</script>
|
|
342
|
-
|
|
343
|
-
<style lang="less">
|
|
344
|
-
@import "./style.less";
|
|
345
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="wrapClasses" class="vd-input">
|
|
3
|
+
<!-- 前缀,还有前缀右边框 -->
|
|
4
|
+
<span v-if="hasPrefix" class="vd-input-form__prefix" :class="borderRightClasses">
|
|
5
|
+
<slot name="prefix">{{ prefix }}</slot>
|
|
6
|
+
</span>
|
|
7
|
+
<textarea
|
|
8
|
+
v-if="type === 'textarea'"
|
|
9
|
+
ref="textarea"
|
|
10
|
+
v-bind="$attrs"
|
|
11
|
+
:rows="rows"
|
|
12
|
+
:class="inputClasses"
|
|
13
|
+
:disabled="disabled"
|
|
14
|
+
:readonly="readonly"
|
|
15
|
+
:value="currentValue"
|
|
16
|
+
@focus="handleFocus"
|
|
17
|
+
@blur="handleBlur"
|
|
18
|
+
@input="handleInput"
|
|
19
|
+
:style="textareaStyles"
|
|
20
|
+
>
|
|
21
|
+
</textarea>
|
|
22
|
+
<input
|
|
23
|
+
v-else
|
|
24
|
+
ref="input"
|
|
25
|
+
v-bind="$attrs"
|
|
26
|
+
:type="passwordIcon ? (passwordVisible ? 'text' : 'password') : type"
|
|
27
|
+
:class="inputClasses"
|
|
28
|
+
:disabled="disabled"
|
|
29
|
+
:readonly="readonly"
|
|
30
|
+
:value="currentValue"
|
|
31
|
+
@input="handleInput"
|
|
32
|
+
@focus="handleFocus"
|
|
33
|
+
@blur="handleBlur"
|
|
34
|
+
/>
|
|
35
|
+
|
|
36
|
+
<!-- 右侧功能区域 -->
|
|
37
|
+
|
|
38
|
+
<div
|
|
39
|
+
v-if="showRightSection"
|
|
40
|
+
class="vd-input-form__right"
|
|
41
|
+
>
|
|
42
|
+
<!-- 清除按钮 -->
|
|
43
|
+
<span v-if="showClear" class="vd-input-form__suffix">
|
|
44
|
+
<vd-icon name="icon_btn_clean" @mousedown.prevent.native="handleClear"></vd-icon>
|
|
45
|
+
</span>
|
|
46
|
+
<!-- (大数字的时候)设计要求的自定义文字 -->
|
|
47
|
+
<span v-if="hasAppend" class="vd-input-form__append">
|
|
48
|
+
<slot name="append">{{ append }}</slot>
|
|
49
|
+
</span>
|
|
50
|
+
<!-- 字数限制 -->
|
|
51
|
+
<div
|
|
52
|
+
v-if="isWordLimitVisible"
|
|
53
|
+
:class="wordLimitClasses"
|
|
54
|
+
>
|
|
55
|
+
<span>{{ textLength }}</span
|
|
56
|
+
>/<span>{{ upperLimit }}</span>
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
<!-- 密码的时候,单独的清空按钮 -->
|
|
60
|
+
<span
|
|
61
|
+
v-if="showPasswordControls"
|
|
62
|
+
class="vd-input-form__password"
|
|
63
|
+
>
|
|
64
|
+
<span v-if="showPasswordClear" class="vd-input-form__password--close">
|
|
65
|
+
<vd-icon name="icon_btn_close" @mousedown.prevent.native="handleClear"></vd-icon>
|
|
66
|
+
</span>
|
|
67
|
+
<span v-if="showPasswordIcon" class="vd-input-form__password--password">
|
|
68
|
+
<vd-icon
|
|
69
|
+
:name="passwordVisible ? 'icon_btn_eye' : 'icon_btn_eye_close'"
|
|
70
|
+
@click="handlePasswordVisible"
|
|
71
|
+
></vd-icon>
|
|
72
|
+
</span>
|
|
73
|
+
</span>
|
|
74
|
+
</div>
|
|
75
|
+
</template>
|
|
76
|
+
|
|
77
|
+
<script>
|
|
78
|
+
import VdIcon from '../icon';
|
|
79
|
+
import calcTextareaHeight from "./calcTextareaHeight";
|
|
80
|
+
const prefixCls = "vd-input";
|
|
81
|
+
|
|
82
|
+
export default {
|
|
83
|
+
name: "vd-input",
|
|
84
|
+
components: {
|
|
85
|
+
VdIcon,
|
|
86
|
+
},
|
|
87
|
+
props: {
|
|
88
|
+
value: {
|
|
89
|
+
type: [String, Number],
|
|
90
|
+
default: "",
|
|
91
|
+
},
|
|
92
|
+
type: {
|
|
93
|
+
type: String,
|
|
94
|
+
default: "text",
|
|
95
|
+
},
|
|
96
|
+
prefix: {
|
|
97
|
+
type: [Boolean, String],
|
|
98
|
+
default: ''
|
|
99
|
+
},
|
|
100
|
+
borderRight: {
|
|
101
|
+
type: Boolean,
|
|
102
|
+
default: true
|
|
103
|
+
},
|
|
104
|
+
// 设计如此,单独的文字
|
|
105
|
+
append: {
|
|
106
|
+
type: [Boolean, String],
|
|
107
|
+
default: ''
|
|
108
|
+
},
|
|
109
|
+
error: {
|
|
110
|
+
type: Boolean,
|
|
111
|
+
},
|
|
112
|
+
bigSize: {
|
|
113
|
+
type: Boolean,
|
|
114
|
+
},
|
|
115
|
+
passwordIcon: {
|
|
116
|
+
type: Boolean,
|
|
117
|
+
},
|
|
118
|
+
passwordClose: {
|
|
119
|
+
type: Boolean,
|
|
120
|
+
},
|
|
121
|
+
// 输入框类型 表单类型,常规输入库,搜索框
|
|
122
|
+
form: {
|
|
123
|
+
type: String,
|
|
124
|
+
},
|
|
125
|
+
disabled: {
|
|
126
|
+
type: Boolean,
|
|
127
|
+
},
|
|
128
|
+
rows: {
|
|
129
|
+
type: Number,
|
|
130
|
+
default: 2,
|
|
131
|
+
},
|
|
132
|
+
// 设计如此多行textarea,跟input属性一样
|
|
133
|
+
inputTextArea: {
|
|
134
|
+
type: Boolean,
|
|
135
|
+
},
|
|
136
|
+
warning: {
|
|
137
|
+
type: Boolean,
|
|
138
|
+
},
|
|
139
|
+
hairline: {
|
|
140
|
+
type: Boolean,
|
|
141
|
+
default: true,
|
|
142
|
+
},
|
|
143
|
+
autosize: {
|
|
144
|
+
type: [Boolean, Object],
|
|
145
|
+
default: false,
|
|
146
|
+
},
|
|
147
|
+
// 新增0118
|
|
148
|
+
showWordLimit: {
|
|
149
|
+
type: Boolean,
|
|
150
|
+
default: false,
|
|
151
|
+
},
|
|
152
|
+
clearable:Boolean,
|
|
153
|
+
readonly:Boolean
|
|
154
|
+
},
|
|
155
|
+
data() {
|
|
156
|
+
return {
|
|
157
|
+
focusClass: false,
|
|
158
|
+
currentValue: this.value,
|
|
159
|
+
textareaStyles: {},
|
|
160
|
+
passwordVisible: false,
|
|
161
|
+
focused: false,
|
|
162
|
+
};
|
|
163
|
+
},
|
|
164
|
+
computed: {
|
|
165
|
+
hasPrefix() {
|
|
166
|
+
return (this.prefix !== undefined && this.prefix !== '') || this.$slots.prefix;
|
|
167
|
+
},
|
|
168
|
+
// 是否显示右侧区域
|
|
169
|
+
showRightSection() {
|
|
170
|
+
return this.showClear || this.hasAppend || this.isWordLimitVisible;
|
|
171
|
+
},
|
|
172
|
+
// 是否有附加内容
|
|
173
|
+
hasAppend() {
|
|
174
|
+
return (this.append !== undefined && this.append !== '') || this.$slots.append;
|
|
175
|
+
},
|
|
176
|
+
// 是否显示清除按钮(假设已经在 computed 中定义)
|
|
177
|
+
showClear() {
|
|
178
|
+
return (
|
|
179
|
+
this.clearable &&
|
|
180
|
+
this.focused &&
|
|
181
|
+
this.currentValue !== '' &&
|
|
182
|
+
!this.disabled &&
|
|
183
|
+
!this.readonly
|
|
184
|
+
);
|
|
185
|
+
},
|
|
186
|
+
wordLimitClasses() {
|
|
187
|
+
return [
|
|
188
|
+
'vd-input__word-limit',
|
|
189
|
+
{ 'vd-input__word-limit--error': this.isOverLimit },
|
|
190
|
+
];
|
|
191
|
+
},
|
|
192
|
+
showPasswordClear() {
|
|
193
|
+
return (
|
|
194
|
+
this.passwordClose &&
|
|
195
|
+
this.focused &&
|
|
196
|
+
this.currentValue !== '' &&
|
|
197
|
+
!this.disabled &&
|
|
198
|
+
!this.readonly
|
|
199
|
+
);
|
|
200
|
+
},
|
|
201
|
+
showPasswordIcon() {
|
|
202
|
+
return this.passwordIcon && this.type === 'password';
|
|
203
|
+
},
|
|
204
|
+
showPasswordControls() {
|
|
205
|
+
return this.showPasswordClear || this.showPasswordIcon;
|
|
206
|
+
},
|
|
207
|
+
wrapClasses() {
|
|
208
|
+
return [
|
|
209
|
+
{
|
|
210
|
+
[`${prefixCls}-${this.form}`]: this.form,
|
|
211
|
+
[`${prefixCls}--disabled`]: this.disabled,
|
|
212
|
+
[`${prefixCls}-${this.type}`]: this.type,
|
|
213
|
+
[`${prefixCls}-${this.type}--warning`]: this.warning,
|
|
214
|
+
[`${prefixCls}--bigsize`]: this.bigSize,
|
|
215
|
+
[`${prefixCls}--error`]: this.error,
|
|
216
|
+
[`${prefixCls}--active`]: this.focused,
|
|
217
|
+
[`${prefixCls}-inputarea`]: this.inputTextArea,
|
|
218
|
+
"vd-hairline--bottom": this.hairline,
|
|
219
|
+
"vd-textarea-auto": this.inputTextArea,
|
|
220
|
+
},
|
|
221
|
+
];
|
|
222
|
+
},
|
|
223
|
+
borderRightClasses(){
|
|
224
|
+
return [
|
|
225
|
+
"vd-hairline--right",
|
|
226
|
+
{
|
|
227
|
+
[`${prefixCls}--border`]: this.borderRight,
|
|
228
|
+
}
|
|
229
|
+
]
|
|
230
|
+
},
|
|
231
|
+
inputClasses() {
|
|
232
|
+
return [
|
|
233
|
+
`${prefixCls}__control`,
|
|
234
|
+
{
|
|
235
|
+
[`${prefixCls}-${this.type}__control`]: this.type,
|
|
236
|
+
},
|
|
237
|
+
];
|
|
238
|
+
},
|
|
239
|
+
// 当前输入的文本长度
|
|
240
|
+
textLength() {
|
|
241
|
+
if (typeof this.value === "number") {
|
|
242
|
+
return String(this.value).length;
|
|
243
|
+
}
|
|
244
|
+
return (this.value || "").length;
|
|
245
|
+
},
|
|
246
|
+
upperLimit() {
|
|
247
|
+
return this.$attrs.maxlength;
|
|
248
|
+
},
|
|
249
|
+
isWordLimitVisible() {
|
|
250
|
+
return (
|
|
251
|
+
this.showWordLimit &&
|
|
252
|
+
this.$attrs.maxlength &&
|
|
253
|
+
(this.type === "text" || this.type === "textarea")
|
|
254
|
+
);
|
|
255
|
+
},
|
|
256
|
+
isOverLimit() {
|
|
257
|
+
return this.textLength >= this.upperLimit;
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
methods: {
|
|
261
|
+
handleFocus(event) {
|
|
262
|
+
this.focused = true;
|
|
263
|
+
this.$emit("focus", event);
|
|
264
|
+
|
|
265
|
+
if (this.readonly) {
|
|
266
|
+
this.blur();
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
handleBlur(event) {
|
|
270
|
+
this.focused = false;
|
|
271
|
+
this.$emit("blur", event);
|
|
272
|
+
},
|
|
273
|
+
focus() {
|
|
274
|
+
if (this.type === "textarea") {
|
|
275
|
+
this.$refs.textarea && this.$refs.textarea.focus();
|
|
276
|
+
} else {
|
|
277
|
+
this.$refs.input && this.$refs.input.focus();
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
blur() {
|
|
281
|
+
if (this.type === "textarea") {
|
|
282
|
+
this.$refs.textarea && this.$refs.textarea.blur();
|
|
283
|
+
} else {
|
|
284
|
+
this.$refs.input && this.$refs.input.blur();
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
handleInput(event) {
|
|
289
|
+
let value = event.target.value;
|
|
290
|
+
this.$emit("input", value);
|
|
291
|
+
this.setCurrentValue(value);
|
|
292
|
+
this.$emit("change", event);
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
setCurrentValue(value) {
|
|
296
|
+
if (value === this.currentValue) return;
|
|
297
|
+
this.currentValue = value;
|
|
298
|
+
this.$nextTick(() => {
|
|
299
|
+
this.resizeTextarea();
|
|
300
|
+
});
|
|
301
|
+
},
|
|
302
|
+
resizeTextarea() {
|
|
303
|
+
if (!this.autosize || this.type !== "textarea") {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const { minRows, maxRows } = this.autosize;
|
|
307
|
+
this.textareaStyles = calcTextareaHeight(
|
|
308
|
+
this.$refs.textarea,
|
|
309
|
+
minRows,
|
|
310
|
+
maxRows
|
|
311
|
+
);
|
|
312
|
+
},
|
|
313
|
+
handleClear() {
|
|
314
|
+
const e = { target: { value: "" } };
|
|
315
|
+
this.$emit("input", "");
|
|
316
|
+
this.setCurrentValue("");
|
|
317
|
+
this.$emit("change", e);
|
|
318
|
+
this.$emit("clear");
|
|
319
|
+
this.$nextTick(() => {
|
|
320
|
+
this.focus();
|
|
321
|
+
});
|
|
322
|
+
},
|
|
323
|
+
|
|
324
|
+
// 切换密码显示状态
|
|
325
|
+
handlePasswordVisible() {
|
|
326
|
+
this.passwordVisible = !this.passwordVisible;
|
|
327
|
+
this.$nextTick(() => {
|
|
328
|
+
this.focus();
|
|
329
|
+
});
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
watch: {
|
|
333
|
+
value(val) {
|
|
334
|
+
this.setCurrentValue(val);
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
mounted() {
|
|
338
|
+
this.resizeTextarea();
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
</script>
|
|
342
|
+
|
|
343
|
+
<style lang="less">
|
|
344
|
+
@import "./style.less";
|
|
345
|
+
</style>
|