-
{{ name }}
-
{{ duration }}
+
{{ authorId.name }}
+
{{ formatTime(createdAt) }}
@@ -45,20 +58,21 @@ const enteredtopicHeat: (string | number)[] = props.topicHeat.map((item) => {
-
{{ enteredtopicHeat[0] ? enteredtopicHeat[0] : '观看' }}
+
{{ viewed ? format(viewed) : '观看' }}
-
{{ enteredtopicHeat[1] ? enteredtopicHeat[1] : '点赞' }}
+
{{ liked[1] ? format(liked) : '点赞' }}
-
{{ enteredtopicHeat[2] ? enteredtopicHeat[2] : '评论' }}
+
{{ commented[2] ? format(commented) : '评论' }}
{
diff --git a/frontend/composables/useFetchPostData.ts b/frontend/composables/useFetchPostData.ts
index 33607ea..a1b1cbe 100644
--- a/frontend/composables/useFetchPostData.ts
+++ b/frontend/composables/useFetchPostData.ts
@@ -1,7 +1,5 @@
-import type { Ref } from 'vue'
-import type { LocationQueryValue } from 'vue-router'
-import type { IArticleItem, IPanel } from '~~/types/IPanel'
-function formatTime(createdAt: string) {
+import type { IArticleItem } from '~~/types/IArticleItem'
+export function formatTime(createdAt: string): string {
const created = new Date(createdAt)
const now = new Date()
const duration = (now.getTime() - created.getTime()) / 1000 / 60
@@ -18,25 +16,7 @@ function formatTime(createdAt: string) {
ans = `${(duration / 60 / 24 / 30 / 365).toFixed(0)}年前`
return ans
}
-function formatArtlist(artlistData: Ref): IPanel[] {
- return artlistData.value.map((item: IArticleItem) => {
- const tagIds: string[] = []
- item.tagIds.data.forEach((sub) => {
- tagIds.push(sub.tag)
- })
- return {
- id: item.id,
- title: item.title,
- topicHeat: [item.viewed, item.liked, item.commented],
- summary: item.summary,
- cover: item.cover,
- duration: formatTime(item.createdAt),
- tagIds,
- name: item.authorId.name,
- }
- })
-}
-export const useArtlist = (data: IPanel[]) => useState('artlist', () => [...data] as IPanel[])
+export const useArtlist = (data: IArticleItem[]) => useState('artlist', () => [...data] as IArticleItem[])
export const useArtlistPath = (path?: string | undefined) => useState('artlistPath', () => {
if (path === undefined)
return ''
@@ -44,11 +24,11 @@ export const useArtlistPath = (path?: string | undefined) => useState('artlistPa
})
export default async (
type?: string,
- sort: LocationQueryValue | LocationQueryValue[] | string = 'recommended',
+ sort: any = 'recommended',
pagenum = 1,
-): Promise => {
+): Promise => {
type = type || '/'
const { data } = await useFetch(`/api/articles/list?sort=${sort}&type=${type.replace('/', '')}&pageNum=${pagenum}`)
// 数据内容
- return formatArtlist(data)
+ return data.value
}
diff --git a/frontend/types/IPanel.ts b/frontend/types/IArticleItem.ts
similarity index 65%
rename from frontend/types/IPanel.ts
rename to frontend/types/IArticleItem.ts
index a88ac4c..76b3848 100644
--- a/frontend/types/IPanel.ts
+++ b/frontend/types/IArticleItem.ts
@@ -18,17 +18,6 @@ interface IArticleItem {
authorId: IAuthor
tagIds: { data: ITagItem[] }
}
-interface IPanel {
- id: string
- title: string
- topicHeat: number[]
- summary: string
- cover: string
- duration: string
- tagIds: string[]
- name: string
-}
export {
IArticleItem,
- IPanel,
}