更新了搜索功能 (终于!) 1.1.0 版本 Release!
All checks were successful
Build / build-and-test (push) Successful in 33s

This commit is contained in:
2025-05-26 11:23:24 +08:00
parent eb5b28249f
commit f5d3e7ea88
10 changed files with 160 additions and 47 deletions

51
src/stores/search.js Normal file
View File

@ -0,0 +1,51 @@
import { ref } from 'vue'
import { defineStore } from 'pinia'
import { useApiStore } from '@/stores/api.js'
export const useSimpleSearchState = defineStore('simpleSearch', () => {
const api = useApiStore()
const keyword = ref('')
const result = ref([])
const count = ref([])
const pageCount = ref(0)
const currentPage = ref(0)
const state = ref(null)
async function load() {
if (currentPage.value == pageCount.value) state.value = 'finish'
let res = await api.workSimpleSearch(keyword.value, currentPage.value)
res = res.data
if (res.code == 0) {
currentPage.value = res.page
pageCount.value = res.pageCount
count.value = res.count
state.value = import.meta.env.SSR ? 'ssrready' : 'ready'
result.value.push(...res.works)
} else if (res.code == 1) {
if (currentPage.value) {
state.value = 'finish'
} else {
currentPage.value = 1
state.value = 'notfound'
}
}
}
async function start(key) {
if (key == keyword.value) return
keyword.value = key
result.value = []
state.value = 'loading'
currentPage.value = 0
await load()
}
return {
keyword,
result,
count,
pageCount,
currentPage,
state,
load, start
}
})

View File

@ -10,7 +10,7 @@ export const useWorkReadState = defineStore('workRead', () => {
const id = ref(null)
const cid = ref(null)
const summary = ref(null)
const pesud = ref(null)
const pseud = ref(null)
const title = ref(null)
const text = ref(null)
const state = ref('')
@ -25,7 +25,7 @@ export const useWorkReadState = defineStore('workRead', () => {
id.value = data.workId
title.value = data.title
summary.value = [escapeAndFormatText(data.summary)]
pesud.value = data.pesud
pseud.value = data.pseud
text.value = data.text
publishedTime.value = data.stats.publishedTime
wordCount.value = data.stats.wordCount
@ -51,7 +51,7 @@ export const useWorkReadState = defineStore('workRead', () => {
id, cid,
title,
summary,
pesud,
pseud,
text,
state,
publishedTime,