From ae1dd9c9417471023ba8023bac9cfab405ef5d1c Mon Sep 17 00:00:00 2001 From: Aresn Date: Tue, 28 May 2024 18:06:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E4=BA=AB=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/i/search/Header.vue | 41 +++++++++++++++------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/components/i/search/Header.vue b/components/i/search/Header.vue index e78cecc..9d9e13c 100644 --- a/components/i/search/Header.vue +++ b/components/i/search/Header.vue @@ -98,31 +98,26 @@ function handleBlurTitle () { isEditTitle.value = false emits('update-query', editTitle.value) } -function handleShare (isUpdate) { - const shareType = String(isOpen.value) - return isUpdate && useRequest(`/v1/chat/${route.params.id}/public/${shareType}`, { method: 'post' }) - +async function handleUpdateOpenState (state) { + const { data } = await useRequest(`/v1/chat/${route.params.id}/public/${state}`, { method: 'post' }) + if (data.value) isOpen.value = state } -function handleUpdateOpenState (state) { - const updateOpened = isOpen.value !== state - isOpen.value = state - handleShare(updateOpened) +function handleCopyLink () { + useCopyToClipboard().copy(window.location.href) + toast.add({ + icon: 'i-heroicons-information-circle-20-solid', + timeout: 2000, + title: '链接已复制到剪贴板' + }) } function handleSetOpenState() { - const isUpdate = !isOpen.value - setTimeout(async () => { - if (!isOpen.value) { - await handleShare(isUpdate) - } - if (!isOpen.value) { - isOpen.value = true - } - useCopyToClipboard().copy(window.location.href) - toast.add({ - icon: 'i-heroicons-information-circle-20-solid', - timeout: 2000, - title: '链接已复制到剪贴板' - }) - }, 500) + if (!isOpen.value) { + setTimeout(async () => { + await handleUpdateOpenState(true) + handleCopyLink() + }, 500) + } else { + handleCopyLink() + } } \ No newline at end of file -- GitLab