mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-10 17:11:10 +08:00
Compare commits
5 Commits
feature/CO
...
codex/refa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7593c8ebf | ||
|
|
4cc2800f09 | ||
|
|
396434a82e | ||
|
|
07c6b53f82 | ||
|
|
930a861ba6 |
@@ -4,6 +4,8 @@
|
|||||||
- [配置环境变量](#配置环境变量)
|
- [配置环境变量](#配置环境变量)
|
||||||
- [配置 IDEA 参数](#配置-idea-参数)
|
- [配置 IDEA 参数](#配置-idea-参数)
|
||||||
- [配置 MySQL](#配置-mysql)
|
- [配置 MySQL](#配置-mysql)
|
||||||
|
- [配置 Redis](#配置-redis)
|
||||||
|
- [配置 RabbitMQ](#配置-rabbitmq)
|
||||||
- [Docker 环境](#docker-环境)
|
- [Docker 环境](#docker-环境)
|
||||||
- [配置环境变量](#配置环境变量-1)
|
- [配置环境变量](#配置环境变量-1)
|
||||||
- [构建并启动镜像](#构建并启动镜像)
|
- [构建并启动镜像](#构建并启动镜像)
|
||||||
@@ -117,14 +119,75 @@ SERVER_PORT=8082
|
|||||||
|
|
||||||
#### 配置 Redis
|
#### 配置 Redis
|
||||||
|
|
||||||
填写环境变量 `.env` 中的 Redis 相关配置并启动 Redis
|
后端的登录态缓存、访问频控等都依赖 Redis,请确保本地有可用的 Redis 实例。
|
||||||
|
|
||||||
```ini
|
1. **启动 Redis 服务**(已有服务可跳过)
|
||||||
REDIS_HOST=<Redis 地址>
|
|
||||||
REDIS_PORT=<Redis 端口>
|
|
||||||
```
|
|
||||||
|
|
||||||
处理完环境问题直接跑起来就能通了
|
```bash
|
||||||
|
docker run --name openisle-redis -p 6379:6379 -d redis:7-alpine
|
||||||
|
```
|
||||||
|
|
||||||
|
该命令会在本机暴露 `6379` 端口。若你已有其他端口的 Redis,可以根据实际情况调整映射关系。
|
||||||
|
|
||||||
|
2. **在 `backend/open-isle.env` 中填写连接信息**
|
||||||
|
|
||||||
|
```ini
|
||||||
|
REDIS_HOST=127.0.0.1
|
||||||
|
REDIS_PORT=6379
|
||||||
|
# 可选:若需要切换逻辑库,可新增此变量,默认使用 0 号库
|
||||||
|
REDIS_DATABASE=0
|
||||||
|
```
|
||||||
|
|
||||||
|
`application.properties` 中的默认值为 `localhost:6379`、数据库 `0`,如果你的环境恰好一致,也可以不额外填写;显式声明可以避免 IDE/运行时读取到意外配置。
|
||||||
|
|
||||||
|
3. **验证连接**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
redis-cli -h 127.0.0.1 -p 6379 ping
|
||||||
|
```
|
||||||
|
|
||||||
|
启动后端后,日志中会出现 `Redis connection established ...`(来自 `RedisConnectionLogger`),说明已成功连通。
|
||||||
|
|
||||||
|
#### 配置 RabbitMQ
|
||||||
|
|
||||||
|
消息通知和 WebSocket 推送链路依赖 RabbitMQ。后端会自动声明交换机与队列,确保本地 RabbitMQ 可用即可。
|
||||||
|
|
||||||
|
1. **启动 RabbitMQ 服务**(推荐包含管理界面)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name openisle-rabbitmq \
|
||||||
|
-e RABBITMQ_DEFAULT_USER=openisle \
|
||||||
|
-e RABBITMQ_DEFAULT_PASS=openisle \
|
||||||
|
-p 5672:5672 -p 15672:15672 \
|
||||||
|
-d rabbitmq:3.13-management
|
||||||
|
```
|
||||||
|
|
||||||
|
管理界面位于 http://127.0.0.1:15672 ,可用于查看队列、交换机等资源。
|
||||||
|
|
||||||
|
2. **同步填写后端与 WebSocket 服务的环境变量**
|
||||||
|
|
||||||
|
```ini
|
||||||
|
# backend/open-isle.env
|
||||||
|
RABBITMQ_HOST=127.0.0.1
|
||||||
|
RABBITMQ_PORT=5672
|
||||||
|
RABBITMQ_USERNAME=openisle
|
||||||
|
RABBITMQ_PASSWORD=openisle
|
||||||
|
|
||||||
|
# 如果需要启动 websocket_service,也需要在 websocket_service.env 中保持一致
|
||||||
|
```
|
||||||
|
|
||||||
|
如果沿用 RabbitMQ 默认的 `guest/guest`,可以不显式设置,Spring Boot 会回退到 `application.properties` 中的默认值 (`localhost:5672`、`guest/guest`、虚拟主机 `/`)。
|
||||||
|
|
||||||
|
3. **确认自动声明的资源**
|
||||||
|
|
||||||
|
- 交换机:`openisle-exchange`
|
||||||
|
- 旧版兼容队列:`notifications-queue`
|
||||||
|
- 分片队列:`notifications-queue-0` ~ `notifications-queue-f`(共 16 个,对应路由键 `notifications.shard.0` ~ `notifications.shard.f`)
|
||||||
|
- 队列持久化默认开启,来自 `rabbitmq.queue.durable=true`,如需仅在本地短暂测试,可在 `application.properties` 中调整该配置。
|
||||||
|
|
||||||
|
启动后端时可在日志中看到 `=== 开始主动声明 RabbitMQ 组件 ===` 与后续的声明结果,也可以在管理界面中查看是否创建成功。
|
||||||
|
|
||||||
|
完成 Redis 与 RabbitMQ 配置后,即可继续启动后端服务。
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.openisle.dto;
|
package com.openisle.dto;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/** Lightweight post metadata used in user profile lists. */
|
/** Lightweight post metadata used in user profile lists. */
|
||||||
@@ -11,6 +12,8 @@ public class PostMetaDto {
|
|||||||
private String title;
|
private String title;
|
||||||
private String snippet;
|
private String snippet;
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
private String category;
|
private CategoryDto category;
|
||||||
|
private List<TagDto> tags;
|
||||||
private long views;
|
private long views;
|
||||||
|
private long commentCount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.openisle.model.Comment;
|
|||||||
import com.openisle.model.Post;
|
import com.openisle.model.Post;
|
||||||
import com.openisle.model.User;
|
import com.openisle.model.User;
|
||||||
import com.openisle.service.*;
|
import com.openisle.service.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
@@ -23,8 +24,10 @@ 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 CategoryMapper categoryMapper;
|
||||||
|
private final TagMapper tagMapper;
|
||||||
|
|
||||||
@Value("${app.snippet-length:50}")
|
@Value("${app.snippet-length}")
|
||||||
private int snippetLength;
|
private int snippetLength;
|
||||||
|
|
||||||
public AuthorDto toAuthorDto(User user) {
|
public AuthorDto toAuthorDto(User user) {
|
||||||
@@ -88,8 +91,10 @@ public class UserMapper {
|
|||||||
dto.setSnippet(content);
|
dto.setSnippet(content);
|
||||||
}
|
}
|
||||||
dto.setCreatedAt(post.getCreatedAt());
|
dto.setCreatedAt(post.getCreatedAt());
|
||||||
dto.setCategory(post.getCategory().getName());
|
dto.setCategory(categoryMapper.toDto(post.getCategory()));
|
||||||
|
dto.setTags(post.getTags().stream().map(tagMapper::toDto).collect(Collectors.toList()));
|
||||||
dto.setViews(post.getViews());
|
dto.setViews(post.getViews());
|
||||||
|
dto.setCommentCount(post.getCommentCount());
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class SearchService {
|
|||||||
private final CategoryRepository categoryRepository;
|
private final CategoryRepository categoryRepository;
|
||||||
private final TagRepository tagRepository;
|
private final TagRepository tagRepository;
|
||||||
|
|
||||||
@org.springframework.beans.factory.annotation.Value("${app.snippet-length:50}")
|
@org.springframework.beans.factory.annotation.Value("${app.snippet-length}")
|
||||||
private int snippetLength;
|
private int snippetLength;
|
||||||
|
|
||||||
public List<User> searchUsers(String keyword) {
|
public List<User> searchUsers(String keyword) {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ app.avatar.base-url=${AVATAR_BASE_URL:https://api.dicebear.com/6.x}
|
|||||||
app.user.posts-limit=${USER_POSTS_LIMIT:10}
|
app.user.posts-limit=${USER_POSTS_LIMIT:10}
|
||||||
app.user.replies-limit=${USER_REPLIES_LIMIT:50}
|
app.user.replies-limit=${USER_REPLIES_LIMIT:50}
|
||||||
# Length of extracted snippets for posts and search (-1 to disable truncation)
|
# Length of extracted snippets for posts and search (-1 to disable truncation)
|
||||||
app.snippet-length=${SNIPPET_LENGTH:50}
|
app.snippet-length=${SNIPPET_LENGTH:200}
|
||||||
|
|
||||||
# Captcha configuration
|
# Captcha configuration
|
||||||
app.captcha.enabled=${CAPTCHA_ENABLED:false}
|
app.captcha.enabled=${CAPTCHA_ENABLED:false}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ body {
|
|||||||
font-family: 'WenQuanYi Micro Hei', 'Helvetica Neue', Arial, sans-serif;
|
font-family: 'WenQuanYi Micro Hei', 'Helvetica Neue', Arial, sans-serif;
|
||||||
background-color: var(--normal-background-color);
|
background-color: var(--normal-background-color);
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
|
text-underline-offset: 4px;
|
||||||
/* 禁止滚动 */
|
/* 禁止滚动 */
|
||||||
/* overflow: hidden; */
|
/* overflow: hidden; */
|
||||||
}
|
}
|
||||||
|
|||||||
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,47 +212,21 @@
|
|||||||
<div class="timeline-list">
|
<div class="timeline-list">
|
||||||
<BaseTimeline :items="filteredTimelineItems">
|
<BaseTimeline :items="filteredTimelineItems">
|
||||||
<template #item="{ item }">
|
<template #item="{ item }">
|
||||||
<template v-if="item.type === 'post'">
|
<!-- <template v-if="item.type === 'post'">
|
||||||
发布了文章
|
发布了文章
|
||||||
<NuxtLink :to="`/posts/${item.post.id}`" class="timeline-link">
|
<NuxtLink :to="`/posts/${item.post.id}`" class="timeline-link">
|
||||||
{{ item.post.title }}
|
{{ item.post.title }}
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
|
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
|
||||||
|
</template> -->
|
||||||
|
<template v-if="item.type === 'post'">
|
||||||
|
<TimelinePostItem :item="item" />
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="item.type === 'comment'">
|
<template v-else-if="item.type === 'comment'">
|
||||||
在
|
<TimelineCommentGroup :item="item" />
|
||||||
<NuxtLink :to="`/posts/${item.comment.post.id}`" class="timeline-link">
|
|
||||||
{{ item.comment.post.title }}
|
|
||||||
</NuxtLink>
|
|
||||||
下评论了
|
|
||||||
<NuxtLink
|
|
||||||
:to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
|
|
||||||
class="timeline-link"
|
|
||||||
>
|
|
||||||
{{ stripMarkdownLength(item.comment.content, 200) }}
|
|
||||||
</NuxtLink>
|
|
||||||
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
|
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="item.type === 'reply'">
|
<template v-else-if="item.type === 'reply'">
|
||||||
在
|
<TimelineCommentGroup :item="item" />
|
||||||
<NuxtLink :to="`/posts/${item.comment.post.id}`" class="timeline-link">
|
|
||||||
{{ item.comment.post.title }}
|
|
||||||
</NuxtLink>
|
|
||||||
下对
|
|
||||||
<NuxtLink
|
|
||||||
:to="`/posts/${item.comment.post.id}#comment-${item.comment.parentComment.id}`"
|
|
||||||
class="timeline-link"
|
|
||||||
>
|
|
||||||
{{ stripMarkdownLength(item.comment.parentComment.content, 200) }}
|
|
||||||
</NuxtLink>
|
|
||||||
回复了
|
|
||||||
<NuxtLink
|
|
||||||
:to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
|
|
||||||
class="timeline-link"
|
|
||||||
>
|
|
||||||
{{ stripMarkdownLength(item.comment.content, 200) }}
|
|
||||||
</NuxtLink>
|
|
||||||
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
|
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="item.type === 'tag'">
|
<template v-else-if="item.type === 'tag'">
|
||||||
创建了标签
|
创建了标签
|
||||||
@@ -326,6 +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 TimelineCommentGroup from '~/components/TimelineCommentGroup.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'
|
||||||
@@ -431,6 +407,57 @@ const fetchSummary = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isDiscussionItem = (item) => item && (item.type === 'comment' || item.type === 'reply')
|
||||||
|
|
||||||
|
const toDateKey = (value) => {
|
||||||
|
const date = new Date(value)
|
||||||
|
if (Number.isNaN(date.getTime())) return ''
|
||||||
|
const month = `${date.getMonth() + 1}`.padStart(2, '0')
|
||||||
|
const day = `${date.getDate()}`.padStart(2, '0')
|
||||||
|
return `${date.getFullYear()}-${month}-${day}`
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
comment: item.comment,
|
||||||
|
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([
|
||||||
fetch(`${API_BASE_URL}/api/users/${username}/posts?limit=50`),
|
fetch(`${API_BASE_URL}/api/users/${username}/posts?limit=50`),
|
||||||
@@ -461,7 +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 = mapped
|
timelineItems.value = combineDiscussionItems(mapped)
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchFollowUsers = async () => {
|
const fetchFollowUsers = async () => {
|
||||||
@@ -903,6 +930,7 @@ watch(selectedTab, async (val) => {
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: gray;
|
color: gray;
|
||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.timeline-snippet {
|
.timeline-snippet {
|
||||||
@@ -939,6 +967,81 @@ watch(selectedTab, async (val) => {
|
|||||||
padding: 40px 0;
|
padding: 40px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ttimeline-container {
|
||||||
|
margin-top: 2px;
|
||||||
|
padding-bottom: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-header {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-title {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
margin-top: 10px;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content-item-main {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 5px;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content-item-icon {
|
||||||
|
width: 20px;
|
||||||
|
height: 25px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-comment-link {
|
||||||
|
color: var(--text-color);
|
||||||
|
word-break: break-word;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-comment-link:hover {
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-article-link {
|
||||||
|
color: var(--text-color);
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 20px;
|
||||||
|
word-break: break-word;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-article-link:hover {
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.article-container {
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 1px solid var(--normal-border-color);
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.follow-container {
|
.follow-container {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
Moon,
|
Moon,
|
||||||
ComputerOne,
|
ComputerOne,
|
||||||
Comment,
|
Comment,
|
||||||
|
CommentOne,
|
||||||
Link,
|
Link,
|
||||||
SlyFaceWhitSmile,
|
SlyFaceWhitSmile,
|
||||||
Like,
|
Like,
|
||||||
@@ -103,6 +104,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|||||||
nuxtApp.vueApp.component('Moon', Moon)
|
nuxtApp.vueApp.component('Moon', Moon)
|
||||||
nuxtApp.vueApp.component('ComputerOne', ComputerOne)
|
nuxtApp.vueApp.component('ComputerOne', ComputerOne)
|
||||||
nuxtApp.vueApp.component('CommentIcon', Comment)
|
nuxtApp.vueApp.component('CommentIcon', Comment)
|
||||||
|
nuxtApp.vueApp.component('CommentOne', CommentOne)
|
||||||
nuxtApp.vueApp.component('LinkIcon', Link)
|
nuxtApp.vueApp.component('LinkIcon', Link)
|
||||||
nuxtApp.vueApp.component('SlyFaceWhitSmile', SlyFaceWhitSmile)
|
nuxtApp.vueApp.component('SlyFaceWhitSmile', SlyFaceWhitSmile)
|
||||||
nuxtApp.vueApp.component('Like', Like)
|
nuxtApp.vueApp.component('Like', Like)
|
||||||
|
|||||||
Reference in New Issue
Block a user