提交 89f68dfa 编写于 作者: View Design's avatar View Design

最多50条

上级 6e3320f4
...@@ -255,7 +255,6 @@ const handleCreateAiTitle = () => { ...@@ -255,7 +255,6 @@ const handleCreateAiTitle = () => {
if (currentCollection) { if (currentCollection) {
state.title = currentCollection.title state.title = currentCollection.title
$updateSearchHistory(currentCollection) $updateSearchHistory(currentCollection)
} }
}, 2000) }, 2000)
} }
......
...@@ -3,11 +3,16 @@ import { useStorage } from '@vueuse/core' ...@@ -3,11 +3,16 @@ import { useStorage } from '@vueuse/core'
const searchHistory = useStorage('search-history', '') const searchHistory = useStorage('search-history', '')
const maxLength = 50
export const useSearchStore = defineStore('search', () => { export const useSearchStore = defineStore('search', () => {
const $searchHistory = computed(() => searchHistory.value ? JSON.parse(searchHistory.value) : []) const $searchHistory = computed(() => searchHistory.value ? JSON.parse(searchHistory.value) : [])
function $setSearchHistory (item) { function $setSearchHistory (item) {
const history = searchHistory.value ? JSON.parse(searchHistory.value) : [] const history = searchHistory.value ? JSON.parse(searchHistory.value) : []
const findIndex = history.findIndex(i => i.c_id === item.c_id) 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) if (findIndex >= 0) history.splice(findIndex, 1)
history.push(item) history.push(item)
searchHistory.value = JSON.stringify(history) searchHistory.value = JSON.stringify(history)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册