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

浏览记录

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