refactor: user profile.

pull/3445/head
ruibaby 2019-12-16 22:22:17 +08:00
parent 61df292126
commit f376635340
5 changed files with 71 additions and 55 deletions

30
package-lock.json generated
View File

@ -2826,9 +2826,9 @@
"dev": true "dev": true
}, },
"axios": { "axios": {
"version": "0.18.1", "version": "0.19.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz",
"integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==", "integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==",
"requires": { "requires": {
"follow-redirects": "1.5.10", "follow-redirects": "1.5.10",
"is-buffer": "^2.0.2" "is-buffer": "^2.0.2"
@ -6700,9 +6700,9 @@
} }
}, },
"filepond": { "filepond": {
"version": "4.8.2", "version": "4.9.2",
"resolved": "https://registry.npmjs.org/filepond/-/filepond-4.8.2.tgz", "resolved": "https://registry.npmjs.org/filepond/-/filepond-4.9.2.tgz",
"integrity": "sha512-CWXCv3amz1ECVidA33vezuXqfBI0O+UKWGh3g4574ZbyLwSwcJEbOy0vv2kgE0Xdg39xDQAruxHUGZm/xYK2oA==" "integrity": "sha512-YJGwIPFnkHxtG88LLpSuZSCySaxRDOKqSKywQ7KgPCRoUzHD8e5uC8Ii78+mjfBaU5QDOND/FFQLXLoLE99oJw=="
}, },
"filepond-plugin-image-preview": { "filepond-plugin-image-preview": {
"version": "4.5.0", "version": "4.5.0",
@ -10276,9 +10276,9 @@
} }
}, },
"marked": { "marked": {
"version": "0.7.0", "version": "0.8.0",
"resolved": "https://registry.npmjs.org/marked/-/marked-0.7.0.tgz", "resolved": "https://registry.npmjs.org/marked/-/marked-0.8.0.tgz",
"integrity": "sha512-c+yYdCZJQrsRjTPhUx7VKkApw9bwDkNbHUKo1ovgcfDjb2kc8rLuRbIFyXL5WOEUwzSSKo3IXpph2K6DqB/KZg==" "integrity": "sha512-MyUe+T/Pw4TZufHkzAfDj6HarCBWia2y27/bhuYkTaiUnfDYFnCP3KUN+9oM7Wi6JA2rymtVYbQu3spE0GCmxQ=="
}, },
"md5.js": { "md5.js": {
"version": "1.3.5", "version": "1.3.5",
@ -14521,9 +14521,9 @@
"dev": true "dev": true
}, },
"vue": { "vue": {
"version": "2.6.10", "version": "2.6.11",
"resolved": "https://registry.npmjs.org/vue/-/vue-2.6.10.tgz", "resolved": "https://registry.npmjs.org/vue/-/vue-2.6.11.tgz",
"integrity": "sha512-ImThpeNU9HbdZL3utgMCq0oiMzAkt1mcgy3/E6zWC/G6AaQoeuFdsl9nDhTDU3X1R6FK7nsIUuRACVcjI+A2GQ==" "integrity": "sha512-VfPwgcGABbGAue9+sfrD4PuwFar7gPb1yl1UK1MwXoQPAw0BKSqWfoYCT/ThFrdEVWoI51dBuyCoiNU9bZDZxQ=="
}, },
"vue-clipboard2": { "vue-clipboard2": {
"version": "0.3.1", "version": "0.3.1",
@ -14713,9 +14713,9 @@
} }
}, },
"vue-template-compiler": { "vue-template-compiler": {
"version": "2.6.10", "version": "2.6.11",
"resolved": "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.6.10.tgz", "resolved": "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.6.11.tgz",
"integrity": "sha512-jVZkw4/I/HT5ZMvRnhv78okGusqe0+qH2A0Em0Cp8aq78+NK9TII263CDVz2QXZsIT+yyV/gZc/j/vlwa+Epyg==", "integrity": "sha512-KIq15bvQDrcCjpGjrAhx4mUlyyHfdmTaoNfeoATHLAiWB+MU3cx4lOzMwrnUh9cCxy0Lt1T11hAFY6TQgroUAA==",
"dev": true, "dev": true,
"requires": { "requires": {
"de-indent": "^1.0.2", "de-indent": "^1.0.2",

View File

@ -11,15 +11,15 @@
"dependencies": { "dependencies": {
"animate.css": "^3.7.0", "animate.css": "^3.7.0",
"ant-design-vue": "^1.4.10", "ant-design-vue": "^1.4.10",
"axios": "^0.18.0", "axios": "^0.19.0",
"enquire.js": "^2.1.6", "enquire.js": "^2.1.6",
"filepond": "^4.7.2", "filepond": "^4.9.2",
"filepond-plugin-image-preview": "^4.5.0", "filepond-plugin-image-preview": "^4.5.0",
"halo-editor": "^2.8.2", "halo-editor": "^2.8.2",
"marked": "^0.7.0", "marked": "^0.8.0",
"moment": "^2.24.0", "moment": "^2.24.0",
"verte": "^0.0.12", "verte": "^0.0.12",
"vue": "^2.6.10", "vue": "^2.6.11",
"vue-clipboard2": "^0.3.0", "vue-clipboard2": "^0.3.0",
"vue-codemirror-lite": "^1.0.4", "vue-codemirror-lite": "^1.0.4",
"vue-count-to": "^1.0.13", "vue-count-to": "^1.0.13",
@ -50,7 +50,7 @@
"less": "^3.10.0", "less": "^3.10.0",
"less-loader": "^5.0.0", "less-loader": "^5.0.0",
"vue-svg-icon-loader": "^2.1.1", "vue-svg-icon-loader": "^2.1.1",
"vue-template-compiler": "^2.6.10" "vue-template-compiler": "^2.6.11"
}, },
"eslintConfig": { "eslintConfig": {
"root": true, "root": true,

21
src/api/statistics.js Normal file
View File

@ -0,0 +1,21 @@
import service from '@/utils/service'
const baseUrl = '/api/admin/statistics'
const statisticsApi = {}
statisticsApi.statistics = () => {
return service({
url: `${baseUrl}`,
method: 'get'
})
}
statisticsApi.statisticsWithUser = () => {
return service({
url: `${baseUrl}/user`,
method: 'get'
})
}
export default statisticsApi

View File

@ -12,7 +12,7 @@
<analysis-card <analysis-card
:loading="countsLoading" :loading="countsLoading"
title="文章" title="文章"
:number="countsData.postCount" :number="statisticsData.postCount"
> >
<router-link <router-link
:to="{ name:'PostList' }" :to="{ name:'PostList' }"
@ -33,7 +33,7 @@
<analysis-card <analysis-card
:loading="countsLoading" :loading="countsLoading"
title="评论" title="评论"
:number="countsData.commentCount" :number="statisticsData.commentCount"
> >
<router-link <router-link
:to="{ name:'Comments' }" :to="{ name:'Comments' }"
@ -54,14 +54,14 @@
<analysis-card <analysis-card
:loading="countsLoading" :loading="countsLoading"
title="总访问" title="总访问"
:number="countsData.visitCount" :number="statisticsData.visitCount"
> >
<a-tooltip slot="action"> <a-tooltip slot="action">
<template slot="title"> <template slot="title">
文章总访问共 文章总访问共
<countTo <countTo
:startVal="0" :startVal="0"
:endVal="countsData.visitCount" :endVal="statisticsData.visitCount"
:duration="3000" :duration="3000"
></countTo> ></countTo>
</template> </template>
@ -82,10 +82,10 @@
<analysis-card <analysis-card
:loading="countsLoading" :loading="countsLoading"
title="建立天数" title="建立天数"
:number="countsData.establishDays" :number="statisticsData.establishDays"
> >
<a-tooltip slot="action"> <a-tooltip slot="action">
<template slot="title">博客建立于 {{ countsData.birthday | moment }}</template> <template slot="title">博客建立于 {{ statisticsData.birthday | moment }}</template>
<a href="javascript:void(0);"> <a href="javascript:void(0);">
<a-icon type="info-circle-o" /> <a-icon type="info-circle-o" />
</a> </a>
@ -336,7 +336,7 @@ import countTo from 'vue-count-to'
import postApi from '@/api/post' import postApi from '@/api/post'
import logApi from '@/api/log' import logApi from '@/api/log'
import adminApi from '@/api/admin' import statisticsApi from '@/api/statistics'
import journalApi from '@/api/journal' import journalApi from '@/api/journal'
export default { export default {
name: 'Dashboard', name: 'Dashboard',
@ -359,7 +359,7 @@ export default {
logDrawerVisible: false, logDrawerVisible: false,
postData: [], postData: [],
logData: [], logData: [],
countsData: {}, statisticsData: {},
journal: { journal: {
content: '', content: '',
photos: [] photos: []
@ -379,7 +379,7 @@ export default {
} }
}, },
created() { created() {
this.getCounts() this.getStatistics()
this.listLatestPosts() this.listLatestPosts()
this.listLatestLogs() this.listLatestLogs()
}, },
@ -413,7 +413,7 @@ export default {
beforeRouteEnter(to, from, next) { beforeRouteEnter(to, from, next) {
next(vm => { next(vm => {
vm.interval = setInterval(() => { vm.interval = setInterval(() => {
vm.getCounts() vm.getStatistics()
}, 5000) }, 5000)
}) })
}, },
@ -442,9 +442,9 @@ export default {
this.writeLoading = false this.writeLoading = false
}) })
}, },
getCounts() { getStatistics() {
adminApi.counts().then(response => { statisticsApi.statistics().then(response => {
this.countsData = response.data.data this.statisticsData = response.data.data
this.countsLoading = false this.countsLoading = false
}) })
}, },

View File

@ -40,20 +40,21 @@
<a-icon type="mail" />{{ user.email }} <a-icon type="mail" />{{ user.email }}
</p> </p>
<p> <p>
<a-icon type="calendar" />{{ counts.establishDays || 0 }} <a-icon type="calendar" />{{ statistics.establishDays || 0 }}
</p> </p>
</div> </div>
<a-divider /> <a-divider />
<div class="general-profile"> <div class="general-profile">
<a-list <a-list
:loading="countsLoading" :loading="statisticsLoading"
itemLayout="horizontal" itemLayout="horizontal"
> >
<a-list-item>累计发表了 {{ counts.postCount || 0 }} 篇文章</a-list-item> <a-list-item>累计发表了 {{ statistics.postCount || 0 }} 篇文章</a-list-item>
<a-list-item>累计创建了 {{ counts.attachmentCount || 0 }} 个附件</a-list-item> <a-list-item>累计创建了 {{ statistics.categoryCount || 0 }} 个分类</a-list-item>
<a-list-item>累计获得了 {{ counts.commentCount || 0 }} 条评论</a-list-item> <a-list-item>累计创建了 {{ statistics.tagCount || 0 }} 个标签</a-list-item>
<a-list-item>累计添加了 {{ counts.linkCount || 0 }} 个友链</a-list-item> <a-list-item>累计获得了 {{ statistics.commentCount || 0 }} 条评论</a-list-item>
<a-list-item>文章总访问 {{ counts.visitCount || 0 }} </a-list-item> <a-list-item>累计添加了 {{ statistics.linkCount || 0 }} 个友链</a-list-item>
<a-list-item>文章总访问 {{ statistics.visitCount || 0 }} </a-list-item>
<a-list-item></a-list-item> <a-list-item></a-list-item>
</a-list> </a-list>
</div> </div>
@ -142,7 +143,7 @@
<script> <script>
import AttachmentSelectDrawer from '../attachment/components/AttachmentSelectDrawer' import AttachmentSelectDrawer from '../attachment/components/AttachmentSelectDrawer'
import userApi from '@/api/user' import userApi from '@/api/user'
import adminApi from '@/api/admin' import statisticsApi from '@/api/statistics'
import { mapMutations, mapGetters } from 'vuex' import { mapMutations, mapGetters } from 'vuex'
import MD5 from 'md5.js' import MD5 from 'md5.js'
@ -152,10 +153,10 @@ export default {
}, },
data() { data() {
return { return {
countsLoading: true, statisticsLoading: true,
attachmentDrawerVisible: false, attachmentDrawerVisible: false,
user: {}, user: {},
counts: {}, statistics: {},
passwordParam: { passwordParam: {
oldPassword: null, oldPassword: null,
newPassword: null, newPassword: null,
@ -171,21 +172,15 @@ export default {
...mapGetters(['options']) ...mapGetters(['options'])
}, },
created() { created() {
this.loadUser() this.getStatistics()
this.getCounts()
}, },
methods: { methods: {
...mapMutations({ setUser: 'SET_USER' }), ...mapMutations({ setUser: 'SET_USER' }),
loadUser() { getStatistics() {
userApi.getProfile().then(response => { statisticsApi.statisticsWithUser().then(response => {
this.user = response.data.data this.user = response.data.data.user
this.profileLoading = false this.statistics = response.data.data
}) this.statisticsLoading = false
},
getCounts() {
adminApi.counts().then(response => {
this.counts = response.data.data
this.countsLoading = false
}) })
}, },
handleUpdatePassword() { handleUpdatePassword() {