Complate tag manage.

pull/25/head
ruibaby 2019-06-01 11:40:57 +08:00
parent 3fe7033b70
commit 064ce66c18
1 changed files with 64 additions and 14 deletions

View File

@ -9,7 +9,7 @@
:xs="24" :xs="24"
:style="{ 'padding-bottom': '12px' }" :style="{ 'padding-bottom': '12px' }"
> >
<a-card title="添加标签"> <a-card :title="title">
<a-form layout="horizontal"> <a-form layout="horizontal">
<a-form-item <a-form-item
label="名称:" label="名称:"
@ -26,8 +26,32 @@
<a-form-item> <a-form-item>
<a-button <a-button
type="primary" type="primary"
@click="handleCreateTag" @click="handleSaveClick"
v-if="formType==='create'"
>保存</a-button> >保存</a-button>
<a-button-group v-else>
<a-button
type="primary"
@click="handleSaveClick"
>更新</a-button>
<a-button
type="dashed"
@click="handleAddTag"
v-if="formType==='update'"
>返回添加</a-button>
</a-button-group>
<a-popconfirm
:title="'你确定要删除【' + tagToCreate.name + '】标签?'"
@confirm="handleDeleteTag(tagToCreate.id)"
okText="确定"
cancelText="取消"
v-if="formType==='update'"
>
<a-button
type="danger"
style="float:right"
>删除</a-button>
</a-popconfirm>
</a-form-item> </a-form-item>
</a-form> </a-form>
</a-card> </a-card>
@ -50,9 +74,9 @@
<span>{{ tag.postCount }} 篇文章</span> <span>{{ tag.postCount }} 篇文章</span>
</template> </template>
<a-tag <a-tag
closable
@close="handleDeleteTag(tag.id)"
color="blue" color="blue"
style="margin-bottom: 8px"
@click="handleEditTag(tag)"
>{{ tag.name }}</a-tag> >{{ tag.name }}</a-tag>
</a-tooltip> </a-tooltip>
</a-card> </a-card>
@ -67,9 +91,17 @@ import tagApi from '@/api/tag'
export default { export default {
data() { data() {
return { return {
formType: 'create',
tags: [], tags: [],
tagToCreate: {}, tagToCreate: {}
tagToUpdate: {} }
},
computed: {
title() {
if (this.tagToCreate.id) {
return '修改标签'
}
return '添加标签'
} }
}, },
created() { created() {
@ -81,21 +113,39 @@ export default {
this.tags = response.data.data this.tags = response.data.data
}) })
}, },
handleCreateTag() { handleSaveClick() {
tagApi.create(this.tagToCreate).then(response => { this.createOrUpdateTag()
this.loadTags()
})
}, },
handleUpdateTag(tagId) { handleAddTag() {
tagApi.update(tagId, this.tagToUpdate).then(response => { this.formType = 'create'
this.loadTags() this.tagToCreate = {}
}) },
handleEditTag(tag) {
this.tagToCreate = tag
this.formType = 'update'
}, },
handleDeleteTag(tagId) { handleDeleteTag(tagId) {
tagApi.delete(tagId).then(response => { tagApi.delete(tagId).then(response => {
this.$message.success('删除成功!') this.$message.success('删除成功!')
this.loadTags() this.loadTags()
this.handleAddTag()
}) })
},
createOrUpdateTag() {
if (this.tagToCreate.id) {
tagApi.update(this.tagToCreate.id, this.tagToCreate).then(response => {
this.$message.success('更新成功!')
this.loadTags()
this.tagToCreate = {}
})
} else {
tagApi.create(this.tagToCreate).then(response => {
this.$message.success('保存成功!')
this.loadTags()
this.tagToCreate = {}
})
}
this.handleAddTag()
} }
} }
} }