Skip to content

Commit d28d63a

Browse files
authored
Merge pull request #1308 from Wster11/docsSearch
优化文档搜索体验
2 parents a7e495a + b5aa7f0 commit d28d63a

File tree

2 files changed

+595
-80
lines changed

2 files changed

+595
-80
lines changed

docs/.vuepress/components/Navbar.vue

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
<script setup>
2-
import Navbar from 'vuepress-theme-hope/modules/navbar/components/Navbar.js'
3-
import { useThemeLocaleData } from 'vuepress-theme-hope/composables/index'
2+
import Navbar from "vuepress-theme-hope/modules/navbar/components/Navbar.js";
3+
import { useThemeLocaleData } from "vuepress-theme-hope/composables/index";
44
5-
const themeData = useThemeLocaleData()
6-
const extraNavList = themeData.value.extra_nav || []
5+
const themeData = useThemeLocaleData();
6+
const extraNavList = themeData.value.extra_nav || [];
77
</script>
88

99
<template>
1010
<Navbar>
1111
<template #endBefore>
12-
<Docsearch />
12+
<!-- <Docsearch /> -->
13+
<div class="search-box" @click="handleSearch">
14+
<div class="search-input-wrapper">
15+
<div class="search-icon">
16+
<i class="iconfont icon-search"></i>
17+
</div>
18+
<div class="search-input">搜索关键字</div>
19+
</div>
20+
</div>
21+
1322
<el-link
1423
class="extra-link"
1524
:type="item.type"
@@ -22,4 +31,80 @@ const extraNavList = themeData.value.extra_nav || []
2231
</Navbar>
2332
</template>
2433

25-
<style scope></style>
34+
<script>
35+
export default {
36+
methods: {
37+
handleSearch() {
38+
const s = document.getElementById("meta-category")?.innerText;
39+
const url = s ? "/form/search.html?s=" + s : "/form/search.html";
40+
window.open(url, "_blank");
41+
}
42+
}
43+
};
44+
</script>
45+
46+
<style>
47+
.search-box {
48+
display: flex;
49+
align-items: center;
50+
justify-content: center;
51+
background-color: #f8f8f8; /* 背景色 */
52+
border-radius: 20px; /* 圆角 */
53+
padding: 0 0.8em; /* 缩小内边距 */
54+
border: 1px solid rgba(230, 249, 255, 0.15);
55+
cursor: pointer;
56+
transition: all 0.3s;
57+
}
58+
59+
.search-box:hover {
60+
border: 1px solid var(--theme-color);
61+
.search-icon {
62+
color: var(--theme-color);
63+
}
64+
}
65+
66+
.search-input-wrapper {
67+
display: flex;
68+
align-items: center;
69+
}
70+
71+
.search-input {
72+
user-select: none;
73+
background-color: transparent;
74+
font-weight: 500;
75+
color: #999; /* 字体颜色 */
76+
font-size: 14px; /* 缩小字体大小 */
77+
width: 100px; /* 缩小输入框宽度 */
78+
margin-left: 0.4em; /* 缩小间距 */
79+
cursor: pointer;
80+
}
81+
82+
.search-input::placeholder {
83+
color: #a0aec0; /* 占位符颜色 */
84+
}
85+
86+
.search-icon {
87+
display: flex;
88+
align-items: center;
89+
justify-content: center;
90+
cursor: pointer;
91+
color: #cbd5e0; /* 图标颜色 */
92+
font-size: 14px; /* 缩小图标大小 */
93+
transition: color 0.3s;
94+
}
95+
96+
.search-icon:hover {
97+
color: var(--theme-color); /* 悬停时的图标颜色 */
98+
}
99+
100+
.iconfont {
101+
font-size: 14px; /* 缩小图标大小 */
102+
}
103+
104+
/* 小屏幕隐藏输入框 */
105+
@media (max-width: 900px) {
106+
.search-input {
107+
display: none;
108+
}
109+
}
110+
</style>

0 commit comments

Comments
 (0)