feat(评论): 添加评论置顶功能
- 在评论表中添加 priority 字段用于控制置顶权重 - 修改所有评论查询接口按 priority 和 created 排序 - 在管理后台添加置顶权重编辑功能 - 在评论列表显示置顶标识
This commit is contained in:
@@ -18,6 +18,7 @@ export type CommentItem = {
|
||||
contentText: string;
|
||||
contentHtml: string;
|
||||
status: string;
|
||||
priority?: number;
|
||||
ua?: string | null;
|
||||
};
|
||||
|
||||
@@ -118,6 +119,7 @@ export function updateComment(data: {
|
||||
postSlug?: string;
|
||||
contentText: string;
|
||||
status?: string;
|
||||
priority?: number;
|
||||
}): Promise<{ message: string }> {
|
||||
return put<{ message: string }>('/admin/comments/update', {
|
||||
id: data.id,
|
||||
@@ -126,7 +128,8 @@ export function updateComment(data: {
|
||||
url: data.url ?? null,
|
||||
postSlug: data.postSlug,
|
||||
content: data.contentText,
|
||||
status: data.status
|
||||
status: data.status,
|
||||
priority: data.priority
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -76,9 +76,14 @@
|
||||
>
|
||||
</div>
|
||||
<div class="table-cell table-cell-status">
|
||||
<span class="cell-status" :class="`cell-status-${item.status}`">
|
||||
{{ formatStatus(item.status) }}
|
||||
</span>
|
||||
<div class="cell-status-wrapper">
|
||||
<span class="cell-status" :class="`cell-status-${item.status}`">
|
||||
{{ formatStatus(item.status) }}
|
||||
</span>
|
||||
<span v-if="item.priority && item.priority > 1" class="cell-pin-flag">
|
||||
置顶 {{ item.priority }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-cell table-cell-actions">
|
||||
<div class="table-actions">
|
||||
@@ -176,7 +181,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="editVisible" class="modal-overlay" @click.self="closeEdit">
|
||||
<div v-if="editVisible" class="modal-overlay">
|
||||
<div class="modal">
|
||||
<h3 class="modal-title">编辑评论</h3>
|
||||
<div v-if="editForm" class="modal-body">
|
||||
@@ -212,6 +217,10 @@
|
||||
<option value="rejected">已拒绝</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<label class="form-label">置顶权重(1 为不置顶,数值越大越靠前)</label>
|
||||
<input v-model.number="editForm.priority" class="form-input" type="number" min="1" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-actions">
|
||||
<button class="modal-btn secondary" type="button" @click="closeEdit">
|
||||
@@ -267,6 +276,7 @@ const editForm = ref<{
|
||||
postSlug: string;
|
||||
contentText: string;
|
||||
status: string;
|
||||
priority: number;
|
||||
} | null>(null);
|
||||
|
||||
const domainOptions = ref<string[]>([]);
|
||||
@@ -443,6 +453,7 @@ function openEdit(item: CommentItem) {
|
||||
postSlug: item.postSlug || "",
|
||||
contentText: item.contentText,
|
||||
status: item.status,
|
||||
priority: typeof item.priority === "number" && Number.isFinite(item.priority) ? item.priority : 1,
|
||||
};
|
||||
editVisible.value = true;
|
||||
}
|
||||
@@ -465,6 +476,7 @@ async function submitEdit() {
|
||||
const trimmedContent = current.contentText.trim();
|
||||
const trimmedUrl = current.url.trim();
|
||||
const trimmedPostSlug = current.postSlug.trim();
|
||||
const priorityValue = typeof current.priority === "number" && Number.isFinite(current.priority) ? current.priority : 1;
|
||||
const commentIndex = comments.value.findIndex((c) => c.id === current.id);
|
||||
const existingComment = commentIndex !== -1 ? comments.value[commentIndex] : null;
|
||||
const newPostSlug = trimmedPostSlug || existingComment?.postSlug || "";
|
||||
@@ -483,6 +495,7 @@ async function submitEdit() {
|
||||
postSlug: newPostSlug,
|
||||
contentText: trimmedContent,
|
||||
status: current.status,
|
||||
priority: priorityValue,
|
||||
});
|
||||
if (commentIndex !== -1) {
|
||||
comments.value[commentIndex] = {
|
||||
@@ -493,6 +506,7 @@ async function submitEdit() {
|
||||
postSlug: newPostSlug,
|
||||
contentText: trimmedContent,
|
||||
status: current.status,
|
||||
priority: priorityValue,
|
||||
};
|
||||
}
|
||||
closeEdit();
|
||||
|
||||
Reference in New Issue
Block a user