diff --git a/pages/search/[id].vue b/pages/search/[id].vue index 7c412692fc57bab3aaf6fc73ad12eb7f148f544e..79b155620fc94dcfa80562f3be8eec42e3ee5194 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 8082ea7d7898d8a5942e1ec4fb97824de1b88ffa..887a0629db00e26021b0f843aebc09ad1cec6194 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)