From 9b53479ab6bc4370173d74cf7a49da94898a2536 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 8 Sep 2025 13:04:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20changelog=E5=89=8D=E7=AB=AFui=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/PostChangeLogItem.vue | 3 +- frontend_nuxt/pages/posts/[id]/index.vue | 64 ++++++++++++++++--- frontend_nuxt/plugins/iconpark.client.ts | 4 ++ 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/frontend_nuxt/components/PostChangeLogItem.vue b/frontend_nuxt/components/PostChangeLogItem.vue index d962171b6..6c0b6237c 100644 --- a/frontend_nuxt/components/PostChangeLogItem.vue +++ b/frontend_nuxt/components/PostChangeLogItem.vue @@ -31,7 +31,8 @@ const props = defineProps({ log: Object }) .change-log-container { display: flex; flex-direction: column; - padding: 4px 0; + padding-bottom: 30px; + opacity: 0.7; } .change-log-user { font-weight: bold; diff --git a/frontend_nuxt/pages/posts/[id]/index.vue b/frontend_nuxt/pages/posts/[id]/index.vue index 3ddb9c7ad..d2bb041bf 100644 --- a/frontend_nuxt/pages/posts/[id]/index.vue +++ b/frontend_nuxt/pages/posts/[id]/index.vue @@ -134,7 +134,7 @@ :post-closed="closed" @deleted="onCommentDeleted" /> - + @@ -229,11 +229,7 @@ const subscribed = ref(false) const commentSort = ref('NEWEST') const isFetchingComments = ref(false) const isMobile = useIsMobile() -const timelineItems = computed(() => { - const cs = comments.value.map((c) => ({ ...c, kind: 'comment' })) - const ls = changeLogs.value.map((l) => ({ ...l, kind: 'log' })) - return [...cs, ...ls].sort((a, b) => new Date(a.time) - new Date(b.time)) -}) +const timelineItems = ref([]) const headerHeight = import.meta.client ? parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--header-height')) || 0 @@ -337,20 +333,51 @@ const mapComment = ( ), openReplies: level === 0, src: c.author.avatar, + createdAt: c.createdAt, iconClick: () => navigateTo(`/users/${c.author.id}`), parentUserName: parentUserName, parentUserAvatar: parentUserAvatar, parentUserClick: parentUserId ? () => navigateTo(`/users/${parentUserId}`) : null, }) +const changeLogIcon = (l) => { + if (l.type === 'CONTENT') { + return 'edit' + } else if (l.type === 'TITLE') { + return 'hashtag-key' + } else if (l.type === 'CATEGORY') { + return 'tag-one' + } else if (l.type === 'TAG') { + return 'tag-one' + } else if (l.type === 'CLOSED') { + if (l.newClosed) { + return 'lock-one' + } else { + return 'unlock' + } + } else if (l.type === 'PINNED') { + return 'pin-icon' + } else if (l.type === 'FEATURED') { + if (l.newFeatured) { + return 'star' + } else { + return 'dislike' + } + } else { + return 'info' + } +} + const mapChangeLog = (l) => ({ id: l.id, username: l.username, type: l.type, + createdAt: l.time, time: TimeManager.format(l.time), newClosed: l.newClosed, newPinnedAt: l.newPinnedAt, newFeatured: l.newFeatured, + icon: changeLogIcon(l), }) const getTop = (el) => { @@ -788,7 +815,28 @@ const fetchChangeLogs = async () => { } } -watch(commentSort, fetchComments) +// +// todo(tim): fetchComments, fetchChangeLogs 整合到一个请求,并且取消前端排序 +// +const fetchTimeline = async () => { + await Promise.all([fetchComments(), fetchChangeLogs()]) + const cs = comments.value.map((c) => ({ ...c, kind: 'comment' })) + const ls = changeLogs.value.map((l) => ({ ...l, kind: 'log' })) + + if (commentSort.value === 'NEWEST') { + timelineItems.value = [...cs, ...ls].sort( + (a, b) => new Date(b.createdAt) - new Date(a.createdAt), + ) + } else { + timelineItems.value = [...cs, ...ls].sort( + (a, b) => new Date(a.createdAt) - new Date(b.createdAt), + ) + } +} + +watch(commentSort, async () => { + await fetchTimeline() +}) const jumpToHashComment = async () => { const hash = location.hash @@ -811,7 +859,7 @@ const gotoProfile = () => { const initPage = async () => { scrollTo(0, 0) - await Promise.all([fetchComments(), fetchChangeLogs()]) + await fetchTimeline() const hash = location.hash const id = hash.startsWith('#comment-') ? hash.substring('#comment-'.length) : null if (id) expandCommentPath(id) diff --git a/frontend_nuxt/plugins/iconpark.client.ts b/frontend_nuxt/plugins/iconpark.client.ts index ab87cc6bf..643b8b21f 100644 --- a/frontend_nuxt/plugins/iconpark.client.ts +++ b/frontend_nuxt/plugins/iconpark.client.ts @@ -74,6 +74,8 @@ import { Server, Protection, DoubleDown, + Open, + Dislike, } from '@icon-park/vue-next' export default defineNuxtPlugin((nuxtApp) => { @@ -151,4 +153,6 @@ export default defineNuxtPlugin((nuxtApp) => { nuxtApp.vueApp.component('ServerIcon', Server) nuxtApp.vueApp.component('Protection', Protection) nuxtApp.vueApp.component('DoubleDown', DoubleDown) + nuxtApp.vueApp.component('OpenIcon', Open) + nuxtApp.vueApp.component('Dislike', Dislike) })