mirror of
https://github.com/shuguangnet/Code-Master.git
synced 2025-01-22 23:48:43 +08:00
优化了论坛MarkDown组件
This commit is contained in:
parent
43767a8fb9
commit
72cdbae057
@ -123,6 +123,15 @@ export const routes: Array<RouteRecordRaw> = [
|
||||
access: ACCESS_ENMU.NOT_LOGIN,
|
||||
icon:IconUserGroup
|
||||
},
|
||||
},{
|
||||
path: "/forum/post/:id",
|
||||
name: "帖子详细",
|
||||
component: () => import("../views/forum/PostDetail.vue"),
|
||||
meta: {
|
||||
hidden: true,
|
||||
access: ACCESS_ENMU.NOT_LOGIN,
|
||||
icon:IconUserGroup
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/noauth",
|
||||
|
@ -32,16 +32,16 @@
|
||||
<template #item="{ item }">
|
||||
<a-list-item class="list-demo-item" action-layout="vertical" style="display: flex;
|
||||
flex-direction: row;justify-content: center;
|
||||
align-items: center;">
|
||||
align-items: center;" @click="PostDetail(item.id)">
|
||||
<template #actions>
|
||||
<span><icon-heart />{{ item.thumbNum }}</span>
|
||||
<span><icon-star />{{ item.favourNum }}</span>
|
||||
<span><icon-message />收藏</span>
|
||||
</template>
|
||||
<template #extra>
|
||||
<div class="image-area">
|
||||
<!-- <div class="image-area">
|
||||
<img alt="arco-design" :src="item.imageSrc || `https://api.miaomc.cn/image/get?${Math.random()}`" />
|
||||
</div>
|
||||
</div> -->
|
||||
</template>
|
||||
<a-list-item-meta :title="item.title" :description="item.content">
|
||||
<template #avatar>
|
||||
@ -85,11 +85,12 @@
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { PostControllerService } from '../../../generated'; // 假设你有这个服务文件
|
||||
import MdEditor from '@/components/MdEditor.vue'
|
||||
import { useRouter } from 'vue-router';
|
||||
// 请求返回的文章数据
|
||||
const article = ref([]); // 存放获取的文章数据
|
||||
// 请求返回的文章数据
|
||||
const isSidebarHidden = ref(false); // 控制侧边栏的显示与隐藏
|
||||
|
||||
const router=useRouter()
|
||||
// 切换侧边栏显示/隐藏
|
||||
const toggleSidebar = () => {
|
||||
isSidebarHidden.value = !isSidebarHidden.value;
|
||||
@ -106,7 +107,7 @@ const selectedCategory = ref(null); // 当前选中的分类
|
||||
|
||||
// 分页数据
|
||||
const paginationProps = reactive({
|
||||
defaultPageSize: 3,
|
||||
defaultPageSize: 5,
|
||||
total: 0,
|
||||
current: 1,
|
||||
onChange: (page) => fetchData(page), // 页码变化时重新获取数据
|
||||
@ -133,7 +134,10 @@ const fetchData = async (page = 1) => {
|
||||
console.error('数据获取失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const PostDetail=(id)=>{
|
||||
console.log(id)
|
||||
router.push('/forum/post/'+id)
|
||||
}
|
||||
// 初始化时加载数据
|
||||
onMounted(() => {
|
||||
fetchData();
|
||||
|
197
src/views/forum/PostDetail.vue
Normal file
197
src/views/forum/PostDetail.vue
Normal file
@ -0,0 +1,197 @@
|
||||
<template>
|
||||
<div class="post-detail-container">
|
||||
<!-- 返回按钮 -->
|
||||
<div class="back-button" @click="goBack">
|
||||
<a-button type="text" icon="arrow-left">返回</a-button>
|
||||
</div>
|
||||
|
||||
<!-- 帖子内容区域 -->
|
||||
<section class="post-content">
|
||||
<h2 class="post-title">{{ postDetail.title }}</h2>
|
||||
<div class="post-info">
|
||||
<a-avatar :src="postDetail.user?.userAvatar" size="small" />
|
||||
<span class="author-name">{{ postDetail.user?.userName }}</span>
|
||||
<span class="post-date">{{ formatDate(postDetail.createTime) }}</span>
|
||||
</div>
|
||||
<MdViewer :value="postDetail.content || ''" :mode="mode"></MdViewer>
|
||||
</section>
|
||||
|
||||
<!-- 评论区域 -->
|
||||
<section class="comments-section">
|
||||
<h3>评论区</h3>
|
||||
<a-list :data="comments" :bordered="false" class="comment-list">
|
||||
<template #item="{ item }">
|
||||
<a-list-item>
|
||||
<a-list-item-meta
|
||||
:title="item.userName"
|
||||
:description="formatDate(item.createTime)"
|
||||
>
|
||||
<template #avatar>
|
||||
<a-avatar :src="item.userAvatar" />
|
||||
</template>
|
||||
</a-list-item-meta>
|
||||
<div>{{ item.content }}</div>
|
||||
</a-list-item>
|
||||
</template>
|
||||
</a-list>
|
||||
|
||||
<!-- 发布评论 -->
|
||||
<div class="add-comment">
|
||||
<a-textarea
|
||||
v-model="newComment"
|
||||
placeholder="输入您的评论..."
|
||||
:auto-size="{ minRows: 2, maxRows: 4 }"
|
||||
/>
|
||||
<a-button type="primary" @click="submitComment">发布评论</a-button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { useRouter, useRoute } from 'vue-router';
|
||||
import { PostControllerService } from '../../../generated'; // 假设你有这个服务文件
|
||||
import MdViewer from '@/components/MdViewer.vue';
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
|
||||
// 获取帖子ID
|
||||
const postId = route.params.id;
|
||||
console.log(postId);
|
||||
// 存储帖子详情
|
||||
const postDetail = reactive({
|
||||
title: '',
|
||||
content: '',
|
||||
user: {},
|
||||
createTime: '',
|
||||
thumbNum: 0,
|
||||
favourNum: 0,
|
||||
});
|
||||
|
||||
// 存储评论列表
|
||||
const comments = ref([]);
|
||||
|
||||
// 存储新评论内容
|
||||
const newComment = ref('');
|
||||
|
||||
// 格式化日期
|
||||
const formatDate = (dateStr) => {
|
||||
const date = new Date(dateStr);
|
||||
return date.toLocaleString();
|
||||
};
|
||||
|
||||
// 获取帖子详情
|
||||
const fetchPostDetail = async () => {
|
||||
try {
|
||||
const res = await PostControllerService.getPostVoByIdUsingGet(postId); // 假设有这样一个接口
|
||||
if (res.code === 0) {
|
||||
Object.assign(postDetail, res.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取帖子详情失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 获取评论
|
||||
const fetchComments = async () => {
|
||||
try {
|
||||
const res = await PostControllerService.getCommentsByPostId({ postId }); // 假设有这样的接口
|
||||
if (res.code === 0) {
|
||||
comments.value = res.data;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取评论失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 提交评论
|
||||
const submitComment = async () => {
|
||||
if (!newComment.value.trim()) {
|
||||
alert('请填写评论内容');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await PostControllerService.addCommentUsingPost({
|
||||
postId,
|
||||
content: newComment.value,
|
||||
});
|
||||
if (res.code === 0) {
|
||||
alert('评论发布成功');
|
||||
newComment.value = ''; // 清空输入框
|
||||
fetchComments(); // 重新获取评论
|
||||
} else {
|
||||
alert('评论发布失败: ' + res.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('评论发布失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
fetchPostDetail();
|
||||
fetchComments();
|
||||
});
|
||||
|
||||
// 返回上一页
|
||||
const goBack = () => {
|
||||
router.back();
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.post-detail-container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background-color: var(--background-secondary-color);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.back-button {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.post-title {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.post-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
color: var(--text-secondary-color);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.post-body {
|
||||
padding: 10px;
|
||||
border: 1px solid #e5e5e5;
|
||||
border-radius: 4px;
|
||||
background-color: var(--background-color);
|
||||
white-space: pre-line;
|
||||
}
|
||||
|
||||
.comments-section {
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
.comment-list {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.add-comment {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.add-comment textarea {
|
||||
flex: 1;
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user