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 98d6a59

Browse files
feat: finish archives & tags & category
1 parent fb04091 commit 98d6a59

File tree

20 files changed

+594
-122
lines changed

20 files changed

+594
-122
lines changed

‎front/server/api/articles.js‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ const api = require('../http/')
1010
const confirmToken = require('../middleware/confirmToken')
1111
const unpublishedPermission = require('../middleware/unpublishedPermission')
1212

13-
// 获取文章列表 / 按分类筛选文章
13+
// 获取文章列表 / 按分类 / 按标签 筛选文章
1414
router.get('/api/front/article/gets', unpublishedPermission, async (req, res) => {
1515
const params = { publish: req.query.publish }
1616
if (req.query.categoryId) params.categoryId = req.query.categoryId
17+
if (req.query.tag) params.tag = { $in: [req.query.tag] }
1718
const limit = parseInt(req.query.limit) || 10
1819
const skip = req.query.page * limit - limit
1920
const project = req.query.content == '0' ? { content: 0 } : {}
@@ -224,29 +225,35 @@ router.get('/api/front/article/search', unpublishedPermission, async (req, res)
224225
})
225226
// 文章归档
226227
router.get('/api/front/article/archives', async (req, res) => {
227-
// const limit = parseInt(req.query.limit) || 10
228-
// const skip = req.query.page * limit - limit
228+
const limit = parseInt(req.query.limit) || 10
229+
const skip = req.query.page * limit - limit
230+
229231
try {
230232
const doc = await db.article.aggregate([
231233
{ $match: {} },
232234
{ $sort: { _id: -1 } },
233-
// { $skip: skip },
234-
// { $limit: limit },
235+
{ $skip: skip },
236+
{ $limit: limit },
235237
{
236238
$project: {
237239
year: { $dateToString: { format: '%Y', date: '$createTime' } },
238240
month: { $dateToString: { format: '%Y-%m', date: '$createTime' } },
239241
title: 1,
240242
createTime: 1,
241-
articleId: 1
243+
articleId: 1,
244+
headerPic: 1
242245
}
243246
},
244247
{ $group: { _id: '$year', total: { $sum: 1 }, months: { $push: '$$ROOT' } } },
245-
{ $project: { year: '$_id', _id: 0, total: 1, months: 1 } }
248+
{ $project: { year: '$_id', _id: 0, total: 1, months: 1 } },
249+
{ $sort: { year: -1 } }
246250
])
251+
const total = await db.article.count({ publish: 1 })
252+
247253
res.json({
248254
status: 200,
249255
data: doc,
256+
total,
250257
info: '归档查询成功'
251258
})
252259
} catch (e) {

‎front/server/api/category.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ router.get('/api/front/category/get', async (req, res) => {
1111
try {
1212
const doc = await db.category.find({}).sort({ _id: -1 })
1313
res.json({
14-
status: 0,
14+
status: 200,
1515
data: doc,
1616
info: '获取文档分类成功'
1717
})

‎front/src/api/index.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import visitor from './visitor'
33
import comments from './comments'
44
import messageBoard from './messageBoard'
55
import category from './category'
6+
import tags from './tags'
67

78
export default {
89
...article,
910
...visitor,
1011
...comments,
1112
...messageBoard,
12-
...category
13+
...category,
14+
...tags
1315
}

‎front/src/api/tags.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @desc 获取文章标签
3+
* @author Justjokee
4+
*/
5+
6+
import http from '@/http/'
7+
export default {
8+
// 获取文章所有的tag
9+
getTags(payload) {
10+
return http.get('/api/front/tags/count', payload).then(data => {
11+
return data
12+
})
13+
}
14+
}

‎front/src/app.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { createStore } from './store'
1111
import { sync } from 'vuex-router-sync'
1212

1313
import mergeAsyncData from '@/mixins/mergeAsyncData'
14-
api.getArchives()
1514
// Vue.config.productionTip = false
1615
Vue.filter('formatDate', val => {
1716
return moment(val).format('YYYY-MM-DD HH:mm')

‎front/src/assets/img/loading.gif‎

153 KB
Loading[フレーム]
131 KB
Loading[フレーム]

‎front/src/components/dot/index.vue‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<doc>
2+
@desc: 点状形状包裹器
3+
@author: justJokee
4+
</doc>
5+
<template>
6+
<div class="dot">
7+
<slot></slot>
8+
</div>
9+
</template>
10+
<script>
11+
export default {
12+
name: 'dot',
13+
data() {
14+
return {}
15+
}
16+
}
17+
</script>
18+
<style lang="scss">
19+
@import '~@/style/index.scss';
20+
.dot {
21+
position: relative;
22+
display: flex;
23+
align-items: center;
24+
padding-left: 20px;
25+
}
26+
.dot:before {
27+
content: '';
28+
position: absolute;
29+
left: -2px;
30+
top: 50%;
31+
transform: translate(0, -50%);
32+
width: 8px;
33+
height: 8px;
34+
border: 3px solid;
35+
border-radius: 50%;
36+
font-weight: normal;
37+
transition: all ease 0.2s;
38+
@include themeify() {
39+
border-color: themed('color-ele-primary');
40+
}
41+
}
42+
</style>

‎front/src/entry-client.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { storage } from '@/utils/storage'
33
import R_O_P from 'resize-observer-polyfill'
44
import Vue from 'vue'
55
import VueLazyload from '@/utils/lazyLoad'
6+
const loading = require('@/assets/img/loading.gif')
67
if (!window.ResizeObserver) {
78
window.ResizeObserver = R_O_P
89
}
910
// eslint-disable-next-line no-undef
10-
Vue.use(VueLazyload)
11+
Vue.use(VueLazyload, {
12+
loading: loading
13+
})
1114

1215
Vue.mixin({
1316
beforeRouteUpdate(to, from, next) {

‎front/src/router/index.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const miss = () => import('@/components/base/miss')
55
const home = () => import('@/views/home/')
66
const articleDetail = () => import('@/views/article/articleDetail')
77
const messageBoard = () => import('@/views/messageBoard/')
8+
const archives = () => import('@/views/archives/')
9+
const tags = () => import('@/views/tags/')
10+
const articleFilter = () => import('@/views/article-filter/')
11+
const category = () => import('@/views/category/')
812

913
Vue.use(Router)
1014
Vue.use(Meta)
@@ -36,6 +40,26 @@ export function createRouter() {
3640
path: '/app/messageBoard',
3741
name: 'messageBoard',
3842
component: messageBoard
43+
},
44+
{
45+
path: '/app/archives',
46+
name: 'archives',
47+
component: archives
48+
},
49+
{
50+
path: '/app/tags',
51+
name: 'tags',
52+
component: tags
53+
},
54+
{
55+
path: '/app/category',
56+
name: 'category',
57+
component: category
58+
},
59+
{
60+
path: '/app/articles/:type/:param',
61+
name: 'articleFilter',
62+
component: articleFilter
3963
}
4064
],
4165
scrollBehavior(to, from, savedPosition) {

0 commit comments

Comments
(0)

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