|
|
@ -60,10 +60,12 @@
|
|
|
|
<script setup lang="js" name="PostDetail">
|
|
|
|
<script setup lang="js" name="PostDetail">
|
|
|
|
import { ref, onMounted } from 'vue';
|
|
|
|
import { ref, onMounted } from 'vue';
|
|
|
|
import { useRoute } from 'vue-router';
|
|
|
|
import { useRoute } from 'vue-router';
|
|
|
|
import { usePostDetailStore } from '@/stores/postdetail';
|
|
|
|
import { usePostDetailStore } from '@/stores/postdetail.js';
|
|
|
|
|
|
|
|
import { useUserStore } from '@/stores/user.js';
|
|
|
|
|
|
|
|
|
|
|
|
const route = useRoute();
|
|
|
|
const route = useRoute();
|
|
|
|
const postDetailStore = usePostDetailStore();
|
|
|
|
const postDetailStore = usePostDetailStore();
|
|
|
|
|
|
|
|
const userStore = useUserStore(); // 如果需要用户信息
|
|
|
|
const newComment = ref('');
|
|
|
|
const newComment = ref('');
|
|
|
|
|
|
|
|
|
|
|
|
// 作者信息(如不需要可移除)
|
|
|
|
// 作者信息(如不需要可移除)
|
|
|
@ -81,10 +83,15 @@ function formatTime(timeStr) {
|
|
|
|
|
|
|
|
|
|
|
|
// 发送评论(这里只做前端追加,实际应调用后端接口)
|
|
|
|
// 发送评论(这里只做前端追加,实际应调用后端接口)
|
|
|
|
const sendComment = () => {
|
|
|
|
const sendComment = () => {
|
|
|
|
|
|
|
|
if (!userStore.isLoggedIn) {
|
|
|
|
|
|
|
|
alert('请先登录后再评论');
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (newComment.value.trim()) {
|
|
|
|
if (newComment.value.trim()) {
|
|
|
|
postDetailStore.addComment({
|
|
|
|
postDetailStore.addComment({
|
|
|
|
userAvatar: require('@/assets/default-avatar/boy_1.png'),
|
|
|
|
userAvatar: userStore.userInfo.avatar || require('@/assets/default-avatar/boy_1.png'),
|
|
|
|
userName: '新评论者',
|
|
|
|
userName: userStore.userInfo.username,
|
|
|
|
|
|
|
|
userId: userStore.userInfo.userid,
|
|
|
|
content: newComment.value,
|
|
|
|
content: newComment.value,
|
|
|
|
createTime: new Date().toISOString(),
|
|
|
|
createTime: new Date().toISOString(),
|
|
|
|
likeCount: 0,
|
|
|
|
likeCount: 0,
|
|
|
|