From 7b63af238eb68de6f36f6b91e79d391864acdf38 Mon Sep 17 00:00:00 2001 From: KUN1007 Date: Sun, 19 Nov 2023 16:02:43 +0800 Subject: [PATCH] feat: pool get topics --- src/api/pool/types/pool.ts | 2 +- src/store/temp/pool.ts | 2 +- src/utils/formatTime.ts | 4 +- src/utils/formatTimeI18n.ts | 10 +++ src/views/pool/Pool.vue | 30 +++++--- src/views/pool/components/Topic.vue | 44 ++++++++--- src/views/pool/components/topic.ts | 111 ---------------------------- src/views/topic/components/Time.vue | 27 ++----- 8 files changed, 72 insertions(+), 158 deletions(-) create mode 100644 src/utils/formatTimeI18n.ts delete mode 100644 src/views/pool/components/topic.ts diff --git a/src/api/pool/types/pool.ts b/src/api/pool/types/pool.ts index 17b73770..0d6db85b 100644 --- a/src/api/pool/types/pool.ts +++ b/src/api/pool/types/pool.ts @@ -1,4 +1,4 @@ -interface PoolTopic { +export interface PoolTopic { tid: number title: string views: number diff --git a/src/store/temp/pool.ts b/src/store/temp/pool.ts index 8af92cf7..54a94d6b 100644 --- a/src/store/temp/pool.ts +++ b/src/store/temp/pool.ts @@ -10,7 +10,7 @@ export const useTempPoolStore = defineStore({ persist: false, state: (): PoolStoreTemp => ({ page: 1, - limit: 0, + limit: 10, sortField: 'time', sortOrder: 'desc', }), diff --git a/src/utils/formatTime.ts b/src/utils/formatTime.ts index ddd0a4fe..7727fbe1 100644 --- a/src/utils/formatTime.ts +++ b/src/utils/formatTime.ts @@ -37,7 +37,7 @@ const languageOptions = { }, } -function replaceTimeUnits(input: string, language: string) { +const replaceTimeUnits = (input: string, language: string) => { const languageOption = (languageOptions as Record)[language] || languageOptions.en @@ -66,7 +66,7 @@ function replaceTimeUnits(input: string, language: string) { } // Format time difference -export function formatTimeDifference(pastTime: number, language: string) { +export const formatTimeDifference = (pastTime: number, language: string) => { const now = dayjs() const diffInSeconds = now.diff(pastTime, 'second') const hint = language === 'en' ? ' ago' : '前' diff --git a/src/utils/formatTimeI18n.ts b/src/utils/formatTimeI18n.ts new file mode 100644 index 00000000..b9eaf129 --- /dev/null +++ b/src/utils/formatTimeI18n.ts @@ -0,0 +1,10 @@ +import dayjs from 'dayjs' +import 'dayjs/locale/en' + +dayjs.locale('en') + +export const formatTimeI18n = (time: number) => { + const formattedENDate = dayjs(time).format('MMMM D, YYYY - h:mm:ss A') + const formattedCNDate = dayjs(time).format('YYYY年MM月DD日-HH:mm:ss 发布') + return { formattedENDate, formattedCNDate } +} diff --git a/src/views/pool/Pool.vue b/src/views/pool/Pool.vue index a4026997..56a5a684 100644 --- a/src/views/pool/Pool.vue +++ b/src/views/pool/Pool.vue @@ -1,19 +1,30 @@