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

246 lines
9.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<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>
<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>
</AdminFilterPanel>
<a-table
:columns="columns"
:data-source="filteredComments"
:loading="loading"
:pagination="{ pageSize: 10 }"
row-key="id"
: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'
/**
* 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'
import AdminFilterPanel from '@/components/admin/AdminFilterPanel.vue'
/**
* 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)
/**
* 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('')
/**
* 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('')
/**
* 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('')
/**
* 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('')
/**
* 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>()
/**
* 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[]>([])
const activeFilterCount = computed(() => [
keyword.value,
shopKeyword.value,
productKeyword.value,
userKeyword.value,
createdRange.value?.length ? 'date' : ''
].filter(Boolean).length)
/**
* 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 }
]
/**
* 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)
}))
/**
* 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))
}
/**
* 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()
}
/**
* 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
}
}
/**
* 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()
}
/**
* 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;
color: var(--text-primary);
}
.page-head p {
margin: 6px 0 0;
color: var(--text-secondary);
}
.search {
width: min(360px, 100%);
}
.comment-cell {
display: grid;
gap: 6px;
}
.comment-cell strong {
color: var(--text-primary);
font-weight: 600;
}
.comment-cell span {
color: var(--text-secondary);
font-size: 12px;
}
@media (max-width: 960px) {
.comments-page {
gap: 12px;
}
.page-head {
align-items: stretch;
}
.page-head > div {
display: none;
}
.search {
width: 100%;
}
}
</style>