input-search.vue
2.32 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
<template>
<div class="input-search">
<i class="icon icon-search-new"></i>
<input ref="inpSearch" class="inp-search" type="text" dir="auto" placeholder="Search BLK" autocomplete="off" autocorrect="off" spellcheck="false" :value="value" @input="valueInput" @keyup.enter="enter">
<button class="clear-input" type="button" @click="clear" v-show="value">
<i class="icon icon-error-tip" v-show="!loading"></i>
<i class="icon icon-loading" v-show="loading"></i>
</button>
</div>
</template>
<script>
export default {
name: 'InputSearch',
props: {
value: String,
loading: Boolean
},
data() {
return {
showClear: false
};
},
methods: {
clear() {
this.$emit('input', '');
this.$refs.inpSearch && this.$refs.inpSearch.focus();
},
enter() {
this.$emit('enter', '');
},
focus() {
if (this.$yoho.isAndroid) {
setTimeout(() => {
this.$refs.inpSearch && this.$refs.inpSearch.focus(); // 延迟focus 防止影响进入动画流畅
}, 200);
}
},
valueInput(event) {
this.$emit('input', event.target.value);
}
}
};
</script>
<style lang="scss">
.input-search {
position: relative;
display: flex;
.icon-search-new {
vertical-align: middle;
display: inline-block;
width: 60px;
height: 100%;
position: absolute;
font-size: 28px;
color: #b0b0b0;
left: 0;
top: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
}
.inp-search {
padding: 0 60px;
width: 100%;
background-color: #eeeeee;
border-radius: 8px;
color: #000000;
font-size: 28px;
}
.clear-input {
position: absolute;
top: 0;
right: 0;
bottom: 0;
width: 60px;
display: flex;
align-items: center;
justify-content: center;
border: none;
background: none;
.icon {
color: #b0b0b0;
font-size: 34px;
}
}
.icon-loading {
animation: loading 2s linear infinite;
}
}
</style>