From 1cd805c4eb3348b79fc57bd2720328aa6d826969 Mon Sep 17 00:00:00 2001 From: Aresn Date: Thu, 30 May 2024 15:47:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E8=AE=B0=E5=BD=95=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archive/SearchHistory.vue | 145 +++++++++++++++++++++++++++++++++ components/i/Create.vue | 9 +- components/i/Nav.vue | 2 +- components/i/SearchHistory.vue | 105 ++---------------------- pages/md.vue | 15 ---- pages/md2.vue | 8 -- pages/test.vue | 7 -- stores/search.js | 27 ++++-- 8 files changed, 175 insertions(+), 143 deletions(-) create mode 100644 archive/SearchHistory.vue delete mode 100644 pages/md.vue delete mode 100644 pages/md2.vue delete mode 100644 pages/test.vue diff --git a/archive/SearchHistory.vue b/archive/SearchHistory.vue new file mode 100644 index 0000000..f2a1bfc --- /dev/null +++ b/archive/SearchHistory.vue @@ -0,0 +1,145 @@ + + diff --git a/components/i/Create.vue b/components/i/Create.vue index f86d062..f94cb33 100644 --- a/components/i/Create.vue +++ b/components/i/Create.vue @@ -51,7 +51,7 @@ diff --git a/pages/md.vue b/pages/md.vue deleted file mode 100644 index 551fa0d..0000000 --- a/pages/md.vue +++ /dev/null @@ -1,15 +0,0 @@ - - \ No newline at end of file diff --git a/pages/md2.vue b/pages/md2.vue deleted file mode 100644 index 589e4cc..0000000 --- a/pages/md2.vue +++ /dev/null @@ -1,8 +0,0 @@ - - \ No newline at end of file diff --git a/pages/test.vue b/pages/test.vue deleted file mode 100644 index 23d1e60..0000000 --- a/pages/test.vue +++ /dev/null @@ -1,7 +0,0 @@ - - diff --git a/stores/search.js b/stores/search.js index 3467f37..6ded9e0 100644 --- a/stores/search.js +++ b/stores/search.js @@ -1,19 +1,28 @@ import { defineStore } from 'pinia' +import { useStorage } from '@vueuse/core' + +const searchHistory = useStorage('search-history', '') export const useSearchStore = defineStore('search', () => { - const { $isSignIn } = useUserStore() - const $searchHistory = ref([]) - const $firstRecordTitle = ref('') - async function $getSearchHistory () { - if (!$isSignIn) return - const { data } = await useRequest('/v1/chat/completion/list') - $searchHistory.value = data.value.data + const $searchHistory = computed(() => searchHistory.value ? JSON.parse(searchHistory.value) : []) + function $setSearchHistory (item) { + const history = searchHistory.value ? JSON.parse(searchHistory.value) : [] + history.push(item) + searchHistory.value = JSON.stringify(history) + } + function $clearSearchHistory () { + searchHistory.value = '' } + + const $firstRecordTitle = ref('') function $setFirstRecordTitle (article) { $firstRecordTitle.value = article } return { - $searchHistory, $getSearchHistory, - $firstRecordTitle, $setFirstRecordTitle + $searchHistory, + $setSearchHistory, + $clearSearchHistory, + $firstRecordTitle, + $setFirstRecordTitle } }) -- GitLab