-
+
-
-
-
@@ -152,9 +204,10 @@ onUnmounted(() => {
position: fixed;
top: -64px;
+ right: 0px;
height: 64px;
- width: 100%;
+ width: calc(100% - 96px);
padding-inline: 4px;
@@ -162,10 +215,8 @@ onUnmounted(() => {
background-color: var(--md-sys-color-surface);
- opacity: 0;
overflow: hidden;
transition: var(--md-sys-motion-spring-slow-effect-duration) var(--md-sys-motion-spring-slow-effect);
- visibility: hidden;
z-index: 998;
.actionArea {
@@ -210,7 +261,7 @@ onUnmounted(() => {
height: 56px;
min-width: 0px;
- margin-inline-start: 56px;
+ margin-inline-start: 0px;
padding-block: 0px;
padding-inline: 24px;
@@ -289,8 +340,12 @@ onUnmounted(() => {
}
&.searching {
+ top: 0px;
+
height: 100%;
+ padding: 12px;
+
.actionArea {
.leadingButton {
opacity: 0;
@@ -324,9 +379,17 @@ onUnmounted(() => {
.appbar {
top: 0;
+ width: 100%;
+
opacity: 1;
visibility: visible;
+ .actionArea {
+ .searchInput {
+ margin-inline-start: 56px;
+ }
+ }
+
.searchResult {
height: calc(100% - (80px + 64px));
}
diff --git a/.vitepress/theme/components/Navbar.vue b/.vitepress/theme/components/Navbar.vue
index c89d1df..073e494 100644
--- a/.vitepress/theme/components/Navbar.vue
+++ b/.vitepress/theme/components/Navbar.vue
@@ -2,27 +2,48 @@
import { computed } from "vue";
import { useGlobalData } from "../composables/useGlobalData";
import { useScreenWidth } from "../composables/useScreenWidth";
+import { useSearchState } from "../composables/useSearchState";
const { page, theme } = useGlobalData();
const { isAboveBreakpoint } = useScreenWidth(840);
+const { isSearchActive, activateSearch, deactivateSearch } = useSearchState();
+// 计算导航段落
const navSegment = computed(() => {
const items = theme.value.navSegment;
- if (Array.isArray(items) && items.length > 0) return items;
+ return Array.isArray(items) && items.length > 0 ? items : [];
});
-function isActive(link: string) {
- const current = page.value.relativePath.replace(/(\/index)?\.md$/, "");
- const target = link.replace(/\/$/, "").replace(/\.html$/, "");
- return current === target.replace(/^\//, "") || (target === "" && current === "index");
+// 规范化路径
+function normalizePath(path: string): string {
+ return path.replace(/(\/index)?\.(md|html)$/, "").replace(/\/$/, "");
+}
+
+// 检查链接是否为当前活动链接
+function isActive(link: string): boolean {
+ const currentPath = normalizePath(page.value.relativePath);
+ const targetPath = normalizePath(link);
+
+ return currentPath === targetPath.replace(/^\//, "") || (targetPath === "" && currentPath === "index");
+}
+
+// 处理fab点击事件 - 切换搜索状态
+function toggleSearch(event: MouseEvent) {
+ event.stopPropagation();
+
+ if (isSearchActive.value) {
+ deactivateSearch();
+ } else {
+ activateSearch();
+ }
}