Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
CI / CI OK (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Issue Close Require / close-issues (push) Has been cancelled
Close stale issues / stale (push) Has been cancelled
162 lines
3.1 KiB
Vue
162 lines
3.1 KiB
Vue
<script lang="ts" setup>
|
|
import { nextTick, ref, watch } from 'vue';
|
|
|
|
import { Button, Input } from 'ant-design-vue';
|
|
|
|
import MIcon from '#/components/icon/icon.vue';
|
|
|
|
const props = defineProps<{
|
|
open: boolean;
|
|
query: string;
|
|
matchCount: number;
|
|
activeIndex: number;
|
|
isDark?: boolean;
|
|
}>();
|
|
|
|
const emit = defineEmits<{
|
|
'update:query': [value: string];
|
|
close: [];
|
|
next: [];
|
|
prev: [];
|
|
}>();
|
|
|
|
const inputRef = ref<InstanceType<typeof Input> | null>(null);
|
|
|
|
watch(
|
|
() => props.open,
|
|
(v) => {
|
|
if (v) {
|
|
void nextTick(() => {
|
|
const el = inputRef.value?.$el?.querySelector?.('input') as
|
|
| HTMLInputElement
|
|
| undefined;
|
|
el?.focus();
|
|
el?.select();
|
|
});
|
|
}
|
|
},
|
|
);
|
|
|
|
function onInput(v: string) {
|
|
emit('update:query', v);
|
|
}
|
|
|
|
function onKeydown(e: KeyboardEvent) {
|
|
if (e.key === 'Escape') {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
emit('close');
|
|
return;
|
|
}
|
|
if (e.key === 'Enter') {
|
|
e.preventDefault();
|
|
if (e.shiftKey) emit('prev');
|
|
else emit('next');
|
|
}
|
|
}
|
|
|
|
const countLabel = () => {
|
|
if (!props.query.trim()) return '';
|
|
if (props.matchCount === 0) return '无匹配';
|
|
const current = props.activeIndex >= 0 ? props.activeIndex + 1 : 0;
|
|
return `${current} / ${props.matchCount}`;
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
v-if="open"
|
|
class="spreadsheet-find-bar"
|
|
:class="{ 'is-dark': isDark }"
|
|
@mousedown.stop
|
|
>
|
|
<Input
|
|
ref="inputRef"
|
|
class="find-input"
|
|
:value="query"
|
|
placeholder="查找"
|
|
size="small"
|
|
allow-clear
|
|
@update:value="onInput"
|
|
@keydown="onKeydown"
|
|
/>
|
|
<span class="find-count">{{ countLabel() }}</span>
|
|
<Button
|
|
class="find-nav-btn"
|
|
size="small"
|
|
type="text"
|
|
title="上一个 (Shift+Enter)"
|
|
:disabled="matchCount === 0"
|
|
@click="emit('prev')"
|
|
>
|
|
<MIcon icon="mdi:chevron-up" />
|
|
</Button>
|
|
<Button
|
|
class="find-nav-btn"
|
|
size="small"
|
|
type="text"
|
|
title="下一个 (Enter)"
|
|
:disabled="matchCount === 0"
|
|
@click="emit('next')"
|
|
>
|
|
<MIcon icon="mdi:chevron-down" />
|
|
</Button>
|
|
<Button
|
|
class="find-close-btn"
|
|
size="small"
|
|
type="text"
|
|
title="关闭 (Esc)"
|
|
@click="emit('close')"
|
|
>
|
|
<MIcon icon="mdi:close" />
|
|
</Button>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped lang="scss">
|
|
.spreadsheet-find-bar {
|
|
position: absolute;
|
|
top: 8px;
|
|
right: 8px;
|
|
z-index: 20;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
padding: 4px 6px;
|
|
background: #fff;
|
|
border: 1px solid #e5e6eb;
|
|
border-radius: 6px;
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
|
|
|
&.is-dark {
|
|
background: #1f1f1f;
|
|
border-color: #424242;
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
|
|
}
|
|
}
|
|
|
|
.find-input {
|
|
width: 180px;
|
|
}
|
|
|
|
.find-count {
|
|
min-width: 52px;
|
|
font-size: 12px;
|
|
color: #86909c;
|
|
text-align: center;
|
|
white-space: nowrap;
|
|
|
|
.is-dark & {
|
|
color: rgba(255, 255, 255, 0.45);
|
|
}
|
|
}
|
|
|
|
.find-nav-btn,
|
|
.find-close-btn {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 0 4px;
|
|
}
|
|
</style>
|