杂务:整理文档并收口 YumiNail 修复
This commit is contained in:
@@ -8,9 +8,17 @@
|
||||
<a-input-search v-model:value="keyword" class="search" allow-clear placeholder="搜索评论内容" @search="loadComments" />
|
||||
</header>
|
||||
|
||||
<div class="admin-filter-bar">
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<a-table
|
||||
:columns="columns"
|
||||
:data-source="comments"
|
||||
:data-source="filteredComments"
|
||||
:loading="loading"
|
||||
:pagination="{ pageSize: 10 }"
|
||||
row-key="id"
|
||||
@@ -33,31 +41,48 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* CommentsView page script.
|
||||
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
|
||||
*/
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { adminCommentApi, type AdminCommentVO } from '@/api/admin'
|
||||
import type { IdType } from '@/utils/id'
|
||||
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
/** keyword is a reactive state variable used by the template and event handlers. */
|
||||
const keyword = ref('')
|
||||
const shopKeyword = ref('')
|
||||
const productKeyword = ref('')
|
||||
const userKeyword = ref('')
|
||||
const createdRange = ref<[string, string] | undefined>()
|
||||
const comments = ref<AdminCommentVO[]>([])
|
||||
|
||||
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: 'shopName', key: 'shopName', width: 160 },
|
||||
{ title: '时间', dataIndex: 'createTime', key: 'createTime', width: 180 },
|
||||
{ title: '操作', key: 'action', width: 100 }
|
||||
]
|
||||
|
||||
/** loadComments is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
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)
|
||||
}))
|
||||
|
||||
const matchText = (needle: string, values: any[]) => {
|
||||
const normalized = needle.trim().toLowerCase()
|
||||
if (!normalized) return true
|
||||
return values.some(value => String(value ?? '').toLowerCase().includes(normalized))
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
const loadComments = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -69,13 +94,21 @@ const loadComments = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
/** deleteComment is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const deleteComment = async (id: IdType) => {
|
||||
await adminCommentApi.deleteComment(id)
|
||||
message.success('评论已删除')
|
||||
await loadComments()
|
||||
}
|
||||
|
||||
const resetFilters = () => {
|
||||
keyword.value = ''
|
||||
shopKeyword.value = ''
|
||||
productKeyword.value = ''
|
||||
userKeyword.value = ''
|
||||
createdRange.value = undefined
|
||||
loadComments()
|
||||
}
|
||||
|
||||
onMounted(loadComments)
|
||||
</script>
|
||||
|
||||
@@ -107,6 +140,12 @@ onMounted(loadComments)
|
||||
width: min(360px, 100%);
|
||||
}
|
||||
|
||||
.admin-filter-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.comment-cell {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
|
||||
Reference in New Issue
Block a user