-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<template> | ||
<div | ||
v-if="searchVisible" | ||
ref="searchRef" | ||
class="fixed top-5 left-50% translate-x--50% rounded-4 overflow-hidden w-400 flex flex-col bg-[--main-background] p-10" | ||
:style="{ | ||
boxShadow: '0px 0px 5px 5px rgba(0, 0, 0, 0.2)' | ||
}" | ||
> | ||
<a-input-search ref="inputRef" v-model="searchText" placeholder="输入关键词,回车键搜索" class="w-full" @keyup.enter="onSearch" /> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { v4 as uuidV4 } from 'uuid'; | ||
import { useSearchBox } from '@/utils/bus'; | ||
import { onClickOutside } from '@vueuse/core'; | ||
const router = useRouter(); | ||
const searchRef = ref(); | ||
const searchText = ref(''); | ||
const inputRef = ref(); | ||
const searchVisible = ref(false); | ||
const searchBox = useSearchBox(); | ||
function openSearchBox() { | ||
searchText.value = ''; | ||
searchVisible.value = true; | ||
nextTick(() => { | ||
inputRef.value.focus(); | ||
}); | ||
} | ||
const unsubscribe = searchBox.on(openSearchBox); | ||
onDeactivated(() => { | ||
unsubscribe(); | ||
}); | ||
onClickOutside(searchRef, () => { | ||
searchVisible.value = false; | ||
}); | ||
function onSearch() { | ||
searchVisible.value = false; | ||
if (!searchText.value) return; | ||
router.push({ | ||
name: 'search', | ||
query: { | ||
keyword: searchText.value, | ||
_uuid: uuidV4() | ||
} | ||
}); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import { useEventBus } from '@vueuse/core'; | ||
|
||
export const OPEN_CHAPTERS_BOX = Symbol(); | ||
export const EVENT_CHAPTERS_BOX = Symbol(); | ||
export const EVENT_SEARCH_BOX = Symbol(); | ||
|
||
export function useOpenChaptersBox() { | ||
return useEventBus(OPEN_CHAPTERS_BOX); | ||
return useEventBus(EVENT_CHAPTERS_BOX); | ||
} | ||
|
||
export function useSearchBox() { | ||
return useEventBus(EVENT_SEARCH_BOX); | ||
} |