Refactor Dashboard.vue.

pull/3445/head
ruibaby 2019-05-04 23:38:15 +08:00
parent 373c6cc040
commit 00ad554234
4 changed files with 146 additions and 76 deletions

View File

@ -4,9 +4,12 @@ const baseUrl = '/api/admin/posts'
const postApi = {} const postApi = {}
postApi.listLatest = () => { postApi.listLatest = (top) => {
return service({ return service({
url: `${baseUrl}/latest`, url: `${baseUrl}/latest`,
params: {
top: top
},
method: 'get' method: 'get'
}) })
} }

View File

@ -53,15 +53,16 @@
> >
<analysis-card <analysis-card
:loading="countsLoading" :loading="countsLoading"
title="附件" title="总访问"
:number="countsData.attachmentCount" :number="countsData.visitCount"
> >
<router-link <a-tooltip slot="action">
:to="{ name:'Attachments' }" <template slot="title">
slot="action" 文章总访问共 {{ countsData.visitCount }}
> </template>
<a-icon type="link" /> <a href="javascript:void(0);">
</router-link> <a-icon type="info-circle-o" /></a>
</a-tooltip>
</analysis-card> </analysis-card>
</a-col> </a-col>
<a-col <a-col
@ -77,9 +78,7 @@
title="建立天数" title="建立天数"
:number="countsData.establishDays" :number="countsData.establishDays"
> >
<a-tooltip <a-tooltip slot="action">
slot="action"
>
<template slot="title"> <template slot="title">
博客建立于 {{ countsData.birthday | moment }} 博客建立于 {{ countsData.birthday | moment }}
</template> </template>
@ -99,11 +98,76 @@
:style="{ marginBottom: '12px' }" :style="{ marginBottom: '12px' }"
> >
<a-card <a-card
:loading="postLoading" :loading="activityLoading"
:bordered="false" :bordered="false"
title="最新文章" title="新动态"
:bodyStyle="{ padding: '16px' }"
> >
最新文章 <div class="card-container">
<a-tabs
defaultActiveKey="1"
type="card"
>
<a-tab-pane key="1">
<span slot="tab">
最近文章
</span>
<a-list :dataSource="postData">
<a-list-item
slot="renderItem"
slot-scope="item, index"
:key="index"
>
<a-list-item-meta>
<a
slot="title"
href="javascript:void(0);"
@click="handleEditPostClick(item)"
>{{ item.title }}</a>
</a-list-item-meta>
<div>{{ item.createTime | timeAgo }}</div>
</a-list-item>
</a-list>
</a-tab-pane>
<a-tab-pane
key="2"
forceRender
>
<span slot="tab">
最近评论
</span>
<a-list
itemLayout="horizontal"
:dataSource="commentData"
>
<a-list-item
slot="renderItem"
slot-scope="item, index"
:key="index"
>
<a-comment :avatar="'//gravatar.loli.net/avatar/'+item.gavatarMd5+'/?s=256&d=mp'">
<template slot="author">
{{ item.author }} 发表在 <a
href="javascript:void(0);"
target="_blank"
>{{ item.post.title }}</a>
</template>
<template slot="actions">
<span>回复</span>
</template>
<p slot="content">{{ item.content }}</p>
<a-tooltip
slot="datetime"
:title="item.createTime | moment"
>
<span>{{ item.createTime | timeAgo }}</span>
</a-tooltip>
</a-comment>
</a-list-item>
</a-list>
</a-tab-pane>
</a-tabs>
</div>
</a-card> </a-card>
</a-col> </a-col>
<a-col <a-col
@ -115,11 +179,29 @@
:style="{ marginBottom: '12px' }" :style="{ marginBottom: '12px' }"
> >
<a-card <a-card
:loading="commentLoading"
:bordered="false" :bordered="false"
title="最新评论" :bodyStyle="{ padding: '16px' }"
> >
最新评论 <template slot="title">
速记 <a-tooltip
slot="action"
title="内容将保存到页面/所有页面/日志页面"
>
<a-icon type="info-circle-o" />
</a-tooltip>
</template>
<a-form layout="vertical">
<a-form-item>
<a-input
type="textarea"
:autosize="{ minRows: 8 }"
v-model="journal.content"
/>
</a-form-item>
<a-form-item>
<a-button type="primary" @click="handleCreateJournalClick"></a-button>
</a-form-item>
</a-form>
</a-card> </a-card>
</a-col> </a-col>
<a-col <a-col
@ -133,9 +215,10 @@
<a-card <a-card
:loading="logLoading" :loading="logLoading"
:bordered="false" :bordered="false"
title="最新日志" title="日志记录"
:bodyStyle="{ padding: '16px' }"
> >
最新日志 日志记录
</a-card> </a-card>
</a-col> </a-col>
</a-row> </a-row>
@ -150,48 +233,7 @@ import postApi from '@/api/post'
import commentApi from '@/api/comment' import commentApi from '@/api/comment'
import logApi from '@/api/log' import logApi from '@/api/log'
import adminApi from '@/api/admin' import adminApi from '@/api/admin'
import journalApi from '@/api/journal'
const postColumns = [
{
title: '标题',
dataIndex: 'title',
scopedSlots: { customRender: 'name' }
},
{
title: '状态',
className: 'status',
dataIndex: 'status',
scopedSlots: { customRender: 'status' }
},
{
title: '最后编辑时间',
dataIndex: 'editTime',
scopedSlots: { customRender: 'editTime' }
}
]
const commentColumns = [
{
title: '评论者',
dataIndex: 'author',
scopedSlots: { customRender: 'name' }
},
{
title: '状态',
className: 'status',
dataIndex: 'status'
},
{
title: '内容',
className: 'content',
dataIndex: 'content'
},
{
title: '发布时间',
dataIndex: 'date'
}
]
export default { export default {
name: 'Dashboard', name: 'Dashboard',
components: { components: {
@ -200,16 +242,14 @@ export default {
}, },
data() { data() {
return { return {
postLoading: true, activityLoading: true,
commentLoading: true,
logLoading: true, logLoading: true,
countsLoading: true, countsLoading: true,
postColumns,
postData: [], postData: [],
commentColumns,
commentData: [], commentData: [],
logData: [], logData: [],
countsData: {} countsData: {},
journal: {}
} }
}, },
created() { created() {
@ -229,21 +269,21 @@ export default {
}, },
methods: { methods: {
listLatestPosts() { listLatestPosts() {
postApi.listLatest().then(response => { postApi.listLatest(5).then(response => {
this.postLoading = false
this.postData = response.data.data this.postData = response.data.data
this.activityLoading = false
}) })
}, },
listLatestComments() { listLatestComments() {
commentApi.listLatest().then(response => { commentApi.listLatest(5, 'PUBLISHED').then(response => {
this.commentLoading = false
this.commentData = response.data.data this.commentData = response.data.data
this.activityLoading = false
}) })
}, },
listLatestLogs() { listLatestLogs() {
logApi.listLatest().then(response => { logApi.listLatest().then(response => {
this.logLoading = false
this.logData = response.data.data this.logData = response.data.data
this.logLoading = false
}) })
}, },
getCounts() { getCounts() {
@ -251,10 +291,28 @@ export default {
this.countsData = response.data.data this.countsData = response.data.data
this.countsLoading = false this.countsLoading = false
}) })
},
handleEditPostClick(post) {
this.$router.push({ name: 'PostEdit', query: { postId: post.id } })
},
handleCreateJournalClick() {
journalApi.create(this.journal).then(response => {
this.$message.success('发表成功!')
this.journal = {}
})
} }
} }
} }
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.ant-comment {
.ant-comment-actions {
margin-bottom: 0 !important;
padding-bottom: 0 !important;
}
}
.ant-comment-inner {
padding: 0 !important;
}
</style> </style>

View File

@ -84,6 +84,9 @@
/>{{ item.commentCount }} />{{ item.commentCount }}
</a> </a>
</span> </span>
<span>
From 微信
</span>
</template> </template>
<template slot="extra"> <template slot="extra">
<a <a
@ -125,10 +128,15 @@
</a-col> </a-col>
</a-row> </a-row>
<a-modal <a-modal v-model="visible">
:title="title" <template slot="title">
v-model="visible" {{ title }} <a-tooltip
> slot="action"
title="只能输入250字"
>
<a-icon type="info-circle-o" />
</a-tooltip>
</template>
<template slot="footer"> <template slot="footer">
<a-button <a-button
key="submit" key="submit"

View File

@ -10,6 +10,7 @@
<a-card <a-card
title="Markdown 文章导入" title="Markdown 文章导入"
:bordered="false" :bordered="false"
:bodyStyle="{ padding: '16px' }"
> >
<p>支持 Hexo/Jekyll 导入并解析元数据</p> <p>支持 Hexo/Jekyll 导入并解析元数据</p>
<a-button <a-button