8000 support add category and tag · pycoder404/blog-vue@e7c603a · GitHub
[go: up one dir, main page]

Skip to content

Commit e7c603a

Browse files
committed
support add category and tag
1 parent c3b3f90 commit e7c603a

File tree

3 files changed

+70
-23
lines changed

3 files changed

+70
-23
lines changed

src/api/article.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function createArticle(data) {
2424
})
2525
}
2626

27-
export function UpdateArticle(articleId, data) {
27+
export function updateArticle(articleId, data) {
2828
return request({
2929
url: '/api/article/update/' + articleId + '/',
3030
method: 'put',

src/views/article/create.vue

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,22 @@
2929
>
3030
{{category['title']}}
3131
</el-radio-button>
32-
<el-button icon="PlusIcon">新建分类</el-button>
32+
<el-button icon="PlusIcon" @click="addCategoryDialogVisible=true">新建分类</el-button>
33+
3334
</el-radio-group>
3435
</el-form-item>
3536

37+
<el-dialog v-model="addCategoryDialogVisible" title="添加分类">
38+
39+
<el-input v-model="newCategory" />
40+
<template #footer>
41+
<span class="dialog-footer">
42+
<el-button @click="addCategoryDialogVisible = false">Cancel</el-button>
43+
<el-button type="primary" @click="submitToCreateCategory">Confirm</el-button>
44+
</span>
45+
</template>
46+
</el-dialog>
47+
3648
<el-form-item label='标签' prop="tags">
3749
<el-checkbox-group
3850
v-model="postForm.tags"
@@ -43,9 +55,19 @@
4355
:label="tag['title']"
4456
:value="tag['title']"
4557
/>
46-
<el-button icon="PlusIcon">新建标签</el-button>
58+
<el-button icon="PlusIcon" @click="addTagDialogVisible=true">新建标签</el-button>
4759
</el-checkbox-group>
4860
</el-form-item>
61+
62+
<el-dialog v-model="addTagDialogVisible" title="添加标签">
63+
<el-input v-model="newTag" />
64+
<template #footer>
65+
<span class="dialog-footer">
66+
<el-button @click="addTagDialogVisible = false">Cancel</el-button>
67+
<el-button type="primary" @click="submitToCreateTag">Confirm</el-button>
68+
</span>
69+
</template>
70+
</el-dialog>
4971
</el-form>
5072

5173
<sticky-nav
@@ -63,9 +85,9 @@
6385
// import Upload from '@/components/UploadFile/index'
6486
import StickyNav from '@/components/StickyNav' // 粘性header组件
6587
// import { validURL } from '@/utils/validate'
66-
import {getArticleDetail, createArticle, UpdateArticle} from '@/api/article'
67-
import {getTagList} from '@/api/tag'
68-
import {getCategoryList} from '@/api/category'
88+
import {getArticleDetail, createArticle, updateArticle} from '@/api/article'
89+
import {getTagList,createTag} from '@/api/tag'
90+
import {getCategoryList,createCategory} from '@/api/category'
6991
// import { CommentDropdown, PlatformDropdown, SourceUrlDropdown } from './Dropdown'
7092
// import axios from 'axios'
7193
import {uploadFile} from "@/api/files";
@@ -100,8 +122,6 @@
100122
}
101123
102124
return {
103-
// image_upload_url: 'http://10.89.228.206:28088/api/article/upload/',
104-
// postForm: Object.assign({}, defaultForm),
105125
postForm: {
106126
status: 'draft',
107127
title: '', // 文章题目
@@ -112,6 +132,10 @@
112132
113133
},
114134
loading: false,
135+
addCategoryDialogVisible:false,
136+
addTagDialogVisible:false,
137+
newCategory:'',
138+
newTag: '',
115139
rules: {
116140
title: [{validator: validateRequire}],
117141
content: [{validator: validateRequire}],
@@ -135,6 +159,9 @@
135159
this.postForm.display_time = new Date(val)
136160
}
137161
}
162+
// articleCategory:{
163+
// return this.articleCategories
164+
// }
138165
},
139166
created() {
140167
// fixme 如果有异常了,不应该进入编辑界面,防止对原有文章的破坏
@@ -251,7 +278,7 @@
251278
this.loading = true
252279
if (this.isEdit) {
253280
const articleId = this.$route.params && this.$route.params.id
254-
UpdateArticle(articleId, this.postForm).then((res) => {
281+
updateArticle(articleId, this.postForm).then((res) => {
255282
const resp = res
256283
this.$notify({
257284
title: 'Success',
@@ -286,6 +313,38 @@
286313
}
287314
})
288315
},
316+
submitToCreateCategory() {
317+
const data={title:this.newCategory}
318+
createCategory(data).then(() => {
319+
this.addCategoryDialogVisible = false
320+
this.fetchArticleCategory()
321+
this.$notify({
322+
title: 'Success',
323+
message: 'Create Successfully',
324+
type: 'success',
325+
duration: 2000
326+
})
327+
})
328+
.catch((err) => {
329+
console.log("Error: ",err)
330+
})
331+
},
332+
submitToCreateTag() {
333+
const data={title:this.newTag}
334+
createTag(data).then(() => {
335+
this.addTagDialogVisible = false
336+
this.fetchArticleTag()
337+
this.$notify({
338+
title: 'Success',
339+
message: 'Create Successfully',
340+
type: 'success',
341+
duration: 2000
342+
})
343+
})
344+
.catch((err) => {
345+
console.log("Error: ",err)
346+
})
347+
}
289348
}
290349
}
291350
</script>

src/views/article/detail.vue

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,7 @@
5050
import LikeFavorite from "@/views/article/components/LikeFavorite";
5151
import CategoryAndTag from "@/views/article/components/CategoryAndTag";
5252
//
53-
// const defaultForm = {
54-
// status: 'draft',
55-
// title: 'title', // 文章题目
56-
// content: 'content', // 文章内容
57-
// toc: '', // 文章目录
58-
// content_short: '', // 文章摘要
59-
// source_uri: '', // 文章外链
60-
// image_uri: '', // 文章图片
61-
// display_time: undefined, // 前台展示时间
62-
// id: undefined,
63-
// platforms: ['a-platform'],
64-
// comment_disabled: false,
65-
// importance: 0
66-
// }
53+
6754
export default {
6855
name: "ArticleDetail",
6956
components:{LikeFavorite,CategoryAndTag},
@@ -99,6 +86,7 @@
9986
// // set page title
10087
// this.setPageTitle()
10188
}).catch(err => {
89+
// FIXME 访问一个不存在的文章过程中应该跳转到404界面
10290
console.log(err)
10391
})
10492
}

0 commit comments

Comments
 (0)
0