zydx-plus 1.17.75 → 1.17.77
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/package.json
CHANGED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="input_wrapper"
|
|
3
|
+
:class="{ 'border': border }">
|
|
4
|
+
<slot name="prefix"></slot>
|
|
5
|
+
<template v-if="['input', 'text', 'password', 'email', 'number'].includes(type)">
|
|
6
|
+
<input :value="value"
|
|
7
|
+
class="input"
|
|
8
|
+
:type="type"
|
|
9
|
+
:maxlength="maxlength"
|
|
10
|
+
:min="min"
|
|
11
|
+
:max="max"
|
|
12
|
+
:minlength="minLength"
|
|
13
|
+
:placeholder="readonly ? '' : placeholder"
|
|
14
|
+
:readonly="readonly"
|
|
15
|
+
@input="onInput"
|
|
16
|
+
@blur="onBlur" />
|
|
17
|
+
<template v-if="hasSuffixSlot">
|
|
18
|
+
<div class="suffix_container">
|
|
19
|
+
<slot name="suffix"></slot>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
22
|
+
</template>
|
|
23
|
+
<template v-if="type === 'textarea'">
|
|
24
|
+
<textarea :value="value"
|
|
25
|
+
class="textarea"
|
|
26
|
+
ref="target"
|
|
27
|
+
:type="type"
|
|
28
|
+
:maxlength="maxlength"
|
|
29
|
+
:minlength="minLength"
|
|
30
|
+
:placeholder="placeholder"
|
|
31
|
+
:readonly="readonly"
|
|
32
|
+
@input="onInput" />
|
|
33
|
+
</template>
|
|
34
|
+
</div>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<script>
|
|
38
|
+
import { defineComponent } from 'vue';
|
|
39
|
+
|
|
40
|
+
export default defineComponent({
|
|
41
|
+
name: 'zydx-input',
|
|
42
|
+
props: {
|
|
43
|
+
type: {
|
|
44
|
+
type: String,
|
|
45
|
+
default: 'text'
|
|
46
|
+
},
|
|
47
|
+
maxlength: {
|
|
48
|
+
type: Number,
|
|
49
|
+
default: null
|
|
50
|
+
},
|
|
51
|
+
step: {
|
|
52
|
+
type: Number,
|
|
53
|
+
default: 1
|
|
54
|
+
},
|
|
55
|
+
minLength: {
|
|
56
|
+
type: Number,
|
|
57
|
+
default: null
|
|
58
|
+
},
|
|
59
|
+
placeholder: {
|
|
60
|
+
type: String,
|
|
61
|
+
default: ''
|
|
62
|
+
},
|
|
63
|
+
readonly: {
|
|
64
|
+
type: Boolean,
|
|
65
|
+
default: false
|
|
66
|
+
},
|
|
67
|
+
row: {
|
|
68
|
+
type: Object,
|
|
69
|
+
default: () => null
|
|
70
|
+
},
|
|
71
|
+
border: {
|
|
72
|
+
type: Boolean,
|
|
73
|
+
default: true
|
|
74
|
+
},
|
|
75
|
+
value: {
|
|
76
|
+
type: String,
|
|
77
|
+
default: ''
|
|
78
|
+
},
|
|
79
|
+
max: {
|
|
80
|
+
type: Number,
|
|
81
|
+
default: Infinity
|
|
82
|
+
},
|
|
83
|
+
min: {
|
|
84
|
+
type: Number,
|
|
85
|
+
default: -Infinity
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
data() {
|
|
89
|
+
return {
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
mounted() {
|
|
93
|
+
this.setDefaultHeight()
|
|
94
|
+
},
|
|
95
|
+
methods: {
|
|
96
|
+
onInput(e) {
|
|
97
|
+
this.$emit('update:value', this.sanitize(e.target.value))
|
|
98
|
+
if (this.type === 'textarea') {
|
|
99
|
+
this.triggerResize()
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
onBlur: function (e) {
|
|
103
|
+
if (this.type === 'number') {
|
|
104
|
+
let value = Number(e.target.value)
|
|
105
|
+
value > this.max && (value = this.max)
|
|
106
|
+
value < this.min && (value = this.min)
|
|
107
|
+
if (String(value).indexOf('.') !== -1) {
|
|
108
|
+
let digits = Math.log10((1 / this.step))
|
|
109
|
+
value = value.toFixed(digits)
|
|
110
|
+
}
|
|
111
|
+
e.target.value = String(value)
|
|
112
|
+
this.$emit('update:value', String(value))
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
setDefaultHeight: function () {
|
|
117
|
+
if (this.type !== 'textarea') return
|
|
118
|
+
if (!this.row) return
|
|
119
|
+
const { min } = this.row
|
|
120
|
+
this.$refs.target.style.height = `${min * 30}px`
|
|
121
|
+
},
|
|
122
|
+
sanitize: function (input) {
|
|
123
|
+
return input.replace(/<\/?[^>]+>/ig, "");
|
|
124
|
+
},
|
|
125
|
+
triggerResize: function () {
|
|
126
|
+
let element = this.$refs.target
|
|
127
|
+
if (!element) return
|
|
128
|
+
if (!element.scrollHeight) {
|
|
129
|
+
element.style.height = '30px'
|
|
130
|
+
} else {
|
|
131
|
+
if (!this.row) {
|
|
132
|
+
element.style.height = `${element.scrollHeight}px`
|
|
133
|
+
} else {
|
|
134
|
+
const { min, max } = this.row
|
|
135
|
+
if (element.scrollHeight < min * 30) {
|
|
136
|
+
element.style.height = `${min * 30}px`
|
|
137
|
+
} else if (element.scrollHeight > max * 30) {
|
|
138
|
+
element.style.height = `${max * 30}px`
|
|
139
|
+
} else {
|
|
140
|
+
element.style.height = `${element.scrollHeight}px`
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
computed: {
|
|
147
|
+
hasSuffixSlot() {
|
|
148
|
+
return !!this.$slots.suffix;
|
|
149
|
+
},
|
|
150
|
+
hasPreffixSlot() {
|
|
151
|
+
return !!this.$slots.prefix;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
</script>
|
|
156
|
+
|
|
157
|
+
<style scoped>
|
|
158
|
+
.input_wrapper {
|
|
159
|
+
width: 100%;
|
|
160
|
+
height: auto;
|
|
161
|
+
display: flex;
|
|
162
|
+
align-items: center;
|
|
163
|
+
justify-content: flex-start;
|
|
164
|
+
border-radius: 3px;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.input_wrapper.border {
|
|
168
|
+
border: 1px solid #ccc
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.input_wrapper .input {
|
|
172
|
+
width: 100%;
|
|
173
|
+
height: 30px;
|
|
174
|
+
border: none;
|
|
175
|
+
outline: none;
|
|
176
|
+
background: transparent;
|
|
177
|
+
padding: 0 10px;
|
|
178
|
+
font-size: 14px;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.input_wrapper .textarea {
|
|
182
|
+
width: 100%;
|
|
183
|
+
border: none;
|
|
184
|
+
outline: none;
|
|
185
|
+
background: transparent;
|
|
186
|
+
height: 30px;
|
|
187
|
+
padding: 0 10px;
|
|
188
|
+
font-size: 14px;
|
|
189
|
+
line-height: 30px;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.prefix_container {
|
|
193
|
+
width: 24px;
|
|
194
|
+
height: 24px;
|
|
195
|
+
display: flex;
|
|
196
|
+
align-items: center;
|
|
197
|
+
justify-content: center;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.suffix_container {
|
|
201
|
+
width: auto;
|
|
202
|
+
display: flex;
|
|
203
|
+
align-items: center;
|
|
204
|
+
justify-content: center;
|
|
205
|
+
padding: 0 10px
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.suffix_container:deep(*) {
|
|
209
|
+
width: auto;
|
|
210
|
+
height: 16px;
|
|
211
|
+
font-size: 14px;
|
|
212
|
+
white-space: nowrap;
|
|
213
|
+
line-height: 16px;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.textarea::-webkit-scrollbar {
|
|
217
|
+
display: none;
|
|
218
|
+
}
|
|
219
|
+
</style>
|