提交 1440249c 编写于 作者: View Design's avatar View Design

浏览记录

上级 393d8670
......@@ -51,7 +51,7 @@
<script setup>
const { $repos } = storeToRefs(useReposStore())
const { $setRepo } = useReposStore()
const { $setFirstRecordTitle, $setSearchHistory } = useSearchStore()
const { $setFirstRecordTitle } = useSearchStore()
const emits = defineEmits([ 'search' ])
const query = ref('')
const selectedRepo = ref('')
......@@ -82,10 +82,6 @@ const handleSearch = async () => {
if (error.value) return
// todo 临时存到pina给搜索使用
$setFirstRecordTitle(query.value)
$setSearchHistory({
title: query.value,
c_id: data.value.data.c_id
})
navigateTo(`/search/${data.value.data.c_id}`)
emits('search')
}
......
......@@ -53,7 +53,7 @@ const route = useRoute()
const { y } = useWindowScroll({ behavior: 'smooth' })
const { directions } = useScroll(window)
const { $firstRecordTitle } = storeToRefs(useSearchStore())
const { $setFirstRecordTitle } = useSearchStore()
const { $setFirstRecordTitle, $setSearchHistory } = useSearchStore()
const state = reactive({
title: '',
query: '',
......@@ -111,6 +111,12 @@ async function init () {
const { info, records } = data.value && data.value.data
initSearchItemInfo(info, records)
initSearchRecords(records)
// 写入本地浏览记录
$setSearchHistory({
title: info.title,
c_id: info.c_id,
type: 'thread'
})
}
await init()
......
......@@ -7,6 +7,8 @@ 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 (findIndex >= 0) history.splice(findIndex, 1)
history.push(item)
searchHistory.value = JSON.stringify(history)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册