|
29 | 29 | >
|
30 | 30 | {{category['title']}}
|
31 | 31 | </el-radio-button>
|
32 |
| - <el-button icon="PlusIcon">新建分类</el-button> |
| 32 | + <el-button icon="PlusIcon" @click="addCategoryDialogVisible=true">新建分类</el-button> |
| 33 | + |
33 | 34 | </el-radio-group>
|
34 | 35 | </el-form-item>
|
35 | 36 |
|
| 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 | + |
36 | 48 | <el-form-item label='标签' prop="tags">
|
37 | 49 | <el-checkbox-group
|
38 | 50 | v-model="postForm.tags"
|
|
43 | 55 | :label="tag['title']"
|
44 | 56 | :value="tag['title']"
|
45 | 57 | />
|
46 |
| - <el-button icon="PlusIcon">新建标签</el-button> |
| 58 | + <el-button icon="PlusIcon" @click="addTagDialogVisible=true">新建标签</el-button> |
47 | 59 | </el-checkbox-group>
|
48 | 60 | </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> |
49 | 71 | </el-form>
|
50 | 72 |
|
51 | 73 | <sticky-nav
|
|
63 | 85 | // import Upload from '@/components/UploadFile/index'
|
64 | 86 | import StickyNav from '@/components/StickyNav' // 粘性header组件
|
65 | 87 | // 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' |
69 | 91 | // import { CommentDropdown, PlatformDropdown, SourceUrlDropdown } from './Dropdown'
|
70 | 92 | // import axios from 'axios'
|
71 | 93 | import {uploadFile} from "@/api/files";
|
|
100 | 122 | }
|
101 | 123 |
|
102 | 124 | return {
|
103 |
| - // image_upload_url: 'http://10.89.228.206:28088/api/article/upload/', |
104 |
| - // postForm: Object.assign({}, defaultForm), |
105 | 125 | postForm: {
|
106 | 126 | status: 'draft',
|
107 | 127 | title: '', // 文章题目
|
|
112 | 132 |
|
113 | 133 | },
|
114 | 134 | loading: false,
|
| 135 | + addCategoryDialogVisible:false, |
| 136 | + addTagDialogVisible:false, |
| 137 | + newCategory:'', |
| 138 | + newTag: '', |
115 | 139 | rules: {
|
116 | 140 | title: [{validator: validateRequire}],
|
117 | 141 | content: [{validator: validateRequire}],
|
|
135 | 159 | this.postForm.display_time = new Date(val)
|
136 | 160 | }
|
137 | 161 | }
|
| 162 | + // articleCategory:{ |
| 163 | + // return this.articleCategories |
| 164 | + // } |
138 | 165 | },
|
139 | 166 | created() {
|
140 | 167 | // fixme 如果有异常了,不应该进入编辑界面,防止对原有文章的破坏
|
|
251 | 278 | this.loading = true
|
252 | 279 | if (this.isEdit) {
|
253 | 280 | const articleId = this.$route.params && this.$route.params.id
|
254 |
| - UpdateArticle(articleId, this.postForm).then((res) => { |
| 281 | + updateArticle(articleId, this.postForm).then((res) => { |
255 | 282 | const resp = res
|
256 | 283 | this.$notify({
|
257 | 284 | title: 'Success',
|
|
286 | 313 | }
|
287 | 314 | })
|
288 | 315 | },
|
| 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 | + } |
289 | 348 | }
|
290 | 349 | }
|
291 | 350 | </script>
|
|
0 commit comments