Skip to content

Commit ae3d811

Browse files
committed
1
1 parent 80d4402 commit ae3d811

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

src/views/MirrorPage.vue

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="tsx">
2-
import { computed, reactive } from 'vue';
2+
import { computed, reactive, onMounted, onUnmounted, ref } from 'vue';
33
import { useRouter } from 'vue-router';
44
import { useI18n } from 'vue-i18n';
55
import {
@@ -26,6 +26,31 @@ const [entries, setEntries] = useMutableRef([] as SyncEntry[]);
2626
const [loading, setLoading] = useMutableRef(true);
2727
const [filter, setFilter] = useMutableRef('');
2828
const onInput = useDebounce(setFilter);
29+
const searchInputRef = ref<HTMLElement>();
30+
31+
// 捕获 Ctrl+F 事件
32+
function handleKeyDown(event: KeyboardEvent) {
33+
if ((event.ctrlKey || event.metaKey) && event.key === 'f') {
34+
event.preventDefault();
35+
if (searchInputRef.value) {
36+
// 聚焦到搜索框
37+
searchInputRef.value.focus();
38+
// 如果有内容,选中内容以便用户可以直接输入新内容
39+
const inputElement = searchInputRef.value.querySelector('input');
40+
if (inputElement) {
41+
inputElement.select();
42+
}
43+
}
44+
}
45+
}
46+
47+
onMounted(() => {
48+
document.addEventListener('keydown', handleKeyDown);
49+
});
50+
51+
onUnmounted(() => {
52+
document.removeEventListener('keydown', handleKeyDown);
53+
});
2954
3055
usePromiseEffect(fetchEntries, res => {
3156
setEntries(res.sort((a, b) => a.name.localeCompare(b.name)));
@@ -36,9 +61,9 @@ function getAbsolutePath(path: string) {
3661
if (path.startsWith('http')) {
3762
return path;
3863
} else if (path.startsWith('/')) {
39-
return window.location.href + path;
64+
return window.location.href.replace(/\/$/, '') + path;
4065
}
41-
return window.location.href + '/' + path;
66+
return window.location.href.replace(/\/$/, '') + '/' + path;
4267
}
4368
4469
function RouteButton({ data }: { data: SyncEntry }) {
@@ -159,7 +184,11 @@ const columns = computed(() =>
159184
<template>
160185
<NH2 prefix="bar">
161186
<span>{{ t('header.mirrors') }}</span>
162-
<NInput :placeholder="t('table.searchText')" @input="onInput">
187+
<NInput
188+
ref="searchInputRef"
189+
:placeholder="t('table.searchText')"
190+
@input="onInput"
191+
>
163192
<template #prefix>
164193
<NIcon>
165194
<SearchOutline />

0 commit comments

Comments
 (0)