diff --git a/components/i/search/Header.vue b/components/i/search/Header.vue index e78cecc816710459e6959afb05efd8c5ec9819e4..9d9e13c4904966b2aa35d815c32fc39638c10b46 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