Files
JayuCloud/JC-Salon-Frontend/src/views/admin/CommentsView.vue
T

246 lines
9.0 KiB
Vue
Raw Normal View History

<template>
<div class="comments-page">
<header class="page-head">
<div>
<h2>评论管理</h2>
<p>查看作品评论与回复,删除不合规内容。</p>
</div>
<a-input-search v-model:value="keyword" class="search" allow-clear placeholder="搜索评论内容" @search="loadComments" />
</header>
2026-05-29 13:30:56 +08:00
<AdminFilterPanel :active-count="activeFilterCount">
<a-input v-model:value="shopKeyword" allow-clear placeholder="店铺" style="width: 160px" @pressEnter="loadComments" />
<a-input v-model:value="productKeyword" allow-clear placeholder="作品" style="width: 160px" @pressEnter="loadComments" />
<a-input v-model:value="userKeyword" allow-clear placeholder="用户" style="width: 160px" @pressEnter="loadComments" />
<a-range-picker v-model:value="createdRange" value-format="YYYY-MM-DD HH:mm:ss" show-time />
<a-button @click="resetFilters">重置筛选</a-button>
2026-05-29 13:30:56 +08:00
</AdminFilterPanel>
<a-table
:columns="columns"
:data-source="filteredComments"
:loading="loading"
:pagination="{ pageSize: 10 }"
row-key="id"
2026-05-29 13:30:56 +08:00
:scroll="{ x: 'max-content' }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'commentContent'">
<div class="comment-cell">
<strong>{{ record.commentContent }}</strong>
<span v-if="record.parentCommentContent">回复:{{ record.parentCommentContent }}</span>
</div>
</template>
<template v-else-if="column.key === 'action'">
<a-popconfirm title="确认删除这条评论?" ok-text="删除" cancel-text="取消" @confirm="deleteComment(record.id)">
<a-button danger type="link">删除</a-button>
</a-popconfirm>
</template>
</template>
</a-table>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { message } from 'ant-design-vue'
2026-05-23 18:44:57 +08:00
/**
* Purpose: AdminCommentVO supports CommentsView.vue by holding or executing the admin comment vo page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { adminCommentApi, type AdminCommentVO } from '@/api/admin'
import type { IdType } from '@/utils/id'
2026-05-29 13:30:56 +08:00
import AdminFilterPanel from '@/components/admin/AdminFilterPanel.vue'
2026-05-23 18:44:57 +08:00
/**
* Purpose: loading supports CommentsView.vue by holding or executing the loading page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const loading = ref(false)
2026-05-23 18:44:57 +08:00
/**
* Purpose: keyword supports CommentsView.vue by holding or executing the keyword page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const keyword = ref('')
2026-05-23 18:44:57 +08:00
/**
* Purpose: shopKeyword supports CommentsView.vue by holding or executing the shop keyword page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const shopKeyword = ref('')
2026-05-23 18:44:57 +08:00
/**
* Purpose: productKeyword supports CommentsView.vue by holding or executing the product keyword page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const productKeyword = ref('')
2026-05-23 18:44:57 +08:00
/**
* Purpose: userKeyword supports CommentsView.vue by holding or executing the user keyword page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const userKeyword = ref('')
2026-05-23 18:44:57 +08:00
/**
* Purpose: createdRange supports CommentsView.vue by holding or executing the created range page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const createdRange = ref<[string, string] | undefined>()
2026-05-23 18:44:57 +08:00
/**
* Purpose: comments supports CommentsView.vue by holding or executing the comments page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const comments = ref<AdminCommentVO[]>([])
2026-05-29 13:30:56 +08:00
const activeFilterCount = computed(() => [
keyword.value,
shopKeyword.value,
productKeyword.value,
userKeyword.value,
createdRange.value?.length ? 'date' : ''
].filter(Boolean).length)
2026-05-23 18:44:57 +08:00
/**
* Purpose: columns supports CommentsView.vue by holding or executing the columns page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const columns = [
{ title: '评论内容', dataIndex: 'commentContent', key: 'commentContent' },
{ title: '用户', dataIndex: 'userNickname', key: 'userNickname', width: 140 },
{ title: '作品', dataIndex: 'productTitle', key: 'productTitle', width: 180 },
{ title: '店铺', dataIndex: 'shopName', key: 'shopName', width: 160 },
{ title: '时间', dataIndex: 'createTime', key: 'createTime', width: 180 },
{ title: '操作', key: 'action', width: 100 }
]
2026-05-23 18:44:57 +08:00
/**
* Purpose: filteredComments supports CommentsView.vue by holding or executing the filtered comments page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const filteredComments = computed(() => comments.value.filter(comment => {
if (!matchText(shopKeyword.value, [comment.shopName, comment.shopId])) return false
if (!matchText(productKeyword.value, [comment.productTitle, comment.productId])) return false
if (!matchText(userKeyword.value, [comment.userNickname, comment.userId])) return false
return matchRange(comment.createTime, createdRange.value)
}))
2026-05-23 18:44:57 +08:00
/**
* Purpose: matchText supports CommentsView.vue by holding or executing the match text page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const matchText = (needle: string, values: any[]) => {
const normalized = needle.trim().toLowerCase()
if (!normalized) return true
return values.some(value => String(value ?? '').toLowerCase().includes(normalized))
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: matchRange supports CommentsView.vue by holding or executing the match range page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const matchRange = (value?: string, range?: [string, string]) => {
if (!range?.length) return true
if (!value) return false
const time = new Date(value).getTime()
return time >= new Date(range[0]).getTime() && time <= new Date(range[1]).getTime()
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: loadComments supports CommentsView.vue by holding or executing the load comments page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const loadComments = async () => {
loading.value = true
try {
comments.value = await adminCommentApi.listComments({ keyword: keyword.value || undefined })
} catch (error: any) {
message.error(error?.message || '评论加载失败')
} finally {
loading.value = false
}
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: deleteComment supports CommentsView.vue by holding or executing the delete comment page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const deleteComment = async (id: IdType) => {
await adminCommentApi.deleteComment(id)
message.success('评论已删除')
await loadComments()
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: resetFilters supports CommentsView.vue by holding or executing the reset filters page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const resetFilters = () => {
keyword.value = ''
shopKeyword.value = ''
productKeyword.value = ''
userKeyword.value = ''
createdRange.value = undefined
loadComments()
}
onMounted(loadComments)
</script>
<style scoped>
.comments-page {
display: grid;
gap: 18px;
}
.page-head {
display: flex;
justify-content: space-between;
gap: 16px;
align-items: flex-start;
}
.page-head h2 {
margin: 0;
font-size: 22px;
2026-05-29 13:30:56 +08:00
color: var(--text-primary);
}
.page-head p {
margin: 6px 0 0;
2026-05-29 13:30:56 +08:00
color: var(--text-secondary);
}
.search {
width: min(360px, 100%);
}
.comment-cell {
display: grid;
gap: 6px;
}
.comment-cell strong {
2026-05-29 13:30:56 +08:00
color: var(--text-primary);
font-weight: 600;
}
.comment-cell span {
2026-05-29 13:30:56 +08:00
color: var(--text-secondary);
font-size: 12px;
}
2026-05-29 13:30:56 +08:00
@media (max-width: 960px) {
.comments-page {
gap: 12px;
}
.page-head {
align-items: stretch;
}
.page-head > div {
display: none;
}
.search {
width: 100%;
}
}
</style>