From caadd5a48434ce6afb5ad3d1ecea243aea91d048 Mon Sep 17 00:00:00 2001 From: Miao_Spring <539943419@qq.com> Date: Tue, 14 Jan 2025 21:14:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=A7=E7=BB=AD=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E5=89=8D=E7=AB=AF=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/icons/cat.vue | 14 +- components/icons/documents.vue | 14 ++ components/icons/home.vue | 11 + pages/posts/post-[id].vue | 3 +- pages/user/index.vue | 182 +++++++++++++++- pages/user/login.vue | 3 + pages/user/main.vue | 323 ++++++++++++++++++++++++++++- pages/user/main/account.vue | 22 ++ pages/user/main/index.vue | 13 ++ pages/user/main/post.vue | 9 + pages/user/main/post/edit-[id].vue | 15 ++ pages/user/main/post/index.vue | 149 +++++++++++++ pages/user/{ => main}/test.vue | 0 style/default.scss | 7 +- utils/getPost.ts | 33 +++ 15 files changed, 781 insertions(+), 17 deletions(-) create mode 100644 components/icons/documents.vue create mode 100644 components/icons/home.vue create mode 100644 pages/user/main/account.vue create mode 100644 pages/user/main/index.vue create mode 100644 pages/user/main/post.vue create mode 100644 pages/user/main/post/edit-[id].vue create mode 100644 pages/user/main/post/index.vue rename pages/user/{ => main}/test.vue (100%) create mode 100644 utils/getPost.ts diff --git a/components/icons/cat.vue b/components/icons/cat.vue index 045388b..5370f8e 100644 --- a/components/icons/cat.vue +++ b/components/icons/cat.vue @@ -3,6 +3,16 @@ p-id="26076"> + :fill="props.fill" p-id="26077"> - \ No newline at end of file + + + \ No newline at end of file diff --git a/components/icons/documents.vue b/components/icons/documents.vue new file mode 100644 index 0000000..554e9a3 --- /dev/null +++ b/components/icons/documents.vue @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/components/icons/home.vue b/components/icons/home.vue new file mode 100644 index 0000000..f50ab34 --- /dev/null +++ b/components/icons/home.vue @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/pages/posts/post-[id].vue b/pages/posts/post-[id].vue index 7e37eba..b8c9e90 100644 --- a/pages/posts/post-[id].vue +++ b/pages/posts/post-[id].vue @@ -26,8 +26,9 @@ const title = ref('') const renderedData = ref('') +const id = route.params.id as string + onMounted(async () => { - const id = route.params.id as string const _p = new Promise(async (resolve, reject) => { try { diff --git a/pages/user/index.vue b/pages/user/index.vue index d15d41a..1f15ee8 100644 --- a/pages/user/index.vue +++ b/pages/user/index.vue @@ -1,9 +1,11 @@ @@ -13,16 +15,174 @@ import useUserStore from '~/hooks/pinia/useUserStore'; const router = useRouter() const userStore = useUserStore() -const handleLogout = () => { - userStore.logout() - router.push('user/login') -} +// definePageMeta({ +// middleware: [ +// function (to, from) { +// // if (userStore.isLogin === false) { +// // return navigateTo('user/login') +// // } +// console.log(to, from) +// } +// ] +// }) onBeforeMount(() => { if (userStore.isLogin === false) { - return router.push('user/login') + return router.replace('/user/login') + } else { + return router.replace('/user/main') } }) - \ No newline at end of file + \ No newline at end of file diff --git a/pages/user/login.vue b/pages/user/login.vue index bb8b27c..6ac5aea 100644 --- a/pages/user/login.vue +++ b/pages/user/login.vue @@ -33,6 +33,9 @@ const userStore = useUserStore() const username = ref('') const password = ref('') +username.value = '539943419' +password.value = 'zjh030628' +onMounted(() => handleLogin()) let isLogining = false diff --git a/pages/user/main.vue b/pages/user/main.vue index 2bd7c78..90fc02f 100644 --- a/pages/user/main.vue +++ b/pages/user/main.vue @@ -1,13 +1,332 @@ + + \ No newline at end of file diff --git a/pages/user/main/account.vue b/pages/user/main/account.vue new file mode 100644 index 0000000..a5323ae --- /dev/null +++ b/pages/user/main/account.vue @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/pages/user/main/index.vue b/pages/user/main/index.vue new file mode 100644 index 0000000..6103605 --- /dev/null +++ b/pages/user/main/index.vue @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/pages/user/main/post.vue b/pages/user/main/post.vue new file mode 100644 index 0000000..1e324ec --- /dev/null +++ b/pages/user/main/post.vue @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/pages/user/main/post/edit-[id].vue b/pages/user/main/post/edit-[id].vue new file mode 100644 index 0000000..59d37ff --- /dev/null +++ b/pages/user/main/post/edit-[id].vue @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/pages/user/main/post/index.vue b/pages/user/main/post/index.vue new file mode 100644 index 0000000..52d61e6 --- /dev/null +++ b/pages/user/main/post/index.vue @@ -0,0 +1,149 @@ + + + + + \ No newline at end of file diff --git a/pages/user/test.vue b/pages/user/main/test.vue similarity index 100% rename from pages/user/test.vue rename to pages/user/main/test.vue diff --git a/style/default.scss b/style/default.scss index 6032bee..55a35cd 100644 --- a/style/default.scss +++ b/style/default.scss @@ -1,6 +1,7 @@ body,html { padding: 0; - margin: 0 + margin: 0; + -webkit-tap-highlight-color: transparent; } body { @@ -10,4 +11,8 @@ body { font-size: 16px; color: #2c3e50; background-color: #fff +} + +:focus-visible { + outline: #15aa8761 auto 1px; } \ No newline at end of file diff --git a/utils/getPost.ts b/utils/getPost.ts new file mode 100644 index 0000000..42f04da --- /dev/null +++ b/utils/getPost.ts @@ -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 +} \ No newline at end of file