index.vue
3.2 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<template>
<div class="input-wrapper" :class="{ active: isExpanded }">
<button class="icon" @click="toggleSearch" type="button">
<svg
width="25px"
height="25px"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M11.5 21C16.7467 21 21 16.7467 21 11.5C21 6.25329 16.7467 2 11.5 2C6.25329 2 2 6.25329 2 11.5C2 16.7467 6.25329 21 11.5 21Z"
stroke="#fff"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
></path>
<path
d="M22 22L20 20"
stroke="#fff"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
></path>
</svg>
</button>
<input
ref="searchInput"
v-model="keyWord"
type="text"
name="searchKeyword"
class="input"
placeholder="输入应用名称回车查找"
@keyup.enter="onSearch"
@blur="handleBlur"
/>
</div>
</template>
<script setup>
const keyWord = ref("");
const isExpanded = ref(false);
const searchInput = ref(null);
function toggleSearch() {
isExpanded.value = !isExpanded.value;
if (isExpanded.value && searchInput.value) {
nextTick(() => {
searchInput.value.focus();
});
}
}
function handleBlur() {
if (!keyWord.value) {
isExpanded.value = false;
}
}
function onSearch() {
if (keyWord.value) {
window.location.href = "/search?keyword=" + keyWord.value;
}
}
</script>
<style scoped>
.input-wrapper {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 15px;
position: relative;
width: 250px;
}
.input {
border-style: none;
height: 40px;
width: 40px;
outline: none;
border-radius: 50%;
transition: 0.5s ease-in-out;
background-color: #5961f9;
box-shadow: 0px 0px 3px #5961f9;
padding-right: 40px;
color: #fff;
}
.input::placeholder,
.input {
font-family:
"Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", "Lucida Sans",
Arial, sans-serif;
font-size: 17px;
}
.input::placeholder {
color: #8f8f8f;
}
.icon {
display: flex;
align-items: center;
justify-content: center;
position: absolute;
right: 0px;
cursor: pointer;
width: 40px;
height: 40px;
outline: none;
border-style: none;
border-radius: 50%;
background-color: transparent;
transition: 0.2s linear;
z-index: 10;
}
.input-wrapper.active .input {
box-shadow: none;
width: 250px;
border-radius: 0px;
background-color: transparent;
border-bottom: 3px solid #5961f9;
transition: all 500ms cubic-bezier(0, 0.11, 0.35, 2);
}
@media (max-width: 768px) {
.input-wrapper {
width: 200px;
gap: 10px;
}
.icon {
width: 44px;
height: 44px;
}
.input {
width: 44px;
height: 44px;
padding-right: 44px;
}
.input::placeholder,
.input {
font-family:
"Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", "Lucida Sans",
Arial, sans-serif;
font-size: 14px;
}
.input-wrapper.active .input {
box-shadow: none;
width: 180px;
border-radius: 0px;
background-color: transparent;
border-bottom: 1.5px solid #5961f9;
transition: all 500ms cubic-bezier(0, 0.11, 0.35, 2);
}
}
</style>