feat: 继续完成后台前端实现
This commit is contained in:
1 parent
83f5788dee
commit
caadd5a484
15 files changed
+781
-17
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import useDefaultStore from "~/hooks/pinia/useDefaultStore"
|
||||
import usePostStore from "~/hooks/pinia/usePostStore"
|
||||
import useMiaoFetch from "~/hooks/useMiaoFetch"
|
||||
// import usePostStore from "~/hooks/pinia/usePostStore"
|
||||
import type { postContent, postItem } from "~/types/post"
|
||||
|
||||
export default async function getPostList() {
|
||||
const store = useDefaultStore()
|
||||
const cache = store.getCache('posts')
|
||||
if (cache) {
|
||||
return cache as postItem[]
|
||||
}
|
||||
const response = await $fetch('/api/posts/getPostList')
|
||||
const res = response.data
|
||||
store.setCache('posts', res)
|
||||
return res
|
||||
}
|
||||
|
||||
export async function getPostData(id: number | string) {
|
||||
const postStore = usePostStore()
|
||||
const cache = postStore.getPostCache(`${id}`)
|
||||
if (cache) {
|
||||
return cache
|
||||
}
|
||||
const res = await $fetch('/api/posts/getPostContent', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
id
|
||||
}
|
||||
}) as postContent
|
||||
postStore.setPostCache(`${id}`, res)
|
||||
return res
|
||||
}
|
||||
Reference in new issue
Block a user