halo-admin/src/views/dashboard/Dashboard.vue

328 lines
8.7 KiB
Vue
Raw Normal View History

2019-03-19 08:43:49 +00:00
<template>
2019-04-10 12:29:41 +00:00
<page-view>
2019-05-03 15:53:08 +00:00
<a-row :gutter="12">
2019-05-03 09:49:11 +00:00
<a-col
:xl="6"
:lg="6"
:md="12"
:sm="12"
:xs="12"
2019-05-03 15:53:08 +00:00
:style="{ marginBottom: '12px' }"
2019-05-03 09:49:11 +00:00
>
<analysis-card
:loading="countsLoading"
title="文章"
:number="countsData.postCount"
>
2019-05-04 03:05:06 +00:00
<router-link
:to="{ name:'PostList' }"
slot="action"
>
2019-05-03 15:53:08 +00:00
<a-icon type="link" />
</router-link>
2019-05-03 09:49:11 +00:00
</analysis-card>
</a-col>
<a-col
:xl="6"
:lg="6"
:md="12"
:sm="12"
:xs="12"
2019-05-03 15:53:08 +00:00
:style="{ marginBottom: '12px' }"
2019-05-03 09:49:11 +00:00
>
<analysis-card
:loading="countsLoading"
title="评论"
:number="countsData.commentCount"
>
2019-05-04 03:05:06 +00:00
<router-link
:to="{ name:'Comments' }"
slot="action"
>
2019-05-03 15:53:08 +00:00
<a-icon type="link" />
</router-link>
2019-05-03 09:49:11 +00:00
</analysis-card>
</a-col>
<a-col
:xl="6"
:lg="6"
:md="12"
:sm="12"
:xs="12"
2019-05-03 15:53:08 +00:00
:style="{ marginBottom: '12px' }"
2019-05-03 09:49:11 +00:00
>
<analysis-card
:loading="countsLoading"
2019-05-04 15:38:15 +00:00
title="总访问"
:number="countsData.visitCount"
2019-05-03 09:49:11 +00:00
>
2019-05-04 15:38:15 +00:00
<a-tooltip slot="action">
<template slot="title">
文章总访问共 {{ countsData.visitCount }}
</template>
<a href="javascript:void(0);">
<a-icon type="info-circle-o" /></a>
</a-tooltip>
2019-05-03 09:49:11 +00:00
</analysis-card>
</a-col>
<a-col
:xl="6"
:lg="6"
:md="12"
:sm="12"
:xs="12"
2019-05-03 15:53:08 +00:00
:style="{ marginBottom: '12px' }"
2019-05-03 09:49:11 +00:00
>
<analysis-card
:loading="countsLoading"
2019-05-04 08:11:46 +00:00
title="建立天数"
2019-05-03 09:49:11 +00:00
:number="countsData.establishDays"
>
2019-05-04 15:38:15 +00:00
<a-tooltip slot="action">
2019-05-04 08:11:46 +00:00
<template slot="title">
博客建立于 {{ countsData.birthday | moment }}
</template>
2019-05-04 03:05:06 +00:00
<a href="javascript:void(0);">
<a-icon type="info-circle-o" /></a>
2019-05-03 15:53:08 +00:00
</a-tooltip>
2019-05-03 09:49:11 +00:00
</analysis-card>
</a-col>
</a-row>
2019-03-20 12:22:52 +00:00
<a-row :gutter="12">
2019-04-24 03:14:44 +00:00
<a-col
:xl="8"
:lg="8"
:md="12"
:sm="24"
:xs="24"
2019-05-03 15:53:08 +00:00
:style="{ marginBottom: '12px' }"
2019-04-24 03:14:44 +00:00
>
2019-03-21 02:25:55 +00:00
<a-card
2019-05-04 15:38:15 +00:00
:loading="activityLoading"
2019-03-21 02:25:55 +00:00
:bordered="false"
2019-05-04 15:38:15 +00:00
title="新动态"
2019-05-04 16:22:09 +00:00
:bodyStyle="{ padding: 0 }"
2019-03-21 02:25:55 +00:00
>
2019-05-04 15:38:15 +00:00
<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>
2019-03-20 12:22:52 +00:00
</a-card>
</a-col>
2019-04-24 03:14:44 +00:00
<a-col
:xl="8"
:lg="8"
:md="12"
:sm="24"
:xs="24"
2019-05-03 15:53:08 +00:00
:style="{ marginBottom: '12px' }"
2019-04-24 03:14:44 +00:00
>
2019-03-21 02:25:55 +00:00
<a-card
:bordered="false"
2019-05-04 15:38:15 +00:00
:bodyStyle="{ padding: '16px' }"
2019-03-21 02:25:55 +00:00
>
2019-05-04 15:38:15 +00:00
<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>
2019-05-04 16:22:09 +00:00
<a-button
type="primary"
@click="handleCreateJournalClick"
>保存</a-button>
2019-05-04 15:38:15 +00:00
</a-form-item>
</a-form>
2019-03-20 12:22:52 +00:00
</a-card>
</a-col>
2019-04-24 03:14:44 +00:00
<a-col
:xl="8"
:lg="8"
:md="12"
:sm="24"
:xs="24"
2019-05-03 15:53:08 +00:00
:style="{ marginBottom: '12px' }"
2019-04-24 03:14:44 +00:00
>
2019-04-14 14:02:52 +00:00
<a-card
2019-05-03 15:53:08 +00:00
:loading="logLoading"
2019-04-14 14:02:52 +00:00
:bordered="false"
2019-05-04 15:38:15 +00:00
title="日志记录"
:bodyStyle="{ padding: '16px' }"
2019-04-14 14:02:52 +00:00
>
2019-05-04 16:55:35 +00:00
<a-list :dataSource="formattedLogDatas">
2019-05-04 16:22:09 +00:00
<a-list-item
slot="renderItem"
slot-scope="item, index"
:key="index"
>
<a-list-item-meta :description="item.createTime | timeAgo">
<span slot="title">{{ item.type }}</span>
</a-list-item-meta>
<div>{{ item.content }}</div>
</a-list-item>
</a-list>
2019-04-14 14:02:52 +00:00
</a-card>
</a-col>
2019-03-20 12:22:52 +00:00
</a-row>
2019-04-10 12:29:41 +00:00
</page-view>
2019-03-19 08:43:49 +00:00
</template>
<script>
2019-04-10 12:29:41 +00:00
import { PageView } from '@/layouts'
2019-05-03 09:49:11 +00:00
import AnalysisCard from './components/AnalysisCard'
2019-04-10 12:29:41 +00:00
2019-03-21 02:25:55 +00:00
import postApi from '@/api/post'
import commentApi from '@/api/comment'
2019-03-21 02:43:20 +00:00
import logApi from '@/api/log'
2019-03-21 02:32:06 +00:00
import adminApi from '@/api/admin'
2019-05-04 15:38:15 +00:00
import journalApi from '@/api/journal'
2019-03-20 12:22:52 +00:00
export default {
name: 'Dashboard',
2019-04-10 12:29:41 +00:00
components: {
2019-05-03 09:49:11 +00:00
PageView,
AnalysisCard
2019-04-10 12:29:41 +00:00
},
2019-03-21 02:25:55 +00:00
data() {
2019-03-20 12:22:52 +00:00
return {
2019-05-04 16:55:35 +00:00
logType: logApi.logType,
2019-05-04 15:38:15 +00:00
activityLoading: true,
2019-03-21 02:43:20 +00:00
logLoading: true,
2019-03-21 02:32:06 +00:00
countsLoading: true,
2019-03-21 02:25:55 +00:00
postData: [],
2019-03-21 02:32:06 +00:00
commentData: [],
2019-03-21 02:43:20 +00:00
logData: [],
2019-05-04 15:38:15 +00:00
countsData: {},
journal: {}
2019-03-20 12:22:52 +00:00
}
},
2019-03-21 02:25:55 +00:00
created() {
2019-03-21 02:32:06 +00:00
this.getCounts()
2019-03-21 02:25:55 +00:00
this.listLatestPosts()
this.listLatestComments()
2019-03-21 02:43:20 +00:00
this.listLatestLogs()
2019-03-21 02:25:55 +00:00
},
computed: {
formattedPostData() {
return Object.assign([], this.postData).map(post => {
// Format the status
2019-04-10 10:37:57 +00:00
post.status = postApi.postStatus[post.status]
return post
})
2019-05-04 16:55:35 +00:00
},
formattedLogDatas() {
return this.logData.map(log => {
log.type = this.logType[log.type].text
return log
})
}
},
2019-03-21 02:25:55 +00:00
methods: {
listLatestPosts() {
2019-05-04 15:38:15 +00:00
postApi.listLatest(5).then(response => {
2019-03-21 02:25:55 +00:00
this.postData = response.data.data
2019-05-04 15:38:15 +00:00
this.activityLoading = false
2019-03-21 02:25:55 +00:00
})
},
listLatestComments() {
2019-05-04 15:38:15 +00:00
commentApi.listLatest(5, 'PUBLISHED').then(response => {
2019-03-21 02:25:55 +00:00
this.commentData = response.data.data
2019-05-04 15:38:15 +00:00
this.activityLoading = false
2019-03-21 02:25:55 +00:00
})
2019-03-21 02:32:06 +00:00
},
2019-03-21 02:43:20 +00:00
listLatestLogs() {
2019-05-04 16:22:09 +00:00
logApi.listLatest(5).then(response => {
2019-03-21 02:43:20 +00:00
this.logData = response.data.data
2019-05-04 15:38:15 +00:00
this.logLoading = false
2019-03-21 02:43:20 +00:00
})
},
2019-03-21 02:32:06 +00:00
getCounts() {
adminApi.counts().then(response => {
this.countsData = response.data.data
2019-05-03 15:53:08 +00:00
this.countsLoading = false
2019-03-21 02:32:06 +00:00
})
2019-05-04 15:38:15 +00:00
},
handleEditPostClick(post) {
this.$router.push({ name: 'PostEdit', query: { postId: post.id } })
},
handleCreateJournalClick() {
journalApi.create(this.journal).then(response => {
this.$message.success('发表成功!')
this.journal = {}
})
2019-03-21 02:25:55 +00:00
}
2019-03-20 12:22:52 +00:00
}
}
2019-03-19 08:43:49 +00:00
</script>