Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion components/PostItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
</div>
<template v-if="!post.isLocal">
<h4>
<a-tag v-if="post.isTop" color="red">
置顶
</a-tag>
<a :title="post.title" :href="post.url" target="_blank">
<web-font icon="external-link" style="margin-right: 5px;" />
<span>{{ post.title }}</span>
Expand All @@ -31,6 +34,9 @@
@click="() => (drawer = true)"
/>
<h4>
<a-tag v-if="post.isTop" color="red">
置顶
</a-tag>
<nuxt-link :to="`/blog/${post.category.alias}/${post.alias}`" :title="post.title">
{{ post.title }}
</nuxt-link>
Expand Down Expand Up @@ -145,7 +151,7 @@ export default Vue.extend({
.blog-item h4 a {
color: #444;
position: relative;
display: -webkit-inline-box;
/* display: -webkit-inline-box; */
overflow: hidden;
text-overflow: ellipsis;
box-orient: vertical;
Expand Down Expand Up @@ -242,6 +248,11 @@ export default Vue.extend({
line-height: 36px;
}

.center-title{
display: flex;
align-items: center;
}

@media (max-width: 576px) {
/* 隐藏预览 */
.preview-link {
Expand Down
17 changes: 17 additions & 0 deletions pages/admin/article-edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@
</a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="置顶" :colon="false">
<a-radio-group
v-decorator="['isTop', isTopOpts]"
name="isTopGroup"
>
<a-radio :value="1">
置顶
</a-radio>
<a-radio :value="0">
非置顶
</a-radio>
</a-radio-group>
</a-form-item>
<div v-show="!initialData.isLocal">
<a-form-item label="URL" :colon="false">
<a-input
Expand Down Expand Up @@ -284,6 +297,9 @@ export default Vue.extend({
isLocalOpts: {
initialValue: true
},
isTopOpts: {
initialValue: 0
},
labelsOpts: {
initialValue: []
},
Expand Down Expand Up @@ -460,6 +476,7 @@ export default Vue.extend({
alias: this.initialData.alias,
category: this.initialData.category,
isLocal: this.initialData.isLocal,
isTop: this.initialData.isTop,
url: this.initialData.url || '',
labels: this.initialData.labels,
commentsFlag: this.initialData.commentsFlag
Expand Down
23 changes: 23 additions & 0 deletions pages/admin/article-manage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,22 @@
</a-select>
</a-form-item>
</a-col>
<a-col :sm="24" :md="11" :xxl="5">
<a-form-item label="是否置顶" :colon="false">
<a-select
v-decorator="['isTop']"
placeholder="不限"
allow-clear
>
<a-select-option value="1">
</a-select-option>
<a-select-option value="-1">
</a-select-option>
</a-select>
</a-form-item>
</a-col>
</a-row>
<a-row type="flex" justify="center">
<a-col>
Expand Down Expand Up @@ -251,6 +267,13 @@
>
已删除
</a-tag>
<a-tag
v-else-if="row.isTop &&!row.isDraft"
color="red"
title="已发布,所有人可见"
>
置顶
</a-tag>
<a-tag
v-else-if="!row.isDraft"
color="green"
Expand Down
3 changes: 3 additions & 0 deletions server/models/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export class Post {
// 是否本地文档,否则是外链
isLocal: { type: Boolean, default: true },

// 是否置顶
isTop: { type: Number, default: 0 },

// 是否草稿
isDraft: { type: Boolean, default: false },

Expand Down
5 changes: 5 additions & 0 deletions server/proxy/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export async function getPosts (params: any) {
publishTime,
isLink,
isDraft,
isTop,
hasComments,
isDeleted
} = params;
Expand Down Expand Up @@ -90,6 +91,10 @@ export async function getPosts (params: any) {
};
}

if (isTop === '1' || isTop === '-1') {
matchObj.isTop = parseInt(isTop);
}

// 排序
let sortObj: any = {
createTime: -1
Expand Down
62 changes: 47 additions & 15 deletions server/proxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,53 @@ export async function getPosts (params) {
];
}
}
const data = await Promise.all([
Post.find(
conditions,
{},
{
skip: (page - 1) * pageSize,
limit: pageSize,
sort: '-publishTime'
}
)
.populate('category')
.populate('comments', '_id')
.exec(),
Post.countDocuments(conditions).exec()
]);
/**
* 因为没找到按照多个排序的指令
* 先获取置顶的帖子,如果没有达到分页限制 就获取剩余个数的正常帖子
* 比较拙劣的解决办法
*/
async function getPost () {
conditions.isTop = 1;
const data:[Array<any>, number] = await Promise.all([
Post.find(
conditions,
{},
{
skip: (page - 1) * pageSize,
limit: pageSize,
sort: '-publishTime'
}
)
.populate('category')
.populate('comments', '_id')
.exec(),
Post.countDocuments(conditions).exec()
]);
if (data[0].length < pageSize) {
conditions.isTop = { $ne: 1 };
let skip:number = (page - 1) * pageSize - data[1];
skip = skip < 0 ? 0 : skip;
const data2:[Array<any>, number] = await Promise.all([
Post.find(
conditions,
{},
{
skip,
limit: pageSize - data[0].length,
sort: '-publishTime'
}
)
.populate('category')
.populate('comments', '_id')
.exec(),
Post.countDocuments(conditions).exec()
]);
data[0].push(...data2[0]);
data[1] = data[1] + data2[1];
return data;
}
}
const data = await getPost() || [[], 0];
const postList = data[0];
const count = data[1];
const pageCount = Math.ceil(count / pageSize);
Expand Down
5 changes: 5 additions & 0 deletions types/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ export interface IPost extends Document {
*/
isLocal: boolean;

/**
* 是否是置顶文章
*/
isTop: number;

/**
* 是否草稿
*/
Expand Down