Complate comment list.

pull/9/head
ruibaby 2019-04-18 22:20:13 +08:00
parent b87c95138c
commit 039b274bc1
4 changed files with 134 additions and 31 deletions

View File

@ -11,4 +11,30 @@ commentApi.listLatest = () => {
}) })
} }
commentApi.query = params => {
return service({
url: baseUrl,
params: params,
method: 'get'
})
}
commentApi.commentStatus = {
PUBLISHED: {
color: 'green',
status: 'success',
text: '已发布'
},
AUDITING: {
color: 'yellow',
status: 'warning',
text: '待审核'
},
RECYCLE: {
color: 'red',
status: 'error',
text: '回收站'
}
}
export default commentApi export default commentApi

View File

@ -6,23 +6,25 @@
<a-row :gutter="48"> <a-row :gutter="48">
<a-col :md="6" :sm="24"> <a-col :md="6" :sm="24">
<a-form-item label="关键词"> <a-form-item label="关键词">
<a-input v-model="queryParam.id" placeholder /> <a-input v-model="queryParam.keyword"/>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :md="6" :sm="24"> <a-col :md="6" :sm="24">
<a-form-item label="评论状态"> <a-form-item label="评论状态">
<a-select v-model="queryParam.status" placeholder="请选择" defaultValue="0"> <a-select v-model="queryParam.status" placeholder="请选择评论状态">
<a-select-option value="0">已发布</a-select-option> <a-select-option
<a-select-option value="1">待审核</a-select-option> v-for="status in Object.keys(commentStatus)"
<a-select-option value="2">回收站</a-select-option> :key="status"
:value="status"
>{{ commentStatus[status].text }}</a-select-option>
</a-select> </a-select>
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col :md="12" :sm="24"> <a-col :md="12" :sm="24">
<span class="table-page-search-submitButtons"> <span class="table-page-search-submitButtons">
<a-button type="primary" @click="$refs.table.refresh(true)"></a-button> <a-button type="primary" @click="loadComments"></a-button>
<a-button style="margin-left: 8px;" @click="() => (queryParam = {})">重置</a-button> <a-button style="margin-left: 8px;" @click="resetParam"></a-button>
</span> </span>
</a-col> </a-col>
</a-row> </a-row>
@ -32,22 +34,46 @@
<div class="table-operator"> <div class="table-operator">
<a-dropdown> <a-dropdown>
<a-menu slot="overlay"> <a-menu slot="overlay">
<a-menu-item key="1"> <a-icon type="delete" />回收站 </a-menu-item> <a-menu-item key="1">
<a-icon type="delete"/>回收站
</a-menu-item>
</a-menu> </a-menu>
<a-button <a-button>
>批量操作 批量操作
<a-icon type="down" /> <a-icon type="down"/>
</a-button> </a-button>
</a-dropdown> </a-dropdown>
</div> </div>
<div style="margin-top:15px"> <div style="margin-top:15px">
<a-table :columns="columns"> <a-table
:rowKey="comment => comment.id"
:columns="columns"
:dataSource="formattedComments"
:loading="commentsLoading"
:pagination="false"
>
<span slot="status" slot-scope="statusProperty">
<a-badge :status="statusProperty.status"/>
{{ statusProperty.text }}
</span>
<a slot="post" slot-scope="post" :href="post.url" target="_blank">{{ post.title }}</a>
<span slot="createTime" slot-scope="createTime">{{ createTime | timeAgo }}</span>
<span slot="action" slot-scope="text, record"> <span slot="action" slot-scope="text, record">
<a href="javascript:;" @click="editComment(record.id)"></a> <a href="javascript:;" @click="editComment(record.id)"></a>
<a-divider type="vertical" /> <a-divider type="vertical"/>
<a href="javascript:;" @click="deleteComment(record.id)"></a> <a href="javascript:;" @click="deleteComment(record.id)"></a>
</span> </span>
</a-table> </a-table>
<a-row type="flex" justify="end" align="middle">
<a-pagination
class="pagination"
:total="pagination.total"
:pageSizeOptions="['1', '2', '5', '10', '20', '50', '100']"
showSizeChanger
@showSizeChange="onPaginationChange"
@change="onPaginationChange"
/>
</a-row>
</div> </div>
</a-card> </a-card>
</page-view> </page-view>
@ -55,13 +81,10 @@
<script> <script>
import { PageView } from '@/layouts' import { PageView } from '@/layouts'
import commentApi from '@/api/comment'
const columns = [ const columns = [
{ {
title: '#', title: '昵称',
scopedSlots: { customRender: 'serial' }
},
{
title: '评论者',
dataIndex: 'author' dataIndex: 'author'
}, },
{ {
@ -70,11 +93,19 @@ const columns = [
}, },
{ {
title: '评论页面', title: '评论页面',
dataIndex: 'post.id' dataIndex: 'post',
scopedSlots: { customRender: 'post' }
}, },
{ {
title: '日期', title: '日期',
dataIndex: 'createTime' dataIndex: 'createTime',
scopedSlots: { customRender: 'createTime' }
},
{
title: '状态',
className: 'status',
dataIndex: 'statusProperty',
scopedSlots: { customRender: 'status' }
}, },
{ {
title: '操作', title: '操作',
@ -90,24 +121,73 @@ export default {
}, },
data() { data() {
return { return {
//
queryParam: {},
//
columns, columns,
loadData: parameter => {}, pagination: {
current: 1,
pageSize: 10,
sort: null
},
queryParam: {
page: 0,
size: 10,
sort: null,
keyword: null,
categoryId: null,
status: null
},
selectedRowKeys: [], selectedRowKeys: [],
selectedRows: [], selectedRows: [],
options: {} comments: [],
commentsLoading: false,
commentStatus: commentApi.commentStatus
} }
}, },
created() {}, computed: {
formattedComments() {
return this.comments.map(comment => {
comment.statusProperty = this.commentStatus[comment.status]
return comment
})
}
},
created() {
this.loadComments()
},
methods: { methods: {
loadComments() {
this.commentsLoading = true
// Set from pagination
this.queryParam.page = this.pagination.current - 1
this.queryParam.size = this.pagination.pageSize
this.queryParam.sort = this.pagination.sort
commentApi.query(this.queryParam).then(response => {
this.comments = response.data.data.content
this.pagination.total = response.data.data.total
this.commentsLoading = false
})
},
editComment(id) { editComment(id) {
this.$message.success('编辑') this.$message.success('编辑')
}, },
deleteComment(id) { deleteComment(id) {
this.$message.success('删除') this.$message.success('删除')
},
onPaginationChange(page, pageSize) {
this.$log.debug(`Current: ${page}, PageSize: ${pageSize}`)
this.pagination.current = page
this.pagination.pageSize = pageSize
this.loadComments()
},
resetParam() {
this.queryParam.keyword = null
this.queryParam.status = null
this.loadComments()
} }
} }
} }
</script> </script>
<style scoped>
.pagination {
margin-top: 1rem;
}
</style>

View File

@ -191,7 +191,6 @@ export default {
data() { data() {
return { return {
postStatus: postApi.postStatus, postStatus: postApi.postStatus,
//
pagination: { pagination: {
current: 1, current: 1,
pageSize: 10, pageSize: 10,
@ -253,8 +252,6 @@ export default {
], ],
selectedRowKeys: [], selectedRowKeys: [],
selectedRows: [], selectedRows: [],
options: {},
optionAlertShow: false,
categories: [], categories: [],
posts: [], posts: [],
postsLoading: false postsLoading: false

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="page-header-index-wide page-header-wrapper-grid-content-main"> <div class="page-header-index-wide page-header-wrapper-grid-content-main">
<a-row :gutter="24"> <a-row :gutter="12">
<a-col :lg="10" :md="24" :style="{ 'padding-bottom': '12px' }"> <a-col :lg="10" :md="24" :style="{ 'padding-bottom': '12px' }">
<a-card :bodyStyle="{ padding: '16' }" :bordered="false"> <a-card :bodyStyle="{ padding: '16' }" :bordered="false">
<div class="profile-center-avatarHolder"> <div class="profile-center-avatarHolder">