From f83f0100e0c9ba44298859c97efe00298424b6f5 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 13 Feb 2026 21:01:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/composables/useSearchHistory.ts | 48 +++++ src/views/Home.vue | 313 ++++++++++++++++++++++++---- 2 files changed, 325 insertions(+), 36 deletions(-) create mode 100644 src/composables/useSearchHistory.ts diff --git a/src/composables/useSearchHistory.ts b/src/composables/useSearchHistory.ts new file mode 100644 index 0000000..6e10fcc --- /dev/null +++ b/src/composables/useSearchHistory.ts @@ -0,0 +1,48 @@ +import { ref, readonly } from 'vue' + +const STORAGE_KEY = 'polyclient_search_history' +const MAX_HISTORY = 10 + +const history = ref([]) + +function loadHistory() { + try { + const raw = localStorage.getItem(STORAGE_KEY) + history.value = raw ? JSON.parse(raw) : [] + } catch { + history.value = [] + } +} + +function saveHistory() { + try { + localStorage.setItem(STORAGE_KEY, JSON.stringify(history.value)) + } catch { + // ignore + } +} + +export function useSearchHistory() { + const list = readonly(history) + + function add(keyword: string) { + const k = keyword.trim() + if (!k) return + history.value = [k, ...history.value.filter((h) => h !== k)].slice(0, MAX_HISTORY) + saveHistory() + } + + function remove(index: number) { + history.value = history.value.filter((_, i) => i !== index) + saveHistory() + } + + function clearAll() { + history.value = [] + saveHistory() + } + + loadHistory() + + return { list, add, remove, clearAll } +} diff --git a/src/views/Home.vue b/src/views/Home.vue index 443e3cb..932374a 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,18 +1,90 @@