Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 670ad1f

Browse files
feat: 看板开发中
1 parent 98d6a59 commit 670ad1f

File tree

15 files changed

+339
-152
lines changed

15 files changed

+339
-152
lines changed

‎front/server/api/articles.js‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ router.get('/api/front/article/gets', unpublishedPermission, async (req, res) =>
1717
if (req.query.tag) params.tag = { $in: [req.query.tag] }
1818
const limit = parseInt(req.query.limit) || 10
1919
const skip = req.query.page * limit - limit
20-
const project = req.query.content == '0' ? { content: 0 } : {}
20+
const project = req.query.content == '0' ? { content: 0,content_plain: 0 } : {}
2121
if (req.query.tag) params.tag = req.query.tag
2222
try {
2323
const total = await db.article.count(params)
@@ -226,8 +226,21 @@ router.get('/api/front/article/search', unpublishedPermission, async (req, res)
226226
// 文章归档
227227
router.get('/api/front/article/archives', async (req, res) => {
228228
const limit = parseInt(req.query.limit) || 10
229-
const skip = req.query.page * limit - limit
230-
229+
const skip = (req.query.page || 1) * limit - limit
230+
// 按年统计
231+
let group = [
232+
{ $group: { _id: '$year', total: { $sum: 1 }, months: { $push: '$$ROOT' } } },
233+
{ $project: { year: '$_id', _id: 0, total: 1, months: 1 } },
234+
{ $sort: { year: -1 } }
235+
]
236+
// 按月统计
237+
if (req.query.countType === 'month') {
238+
group = [
239+
{ $group: { _id: '$month', total: { $sum: 1 } } },
240+
{ $project: { month: '$_id', _id: 0, total: 1 } },
241+
{ $sort: { month: -1 } }
242+
]
243+
}
231244
try {
232245
const doc = await db.article.aggregate([
233246
{ $match: {} },
@@ -244,9 +257,7 @@ router.get('/api/front/article/archives', async (req, res) => {
244257
headerPic: 1
245258
}
246259
},
247-
{ $group: { _id: '$year', total: { $sum: 1 }, months: { $push: '$$ROOT' } } },
248-
{ $project: { year: '$_id', _id: 0, total: 1, months: 1 } },
249-
{ $sort: { year: -1 } }
260+
...group
250261
])
251262
const total = await db.article.count({ publish: 1 })
252263

‎front/server/api/comments.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ const api = require('../http/')
88
// 获取文章评论
99
router.get('/api/front/comments/get', async (req, res) => {
1010
const limit = parseInt(req.query.limit) || 10
11-
const skip = req.query.page * limit - limit
11+
const skip = (req.query.page||1) * limit - limit
1212
const ip = getIp(req)
13+
const articleFilter = Reflect.has(req.query, 'articleId') ? { articleId: parseInt(req.query.articleId) } : {}
1314
try {
14-
const total = await db.comment.count({ articleId: parseInt(req.query.articleId), parentId: null })
15+
const total = await db.comment.count({ ...articleFilter, parentId: null })
1516
const doc = await db.comment.aggregate([
1617
{ $match: { parentId: null } },
17-
{ $match: { articleId: parseInt(req.query.articleId) } },
18+
{ $match: { ...articleFilter } },
1819
{ $sort: { _id: -1 } },
1920
{ $skip: skip },
2021
{ $limit: limit },
@@ -59,6 +60,7 @@ router.get('/api/front/comments/get', async (req, res) => {
5960
page: parseInt(req.query.page)
6061
})
6162
} catch (e) {
63+
console.log('ccomments-------------', e)
6264
res.status(500).end()
6365
}
6466
})

‎front/src/App.vue‎

Lines changed: 33 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
</div>
55
</template>
66
<script>
7-
import { mapState, mapMutations } from 'vuex'
8-
import { getScrollTop } from '@/utils/getScrollTop'
9-
import { getElementTop } from '@/utils/getElementTop'
7+
import { mapMutations } from 'vuex'
108
119
export default {
1210
components: {},
@@ -17,131 +15,41 @@ export default {
1715
showBackTop: true
1816
}
1917
},
20-
watch: {
21-
$route() {
22-
// scrollTo(0)
23-
if (this.$route.name === 'home') {
24-
this.location = []
25-
}
26-
this.currentLocation(this.$route)
27-
},
28-
//当articleShow组件的标题变化时,刷新当前位置的文章标题,防止当前文章显示上一篇文章的标题
29-
currentTitle() {
30-
this.currentLocation(this.$route)
31-
}
32-
},
18+
watch: {},
3319
mounted() {
34-
// this.currentLocation(this.$route)
35-
// this.scrollCotainer()
36-
// //页面重载计算锚点距离并判断tab的背景样式
37-
// this.positionTop(getElementTop(this.$refs.container) - 50)
38-
// this.getTop()
39-
},
40-
computed: {
41-
...mapState(['currentTitle'])
20+
this.initPannel()
4221
},
22+
computed: {},
4323
methods: {
44-
...mapMutations(['addTabBg', 'positionTop']),
45-
scrollCotainer: function() {
46-
window.addEventListener('scroll', this.scroll_resize)
47-
//改变窗口大小后对导航栏状态重新进行确认
48-
window.addEventListener('resize', this.scroll_resize)
49-
},
50-
scroll_resize: function() {
51-
this.debounce(this.getTop, 500)
52-
},
53-
getAT: function() {
54-
let top = getScrollTop() - getElementTop(this.$refs.container)
55-
this.positionTop(top)
56-
},
57-
getTop: function() {
58-
//计算document需要滚动的距离
59-
let tabOffsetTop = getElementTop(this.$refs.container) - 50
60-
let move = Math.abs(getScrollTop() - tabOffsetTop)
61-
if (getScrollTop() > 0) {
62-
this.showBackTop = true
63-
} else {
64-
this.showBackTop = false
65-
}
66-
if (getScrollTop() > tabOffsetTop) {
67-
this.addTabBg(true)
68-
} else {
69-
this.addTabBg(false)
70-
}
71-
//计算路由改变需要滚动的距离
72-
this.positionTop({ top: tabOffsetTop, move: move })
73-
},
74-
//函数去抖,防止scroll和resize频繁触发
75-
debounce: function(func, delay) {
76-
let context = this
77-
let args = arguments
78-
if (this.timer) {
79-
clearTimeout(this.timer)
80-
}
81-
this.timer = setTimeout(function() {
82-
func.apply(context, args)
83-
}, delay)
84-
},
85-
back: function(item) {
86-
let name = item.pathName
87-
if (name === 'techincal') {
88-
this.$router.push({ name: name, params: { articleList: item.params.tag } })
89-
} else if (name === 'articleShow') {
90-
this.$router.push({ name: name, params: { articleList: item.params.tag, id: item.params.id } })
91-
} else if (name === 'lifeShow') {
92-
this.$router.push({ name: name, params: { id: item.params.id } })
93-
} else {
94-
this.$router.push({ name: name })
95-
}
96-
},
97-
backTop: function() {
98-
document.documentElement.scrollTop = 0
99-
document.body.scrollTop = 0
100-
},
101-
backHome: function() {
102-
this.location = []
103-
this.$router.push({ name: 'home' })
104-
},
105-
//当前位置的路由信息表
106-
currentLocation: function(to) {
107-
switch (to.name) {
108-
case 'article':
109-
this.location = [{ pathName: 'article', showName: '技术文章' }]
110-
break
111-
case 'techincal':
112-
let tag = to.params.articleList
113-
this.location = [
114-
{ pathName: 'article', showName: '技术文章' },
115-
{ pathName: 'techincal', showName: tag, params: { tag: tag } }
116-
]
117-
break
118-
case 'articleShow':
119-
let _tag = to.params.articleList
120-
this.location = [
121-
{ pathName: 'article', showName: '技术文章' },
122-
{ pathName: 'techincal', showName: _tag, params: { tag: _tag } },
123-
{ pathName: 'articleShow', showName: this.currentTitle, params: { tag: _tag, id: to.params.id } }
124-
]
125-
break
126-
case 'life':
127-
this.location = [{ pathName: 'life', showName: '生活' }]
128-
break
129-
case 'lifeShow':
130-
this.location = [
131-
{ pathName: 'life', showName: '生活' },
132-
{ pathName: 'lifeShow', showName: this.currentTitle, params: { id: to.params.id } }
133-
]
134-
console.log(this.currentTitle)
135-
break
136-
case 'msgboard':
137-
this.location = [{ pathName: 'msgboard', showName: '留言板' }]
138-
break
139-
case 'search':
140-
this.location = [{ pathName: 'search', showName: '搜索' }]
141-
break
142-
case 'timeLine':
143-
this.location = [{ pathName: 'timeLine', showName: '时间轴' }]
144-
}
24+
...mapMutations(['setArchives', 'setCategory', 'setTags', 'setNewComments', 'setNewArticles']),
25+
initPannel() {
26+
this.$api.getArchives({ countType: 'month', page: 1, limit: 1000 }).then(res => {
27+
if (res.status === 200) this.setArchives(res.data)
28+
})
29+
this.$api.getCategory().then(res => {
30+
if (res.status === 200) this.setCategory(res.data)
31+
})
32+
this.$api.getTags().then(res => {
33+
if (res.status === 200) this.setTags(res.data)
34+
})
35+
this.$api
36+
.getArticleComments({
37+
page: 1,
38+
limit: 5
39+
})
40+
.then(res => {
41+
if (res.status === 200) this.setNewComments(res.data)
42+
})
43+
this.$api
44+
.getArticles({
45+
publish: 1,
46+
page: 1,
47+
limit: 5,
48+
content: 0
49+
})
50+
.then(res => {
51+
if (res.status === 200) this.setNewArticles(res.data)
52+
})
14553
}
14654
}
14755
}

‎front/src/store/index.js‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@ export function createStore() {
1111
rollBack: false,
1212
// 访客信息
1313
visitorInfo: {},
14-
catalogs: []
14+
// 文章目录树
15+
catalogs: [],
16+
// 文章归档 按月统计
17+
archives: [],
18+
// 文章分类
19+
category: [],
20+
// 文章标签
21+
tags: [],
22+
// 最新评论
23+
newComments: [],
24+
// 最新文章
25+
newArticles: []
1526
},
1627
mutations,
1728
actions

‎front/src/store/mutations.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@ export default {
22
setCatalogs(state, catalogs) {
33
state.catalogs = catalogs
44
},
5+
setArchives(state, archives) {
6+
state.archives = archives
7+
},
8+
setCategory(state, category) {
9+
state.category = category
10+
},
11+
setTags(state, tags) {
12+
state.tags = tags
13+
},
14+
setNewComments(state, newComments) {
15+
state.newComments = newComments
16+
},
17+
setNewArticles(state, newArticles) {
18+
state.newArticles = newArticles
19+
},
520
setActiveCatalog(state, id) {
621
state.activeCatalog = id
722
},

‎front/src/views/archives/index.vue‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<div class="archives__content">
1818
<div class="content-left">
1919
<router-link :to="'/app/article/' + article.articleId">
20-
<div></div>
2120
<img v-lazy="article.headerPic" alt="" />
2221
</router-link>
2322
</div>
@@ -111,6 +110,10 @@ export default {
111110
height: 100%;
112111
object-fit: cover;
113112
}
113+
img[src=''],
114+
img:not([src]) {
115+
opacity: 0;
116+
}
114117
}
115118
.content-right {
116119
margin-left: 24px;

‎front/src/views/home/index.vue‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export default {
7171
async asyncData() {
7272
const articleRes = await api.getArticles({
7373
publish: 1,
74-
page: 1
74+
page: 1,
75+
content: 0
7576
})
7677
if (articleRes.status === 200) return { articles: articleRes.data, total: articleRes.total }
7778
},
@@ -80,7 +81,8 @@ export default {
8081
const articleRes = await api.getArticles({
8182
publish: 1,
8283
limit: 1,
83-
page: val
84+
page: val,
85+
content: 0
8486
})
8587
if (articleRes.status === 200) {
8688
this.total = articleRes.total
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<doc>
2+
@desc: 看板 - 文章归档
3+
@author: justJokee
4+
</doc>
5+
<template>
6+
<div class="pannel-archives">
7+
<el-card>网站简介</el-card>
8+
</div>
9+
</template>
10+
<script>
11+
import { mapState } from 'vuex'
12+
export default {
13+
name: 'pannelArchives',
14+
props: {},
15+
data() {
16+
return {}
17+
},
18+
compouted: {
19+
...mapState(['archives'])
20+
},
21+
methods: {}
22+
}
23+
</script>
24+
<style lang="scss">
25+
.pannel-archives {
26+
}
27+
</style>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /