index.vue
2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<template>
<div :class="{ 'el-input': 'el-input', 'is-disabled': disabled ? 'is-disabled' : '' }">
<div :class="'el-input--' + size" v-if="type == 'text'">
<input class="el-input__inner" type="text" v-model.lazy="values" :placeholder="placeholder" :disabled="disabled"
:maxlength="maxlength" @change="change" @blur="blur" @focus="focus" @input="handleInput"
:oninput="oninput" />
</div>
<el-input v-else-if="type == 'textarea'" type="textarea" v-model.lazy="values" :rows="rows" :size="size"
:placeholder="placeholder" :maxlength="maxlength" :disabled="disabled"
:show-word-limit="showWordLimit"></el-input>
<slot name="suffix" v-if="type == 'text'"></slot>
</div>
</template>
<script>
export default {
props: {
value: {
type: [Number, String],
default: null
},
type: {
type: String,
default: 'text'
},
placeholder: {
type: String,
default: ''
},
rows: {
type: Number,
default: 2
},
size: {
type: String,
default: 'small'
},
disabled: {
type: Boolean,
default: false
},
oninput: {
type: String,
default: ''
},
prop: {
type: String,
default: ''
},
maxlength: {
type: String,
default: null
},
node: {
type: Object,
default: null
},
showWordLimit: {
type: Boolean,
default: false,
}
},
data() {
return {
}
},
methods: {
change(val) {
this.$emit('change', val)
},
blur(val) {
if (this.node != null) {
this.node.validateField(this.prop)
}
this.$emit('blur', { val: val.srcElement.value, prop: this.prop })
},
handleInput(val) {
this.$emit('input', val.target._value)
},
focus(val) {
this.$emit('focus', val)
},
},
computed: {
values: {
get: function () {
return this.value;
},
set: function (val) {
this.$emit('input', val)
},
},
}
}
</script>
<style lang="scss" scoped>
.el-input__inner {
padding-right: 25px;
}
.suffixIcon {
color: #C0C4CC;
font-size: 14px;
height: 100%;
position: absolute;
right: 6px;
top: 25%;
text-align: center;
pointer-events: none;
}
</style>