From 4cbd03217678a9426806f98828d76f2da664ba20 Mon Sep 17 00:00:00 2001 From: enncy <877526278@qq.com> Date: Tue, 31 May 2022 00:01:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(core):=20=E6=90=9C=E7=B4=A2=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E9=A1=B5=E9=9D=A2=E6=96=B0=E5=A2=9E=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E9=A2=98=E7=9B=AE=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/src/components/SearchResults.tsx | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/packages/core/src/components/SearchResults.tsx b/packages/core/src/components/SearchResults.tsx index 9ccc4b5d..e744b72b 100644 --- a/packages/core/src/components/SearchResults.tsx +++ b/packages/core/src/components/SearchResults.tsx @@ -1,13 +1,14 @@ import { computed, defineComponent, onMounted, Ref, ref } from 'vue'; -import { store } from '../store'; - import { StringUtils } from '../core/utils'; import { WorkResult } from '../core/worker/interface'; +import { useContext } from '../store'; +import { Tooltip } from './Tooltip'; export const SearchResults = defineComponent({ setup () { + const { common } = useContext(); // 判断是否有搜索结果 - const validResult = computed(() => store.workResults); + const validResult = computed(() => common.workResults); const hasResult = computed(() => validResult.value.length > 0); // 当前搜索对象 const currentResult: Ref | undefined> = ref(undefined); @@ -22,7 +23,7 @@ export const SearchResults = defineComponent({ onMounted(() => { // 清空搜索结果 - store.workResults = []; + common.workResults = []; // 监听页面点击事件,然后关闭搜索悬浮窗 document.addEventListener('click', () => { @@ -129,22 +130,53 @@ export const SearchResults = defineComponent({ {validResult.value.map((res, i) => { const title = res.ctx?.elements.title?.[0]; + const isCopy = ref(false); + return (
(currentResult.value = res)} style={{ color: res.result?.finish ? '' : 'red' }} title={res.ctx?.elements.title?.[0].innerText} + onClick={(e) => { + e.stopPropagation(); + }} > + { + if (isCopy.value === false) { + isCopy.value = true; + navigator.clipboard.writeText(title?.innerText.trim() || ''); + setTimeout(() => { + isCopy.value = false; + }, 500); + } + }} + > + + {isCopy.value ? '✅' : '📄'} + + + + {i + 1} - + {StringUtils.of(title?.innerText || '') .nowrap() .max(40)