mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-06 05:46:05 +00:00
Compare commits
1 Commits
codex/refa
...
codex/refa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7593c8ebf |
@@ -24,8 +24,8 @@ public class UserMapper {
|
|||||||
private final PostReadService postReadService;
|
private final PostReadService postReadService;
|
||||||
private final LevelService levelService;
|
private final LevelService levelService;
|
||||||
private final MedalService medalService;
|
private final MedalService medalService;
|
||||||
private final TagMapper tagMapper;
|
|
||||||
private final CategoryMapper categoryMapper;
|
private final CategoryMapper categoryMapper;
|
||||||
|
private final TagMapper tagMapper;
|
||||||
|
|
||||||
@Value("${app.snippet-length}")
|
@Value("${app.snippet-length}")
|
||||||
private int snippetLength;
|
private int snippetLength;
|
||||||
@@ -93,11 +93,8 @@ public class UserMapper {
|
|||||||
dto.setCreatedAt(post.getCreatedAt());
|
dto.setCreatedAt(post.getCreatedAt());
|
||||||
dto.setCategory(categoryMapper.toDto(post.getCategory()));
|
dto.setCategory(categoryMapper.toDto(post.getCategory()));
|
||||||
dto.setTags(post.getTags().stream().map(tagMapper::toDto).collect(Collectors.toList()));
|
dto.setTags(post.getTags().stream().map(tagMapper::toDto).collect(Collectors.toList()));
|
||||||
if (post.getLastReplyAt() == null) {
|
|
||||||
commentService.updatePostCommentStats(post);
|
|
||||||
}
|
|
||||||
dto.setCommentCount(post.getCommentCount());
|
|
||||||
dto.setViews(post.getViews());
|
dto.setViews(post.getViews());
|
||||||
|
dto.setCommentCount(post.getCommentCount());
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
import com.openisle.dto.CommentInfoDto;
|
import com.openisle.dto.CommentInfoDto;
|
||||||
import com.openisle.dto.PostMetaDto;
|
import com.openisle.dto.PostMetaDto;
|
||||||
import com.openisle.dto.UserDto;
|
import com.openisle.dto.UserDto;
|
||||||
|
import com.openisle.mapper.CategoryMapper;
|
||||||
import com.openisle.mapper.TagMapper;
|
import com.openisle.mapper.TagMapper;
|
||||||
import com.openisle.mapper.UserMapper;
|
import com.openisle.mapper.UserMapper;
|
||||||
import com.openisle.model.User;
|
import com.openisle.model.User;
|
||||||
@@ -64,6 +65,9 @@ class UserControllerTest {
|
|||||||
@MockBean
|
@MockBean
|
||||||
private TagMapper tagMapper;
|
private TagMapper tagMapper;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private CategoryMapper categoryMapper;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getCurrentUser() throws Exception {
|
void getCurrentUser() throws Exception {
|
||||||
User u = new User();
|
User u = new User();
|
||||||
|
|||||||
@@ -1,168 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="timeline-container">
|
|
||||||
<div class="timeline-header">
|
|
||||||
<div class="timeline-title">{{ headerText }}</div>
|
|
||||||
<div class="timeline-date">{{ headerDate }}</div>
|
|
||||||
</div>
|
|
||||||
<div class="comment-content">
|
|
||||||
<div v-for="entry in entries" :key="entry.comment.id" class="comment-content-item">
|
|
||||||
<div class="comment-content-item-main">
|
|
||||||
<comment-one class="comment-content-item-icon" />
|
|
||||||
<template v-if="!entry.comment.parentComment">
|
|
||||||
<span class="comment-prefix">
|
|
||||||
在
|
|
||||||
<NuxtLink :to="entry.postLink" class="timeline-link">
|
|
||||||
{{ entry.comment.post.title }}
|
|
||||||
</NuxtLink>
|
|
||||||
下评论了
|
|
||||||
</span>
|
|
||||||
<NuxtLink :to="entry.commentLink" class="timeline-comment-link">
|
|
||||||
{{ stripContent(entry.comment.content) }}
|
|
||||||
</NuxtLink>
|
|
||||||
</template>
|
|
||||||
<template v-else>
|
|
||||||
<span class="comment-prefix">
|
|
||||||
在
|
|
||||||
<NuxtLink :to="entry.postLink" class="timeline-link">
|
|
||||||
{{ entry.comment.post.title }}
|
|
||||||
</NuxtLink>
|
|
||||||
下对
|
|
||||||
<NuxtLink :to="entry.parentLink" class="timeline-link">
|
|
||||||
{{ stripContent(entry.comment.parentComment.content) }}
|
|
||||||
</NuxtLink>
|
|
||||||
回复了
|
|
||||||
</span>
|
|
||||||
<NuxtLink :to="entry.commentLink" class="timeline-comment-link">
|
|
||||||
{{ stripContent(entry.comment.content) }}
|
|
||||||
</NuxtLink>
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
<div class="timeline-date">{{ formatDate(entry.createdAt) }}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { computed } from 'vue'
|
|
||||||
import { stripMarkdownLength } from '~/utils/markdown'
|
|
||||||
import TimeManager from '~/utils/time'
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
item: {
|
|
||||||
type: Object,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const entries = computed(() =>
|
|
||||||
(props.item.entries || []).map((entry) => ({
|
|
||||||
...entry,
|
|
||||||
postLink: `/posts/${entry.comment.post.id}`,
|
|
||||||
commentLink: `/posts/${entry.comment.post.id}#comment-${entry.comment.id}`,
|
|
||||||
parentLink: entry.comment.parentComment
|
|
||||||
? `/posts/${entry.comment.post.id}#comment-${entry.comment.parentComment.id}`
|
|
||||||
: undefined,
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
|
|
||||||
const commentCount = computed(
|
|
||||||
() => entries.value.filter((entry) => !entry.comment.parentComment).length,
|
|
||||||
)
|
|
||||||
|
|
||||||
const replyCount = computed(
|
|
||||||
() => entries.value.filter((entry) => entry.comment.parentComment).length,
|
|
||||||
)
|
|
||||||
|
|
||||||
const headerText = computed(() => {
|
|
||||||
if (commentCount.value && replyCount.value) {
|
|
||||||
return `发布了${commentCount.value}条评论和${replyCount.value}条回复`
|
|
||||||
}
|
|
||||||
if (commentCount.value) {
|
|
||||||
return `发布了${commentCount.value}条评论`
|
|
||||||
}
|
|
||||||
if (replyCount.value) {
|
|
||||||
return `发布了${replyCount.value}条回复`
|
|
||||||
}
|
|
||||||
return '发布了评论'
|
|
||||||
})
|
|
||||||
|
|
||||||
const headerDate = computed(() => TimeManager.format(props.item.createdAt))
|
|
||||||
|
|
||||||
const formatDate = (date) => TimeManager.format(date)
|
|
||||||
|
|
||||||
const stripContent = (content) => stripMarkdownLength(content || '', 200)
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.timeline-container {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-header {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-title {
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-date {
|
|
||||||
color: var(--text-color-secondary);
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comment-content {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comment-content-item {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comment-content-item-main {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comment-content-item-icon {
|
|
||||||
color: var(--primary-color);
|
|
||||||
font-size: 18px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.comment-prefix {
|
|
||||||
color: var(--text-color-secondary);
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-comment-link {
|
|
||||||
display: inline-flex;
|
|
||||||
gap: 6px;
|
|
||||||
align-items: center;
|
|
||||||
color: var(--text-color);
|
|
||||||
font-size: 15px;
|
|
||||||
line-height: 1.6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-comment-link:hover {
|
|
||||||
color: var(--primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-link {
|
|
||||||
color: var(--primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-link:hover {
|
|
||||||
color: var(--primary-color-hover);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="timeline-container">
|
|
||||||
<div class="timeline-header">
|
|
||||||
<div class="timeline-title">发布了文章</div>
|
|
||||||
<div class="timeline-date">{{ formattedDate }}</div>
|
|
||||||
</div>
|
|
||||||
<div class="article-container">
|
|
||||||
<NuxtLink :to="postLink" class="timeline-article-link">
|
|
||||||
{{ props.item.post.title }}
|
|
||||||
</NuxtLink>
|
|
||||||
<div class="timeline-snippet">
|
|
||||||
{{ postSnippet }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { computed } from 'vue'
|
|
||||||
import { stripMarkdown } from '~/utils/markdown'
|
|
||||||
import TimeManager from '~/utils/time'
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
item: {
|
|
||||||
type: Object,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const formattedDate = computed(() => TimeManager.format(props.item.createdAt))
|
|
||||||
const postLink = computed(() => `/posts/${props.item.post.id}`)
|
|
||||||
const postSnippet = computed(() => stripMarkdown(props.item.post?.snippet ?? ''))
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.timeline-container {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-header {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-title {
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-date {
|
|
||||||
color: var(--text-color-secondary);
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.article-container {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-article-link {
|
|
||||||
font-size: 18px;
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--text-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-article-link:hover {
|
|
||||||
color: var(--primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.timeline-snippet {
|
|
||||||
color: var(--text-color-secondary);
|
|
||||||
font-size: 14px;
|
|
||||||
line-height: 1.6;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
185
frontend_nuxt/components/TimelineCommentGroup.vue
Normal file
185
frontend_nuxt/components/TimelineCommentGroup.vue
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
<template>
|
||||||
|
<div class="timeline-container">
|
||||||
|
<div class="timeline-header">
|
||||||
|
<div class="timeline-title">{{ headerText }}</div>
|
||||||
|
<div class="timeline-date">{{ formattedDate }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="comment-content" v-if="entries.length > 0">
|
||||||
|
<div class="comment-content-item" v-for="entry in entries" :key="entry.comment.id">
|
||||||
|
<div class="comment-content-item-main">
|
||||||
|
<comment-one class="comment-content-item-icon" />
|
||||||
|
<div class="comment-content-item-text">
|
||||||
|
<span class="comment-content-item-prefix">
|
||||||
|
在
|
||||||
|
<NuxtLink :to="`/posts/${entry.comment.post.id}`" class="timeline-link">
|
||||||
|
{{ entry.comment.post.title }}
|
||||||
|
</NuxtLink>
|
||||||
|
<template v-if="entry.comment.parentComment">
|
||||||
|
下对
|
||||||
|
<NuxtLink
|
||||||
|
:to="`/posts/${entry.comment.post.id}#comment-${entry.comment.parentComment.id}`"
|
||||||
|
class="timeline-link"
|
||||||
|
>
|
||||||
|
{{ parentSnippet(entry) }}
|
||||||
|
</NuxtLink>
|
||||||
|
回复了
|
||||||
|
</template>
|
||||||
|
<template v-else> 下评论了 </template>
|
||||||
|
</span>
|
||||||
|
<NuxtLink
|
||||||
|
:to="`/posts/${entry.comment.post.id}#comment-${entry.comment.id}`"
|
||||||
|
class="timeline-comment-link"
|
||||||
|
>
|
||||||
|
{{ stripContent(entry.comment.content) }}
|
||||||
|
</NuxtLink>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="timeline-date">{{ formatEntryDate(entry.createdAt) }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import { stripMarkdownLength } from '~/utils/markdown'
|
||||||
|
import TimeManager from '~/utils/time'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
item: { type: Object, required: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
const entries = computed(() => {
|
||||||
|
if (Array.isArray(props.item.entries)) {
|
||||||
|
return props.item.entries
|
||||||
|
}
|
||||||
|
if (props.item.comment) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
type: props.item.type,
|
||||||
|
comment: props.item.comment,
|
||||||
|
createdAt: props.item.createdAt,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
return []
|
||||||
|
})
|
||||||
|
|
||||||
|
const formattedDate = computed(() => TimeManager.format(props.item.createdAt))
|
||||||
|
|
||||||
|
const hasReplies = computed(() => entries.value.some((entry) => !!entry.comment.parentComment))
|
||||||
|
const hasComments = computed(() => entries.value.some((entry) => !entry.comment.parentComment))
|
||||||
|
|
||||||
|
const headerText = computed(() => {
|
||||||
|
const count = entries.value.length
|
||||||
|
if (count === 0) return ''
|
||||||
|
if (hasComments.value && hasReplies.value) {
|
||||||
|
return `发布了${count}条评论/回复`
|
||||||
|
}
|
||||||
|
if (hasReplies.value) {
|
||||||
|
return `发布了${count}条回复`
|
||||||
|
}
|
||||||
|
return `发布了${count}条评论`
|
||||||
|
})
|
||||||
|
|
||||||
|
const formatEntryDate = (date) => TimeManager.format(date)
|
||||||
|
const stripContent = (content) => stripMarkdownLength(content ?? '', 200)
|
||||||
|
const parentSnippet = (entry) =>
|
||||||
|
stripMarkdownLength(entry.comment.parentComment?.content ?? '', 200)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.timeline-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: var(--timeline-card-background, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-title {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-date {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--timeline-date-color, #888);
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
padding-bottom: 6px;
|
||||||
|
border-bottom: 1px solid var(--comment-item-border, rgba(0, 0, 0, 0.05));
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content-item:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content-item-main {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content-item-icon {
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content-item-text {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content-item-prefix {
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-comment-link {
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--link-color);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-comment-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-link {
|
||||||
|
color: var(--link-color);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.comment-content-item-prefix,
|
||||||
|
.timeline-comment-link {
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
149
frontend_nuxt/components/TimelinePostItem.vue
Normal file
149
frontend_nuxt/components/TimelinePostItem.vue
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
<template>
|
||||||
|
<div class="timeline-container">
|
||||||
|
<div class="timeline-header">
|
||||||
|
<div class="timeline-title">发布了文章</div>
|
||||||
|
<div class="timeline-date">{{ formattedDate }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="article-container">
|
||||||
|
<NuxtLink :to="postLink" class="timeline-article-link">
|
||||||
|
{{ item.post?.title }}
|
||||||
|
</NuxtLink>
|
||||||
|
<div class="timeline-snippet">
|
||||||
|
{{ strippedSnippet }}
|
||||||
|
</div>
|
||||||
|
<div class="article-meta" v-if="hasMeta">
|
||||||
|
<ArticleCategory v-if="item.post?.category" :category="item.post.category" />
|
||||||
|
<div class="article-tags" v-if="(item.post?.tags?.length ?? 0) > 0">
|
||||||
|
<span class="article-tag" v-for="tag in item.post?.tags" :key="tag.id || tag.name">
|
||||||
|
#{{ tag.name }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="article-comment-count" v-if="item.post?.commentCount !== undefined">
|
||||||
|
<comment-one class="article-comment-count-icon" />
|
||||||
|
<span>{{ item.post?.commentCount }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import ArticleCategory from '~/components/ArticleCategory.vue'
|
||||||
|
import { stripMarkdown } from '~/utils/markdown'
|
||||||
|
import TimeManager from '~/utils/time'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
item: { type: Object, required: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
const postLink = computed(() => {
|
||||||
|
const id = props.item.post?.id
|
||||||
|
return id ? `/posts/${id}` : '#'
|
||||||
|
})
|
||||||
|
|
||||||
|
const formattedDate = computed(() => TimeManager.format(props.item.createdAt))
|
||||||
|
const strippedSnippet = computed(() => stripMarkdown(props.item.post?.snippet ?? ''))
|
||||||
|
const hasMeta = computed(() => {
|
||||||
|
const tags = props.item.post?.tags ?? []
|
||||||
|
const hasTags = Array.isArray(tags) && tags.length > 0
|
||||||
|
const hasCategory = !!props.item.post?.category
|
||||||
|
const hasCommentCount =
|
||||||
|
props.item.post?.commentCount !== undefined && props.item.post?.commentCount !== null
|
||||||
|
return hasTags || hasCategory || hasCommentCount
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.timeline-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: var(--timeline-card-background, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-title {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-date {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--timeline-date-color, #888);
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-article-link {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--link-color);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-article-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-snippet {
|
||||||
|
color: var(--timeline-snippet-color, #666);
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-meta {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 8px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-tags {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-tag {
|
||||||
|
background-color: var(--article-info-background-color);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 2px 6px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-comment-count {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-comment-count-icon {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.timeline-article-link {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-snippet {
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -212,9 +212,22 @@
|
|||||||
<div class="timeline-list">
|
<div class="timeline-list">
|
||||||
<BaseTimeline :items="filteredTimelineItems">
|
<BaseTimeline :items="filteredTimelineItems">
|
||||||
<template #item="{ item }">
|
<template #item="{ item }">
|
||||||
<ProfileTimelinePostItem v-if="item.type === 'post'" :item="item" />
|
<!-- <template v-if="item.type === 'post'">
|
||||||
<ProfileTimelineCommentGroup v-else-if="item.type === 'comment'" :item="item" />
|
发布了文章
|
||||||
<ProfileTimelineCommentGroup v-else-if="item.type === 'reply'" :item="item" />
|
<NuxtLink :to="`/posts/${item.post.id}`" class="timeline-link">
|
||||||
|
{{ item.post.title }}
|
||||||
|
</NuxtLink>
|
||||||
|
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
|
||||||
|
</template> -->
|
||||||
|
<template v-if="item.type === 'post'">
|
||||||
|
<TimelinePostItem :item="item" />
|
||||||
|
</template>
|
||||||
|
<template v-else-if="item.type === 'comment'">
|
||||||
|
<TimelineCommentGroup :item="item" />
|
||||||
|
</template>
|
||||||
|
<template v-else-if="item.type === 'reply'">
|
||||||
|
<TimelineCommentGroup :item="item" />
|
||||||
|
</template>
|
||||||
<template v-else-if="item.type === 'tag'">
|
<template v-else-if="item.type === 'tag'">
|
||||||
创建了标签
|
创建了标签
|
||||||
<span class="timeline-link" @click="gotoTag(item.tag)">
|
<span class="timeline-link" @click="gotoTag(item.tag)">
|
||||||
@@ -287,8 +300,8 @@ import BasePlaceholder from '~/components/BasePlaceholder.vue'
|
|||||||
import BaseTimeline from '~/components/BaseTimeline.vue'
|
import BaseTimeline from '~/components/BaseTimeline.vue'
|
||||||
import BaseTabs from '~/components/BaseTabs.vue'
|
import BaseTabs from '~/components/BaseTabs.vue'
|
||||||
import LevelProgress from '~/components/LevelProgress.vue'
|
import LevelProgress from '~/components/LevelProgress.vue'
|
||||||
import ProfileTimelineCommentGroup from '~/components/ProfileTimelineCommentGroup.vue'
|
import TimelineCommentGroup from '~/components/TimelineCommentGroup.vue'
|
||||||
import ProfileTimelinePostItem from '~/components/ProfileTimelinePostItem.vue'
|
import TimelinePostItem from '~/components/TimelinePostItem.vue'
|
||||||
import UserList from '~/components/UserList.vue'
|
import UserList from '~/components/UserList.vue'
|
||||||
import { toast } from '~/main'
|
import { toast } from '~/main'
|
||||||
import { authState, getToken } from '~/utils/auth'
|
import { authState, getToken } from '~/utils/auth'
|
||||||
@@ -394,21 +407,56 @@ const fetchSummary = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSameDay = (a, b) => {
|
const isDiscussionItem = (item) => item && (item.type === 'comment' || item.type === 'reply')
|
||||||
const dateA = new Date(a)
|
|
||||||
const dateB = new Date(b)
|
const toDateKey = (value) => {
|
||||||
return (
|
const date = new Date(value)
|
||||||
dateA.getFullYear() === dateB.getFullYear() &&
|
if (Number.isNaN(date.getTime())) return ''
|
||||||
dateA.getMonth() === dateB.getMonth() &&
|
const month = `${date.getMonth() + 1}`.padStart(2, '0')
|
||||||
dateA.getDate() === dateB.getDate()
|
const day = `${date.getDate()}`.padStart(2, '0')
|
||||||
)
|
return `${date.getFullYear()}-${month}-${day}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const createCommentEntry = (item) => ({
|
const combineDiscussionItems = (items) => {
|
||||||
|
const result = []
|
||||||
|
items.forEach((item) => {
|
||||||
|
if (!isDiscussionItem(item)) {
|
||||||
|
result.push(item)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const dateKey = toDateKey(item.createdAt)
|
||||||
|
const last = result[result.length - 1]
|
||||||
|
if (last && isDiscussionItem(last) && last.dateKey === dateKey) {
|
||||||
|
last.entries.push({
|
||||||
type: item.type,
|
type: item.type,
|
||||||
comment: item.comment,
|
comment: item.comment,
|
||||||
createdAt: item.createdAt,
|
createdAt: item.createdAt,
|
||||||
})
|
})
|
||||||
|
if (item.type === 'comment' && last.type === 'reply') {
|
||||||
|
last.type = 'comment'
|
||||||
|
}
|
||||||
|
if (new Date(item.createdAt) > new Date(last.createdAt)) {
|
||||||
|
last.createdAt = item.createdAt
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result.push({
|
||||||
|
type: item.type,
|
||||||
|
icon: item.icon,
|
||||||
|
createdAt: item.createdAt,
|
||||||
|
dateKey,
|
||||||
|
entries: [
|
||||||
|
{
|
||||||
|
type: item.type,
|
||||||
|
comment: item.comment,
|
||||||
|
createdAt: item.createdAt,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
const fetchTimeline = async () => {
|
const fetchTimeline = async () => {
|
||||||
const [postsRes, repliesRes, tagsRes] = await Promise.all([
|
const [postsRes, repliesRes, tagsRes] = await Promise.all([
|
||||||
@@ -440,32 +488,7 @@ const fetchTimeline = async () => {
|
|||||||
})),
|
})),
|
||||||
]
|
]
|
||||||
mapped.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
mapped.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
||||||
|
timelineItems.value = combineDiscussionItems(mapped)
|
||||||
const grouped = []
|
|
||||||
for (const item of mapped) {
|
|
||||||
if (item.type === 'comment') {
|
|
||||||
const last = grouped[grouped.length - 1]
|
|
||||||
if (last && last.type === 'comment' && isSameDay(last.createdAt, item.createdAt)) {
|
|
||||||
last.entries.push(createCommentEntry(item))
|
|
||||||
if (new Date(item.createdAt) > new Date(last.createdAt)) {
|
|
||||||
last.createdAt = item.createdAt
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
grouped.push({
|
|
||||||
...item,
|
|
||||||
entries: [createCommentEntry(item)],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else if (item.type === 'reply') {
|
|
||||||
grouped.push({
|
|
||||||
...item,
|
|
||||||
entries: [createCommentEntry(item)],
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
grouped.push(item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
timelineItems.value = grouped
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchFollowUsers = async () => {
|
const fetchFollowUsers = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user