From 89f68dfa0fa00d1f99c951a5565385ad4451b0a5 Mon Sep 17 00:00:00 2001 From: Aresn Date: Tue, 4 Jun 2024 10:49:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E5=A4=9A50=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/search/[id].vue | 1 - stores/search.js | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pages/search/[id].vue b/pages/search/[id].vue index 7c41269..79b1556 100644 --- a/pages/search/[id].vue +++ b/pages/search/[id].vue @@ -255,7 +255,6 @@ const handleCreateAiTitle = () => { if (currentCollection) { state.title = currentCollection.title $updateSearchHistory(currentCollection) - } }, 2000) } diff --git a/stores/search.js b/stores/search.js index 8082ea7..887a062 100644 --- a/stores/search.js +++ b/stores/search.js @@ -3,11 +3,16 @@ import { useStorage } from '@vueuse/core' const searchHistory = useStorage('search-history', '') +const maxLength = 50 + export const useSearchStore = defineStore('search', () => { const $searchHistory = computed(() => searchHistory.value ? JSON.parse(searchHistory.value) : []) function $setSearchHistory (item) { const history = searchHistory.value ? JSON.parse(searchHistory.value) : [] const findIndex = history.findIndex(i => i.c_id === item.c_id) + + if (history.length >= maxLength) history.splice(0, 1) + if (findIndex >= 0) history.splice(findIndex, 1) history.push(item) searchHistory.value = JSON.stringify(history) -- GitLab