实现删除帖子

main
Hacker-00001 4 weeks ago
parent 17531545b2
commit 54afda80e1

@ -17,38 +17,38 @@
# accessKey: forely
# secretKey: Forely123!
#lj:
# db:
# host: 192.168.125.128
# password: MySQL@5678
# redis:
# host: 192.168.125.128
# port: 6379
# password: Redis@9012
# rabbitmq:
# host: 192.168.125.128
# port: 5672
# username: rabbit_admin
# password: Rabbit@3456
# minio:
# endpoint: http://192.168.125.128:9000
# accessKey: minio_admin
# secretKey: Minio@1234
lj:
db:
host: localhost
password: 123456
host: 192.168.125.128
password: MySQL@5678
redis:
host: localhost
host: 192.168.125.128
port: 6379
password: 123456
password: Redis@9012
rabbitmq:
host: localhost
host: 192.168.125.128
port: 5672
username: guest
password: guest
username: rabbit_admin
password: Rabbit@3456
minio:
endpoint: http://localhost:9005
accessKey: leezt
secretKey: lzt264610
endpoint: http://192.168.125.128:9000
accessKey: minio_admin
secretKey: Minio@1234
#lj:
# db:
# host: localhost
# password: 123456
# redis:
# host: localhost
# port: 6379
# password: 123456
# rabbitmq:
# host: localhost
# port: 5672
# username: guest
# password: guest
# minio:
# endpoint: http://localhost:9005
# accessKey: leezt
# secretKey: lzt264610

@ -1,3 +1,4 @@
USE luojia_channel; -- 指定目标数据库
## 用户表
DROP TABLE IF EXISTS `user`;

@ -103,9 +103,10 @@
</div>
<p class="post-summary">{{ post.summary }}</p>
<div class="post-stats">
<span><i class="icon-view"></i> {{ post.viewCount || 0 }}</span>
<span><i class="icon-like"></i> {{ post.likeCount || 0 }}</span>
<span><i class="icon-comment"></i> {{ post.commentCount || 0 }}</span>
<span><i class="icon-view"></i> 热度 {{ post.viewCount || 0 }}</span>
<span><i class="icon-comment"></i> 评论 {{ post.commentCount || 0 }}</span>
<span><i class="icon-like"></i> {{ post.likeCount || 0 }}</span>
<span v-if="isCurrentUser" class="delete-btn" @click.stop="deletePost(post.id)"></span>
</div>
</div>
</div>
@ -306,6 +307,26 @@ const loadUserPosts = async () => {
}
};
//
const deletePost = async (postId) => {
if (!postId) return;
if (!confirm('确定要删除这条帖子吗?')) return;
try {
const res = await request.delete('/post', { params: { id: postId } });
if (res && res.code === 200) {
//
userPosts.value = userPosts.value.filter(post => post.id !== postId);
ElMessage.success('删除成功');
} else {
ElMessage.error(res.message || '删除失败');
}
} catch (e) {
ElMessage.error(e.response?.message || '删除失败');
}
};
//
const loadMorePosts = () => {
loadUserPosts();
@ -752,4 +773,16 @@ onUnmounted(() => {
color: #999;
margin-top: 4px;
}
.delete-btn {
right: 16px;
bottom: 12px;
color: #fff;
background: #f56c6c;
border: none;
border-radius: 4px;
padding: 4px 12px;
cursor: pointer;
font-size: 12px;
}
</style>
Loading…
Cancel
Save