Complete post api and comment api

pull/9/head
johnniang 2019-03-21 10:25:55 +08:00
parent bc017a30da
commit edf9522171
5 changed files with 130 additions and 83 deletions

5
.prettierrc Normal file
View File

@ -0,0 +1,5 @@
{
"printWidth": 120,
"semi": false,
"singleQuote": true
}

View File

@ -64,6 +64,10 @@
"parser": "babel-eslint"
},
"rules": {
"space-before-function-paren": [
"error",
"never"
],
"generator-star-spacing": "off",
"no-mixed-operators": 0,
"vue/max-attributes-per-line": [

14
src/api/comment.js Normal file
View File

@ -0,0 +1,14 @@
import service from '@/utils/service'
const baseUrl = '/admin/api/comments'
const commentApi = {}
commentApi.listLatest = () => {
return service({
url: `${baseUrl}/latest`,
method: 'get'
})
}
export default commentApi

View File

@ -1,5 +1,14 @@
import service from '@/utils/service'
const baseUrl = '/admin/api/posts'
const postApi = {}
postApi.listLatest = () => {
return service({
url: `${baseUrl}/latest`,
method: 'get'
})
}
export default postApi

View File

@ -1,17 +1,45 @@
<template>
<div class="page-header-index-wide">
<a-row :gutter="12">
<a-col :xl="12" :lg="24" :md="24" :sm="24" :xs="24">
<a-card :loading="loading" :bordered="false" title="最新文章" :bodyStyle="{ padding: '0px' }">
<a-table :columns="postColumns" :dataSource="postData" :pagination="false">
<a-col
:xl="12"
:lg="24"
:md="24"
:sm="24"
:xs="24"
>
<a-card
:loading="postLoading"
:bordered="false"
title="最新文章"
:bodyStyle="{ padding: '0px' }"
>
<a-table
:columns="postColumns"
:dataSource="postData"
:pagination="false"
>
</a-table>
</a-card>
</a-col>
<a-col :xl="12" :lg="24" :md="24" :sm="24" :xs="24">
<a-card :loading="loading" :bordered="false" title="最新评论" :bodyStyle="{ padding: '0px' }">
<a-table :columns="commentColumns" :dataSource="commentData" :pagination="false">
<a-col
:xl="12"
:lg="24"
:md="24"
:sm="24"
:xs="24"
>
<a-card
:loading="commentLoading"
:bordered="false"
title="最新评论"
:bodyStyle="{ padding: '0px' }"
>
<a-table
:columns="commentColumns"
:dataSource="commentData"
:pagination="false"
>
</a-table>
</a-card>
</a-col>
@ -20,95 +48,82 @@
</template>
<script>
import postApi from '@/api/post'
import commentApi from '@/api/comment'
const postColumns = [{
const postColumns = [
{
title: '标题',
dataIndex: 'title',
scopedSlots: { customRender: 'name' }
}, {
},
{
title: '状态',
className: 'status',
dataIndex: 'status'
}, {
},
{
title: '发布时间',
dataIndex: 'date'
}]
}
]
const commentColumns = [{
const commentColumns = [
{
title: '评论者',
dataIndex: 'author',
scopedSlots: { customRender: 'name' }
}, {
},
{
title: '状态',
className: 'status',
dataIndex: 'status'
}, {
},
{
title: '内容',
className: 'content',
dataIndex: 'content'
}, {
},
{
title: '发布时间',
dataIndex: 'date'
}]
const postData = [{
key: '1',
title: '测试文章1',
status: '已发布',
date: '2019-03-20'
}, {
key: '2',
title: '测试文章3',
status: '草稿',
date: '2019-03-20'
}, {
key: '3',
title: '测试文章3',
status: '回收站',
date: '2019-03-20'
}]
const commentData = [{
key: '1',
author: 'test1',
status: '已发布',
content: '测试评论1',
date: '2019-03-20'
}, {
key: '2',
author: 'test1',
status: '草稿',
content: '测试评论1',
date: '2019-03-20'
}, {
key: '3',
author: 'test1',
status: '回收站',
content: '测试评论1',
date: '2019-03-20'
}]
}
]
export default {
name: 'Dashboard',
components: {
},
components: {},
data() {
return {
loading: true,
postLoading: true,
commentLoading: true,
postColumns,
postData,
postData: [],
commentColumns,
commentData
commentData: []
}
},
created() {
setTimeout(() => {
this.loading = !this.loading
}, 1000)
this.listLatestPosts()
this.listLatestComments()
},
methods: {
listLatestPosts() {
postApi.listLatest().then(response => {
this.postLoading = false
this.postData = response.data.data
})
},
listLatestComments() {
commentApi.listLatest().then(response => {
this.commentLoading = false
this.commentData = response.data.data
})
}
}
}
</script>
<style lang="less" scoped>
</style>