From c80138aff19433f97ea5ba1a6db6e93bb203f2e6 Mon Sep 17 00:00:00 2001 From: guqing <1484563614@qq.com> Date: Sun, 1 Dec 2019 18:34:14 +0800 Subject: [PATCH] feat: allow add and modify post metas --- src/views/post/PostEdit.vue | 10 ++++ src/views/post/PostList.vue | 11 +++++ .../post/components/PostSettingDrawer.vue | 49 +++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/src/views/post/PostEdit.vue b/src/views/post/PostEdit.vue index c0f7cecb..9c8e7803 100644 --- a/src/views/post/PostEdit.vue +++ b/src/views/post/PostEdit.vue @@ -30,11 +30,13 @@ :post="postToStage" :tagIds="selectedTagIds" :categoryIds="selectedCategoryIds" + :postMetas="selectedPostMetas" :visible="postSettingVisible" @close="onPostSettingsClose" @onRefreshPost="onRefreshPostFromSetting" @onRefreshTagIds="onRefreshTagIdsFromSetting" @onRefreshCategoryIds="onRefreshCategoryIdsFromSetting" + @onRefreshPostMetas="onRefreshPostMetasFromSetting" @onSaved="onSaved" /> @@ -92,6 +94,10 @@ export default { postToStage: {}, selectedTagIds: [], selectedCategoryIds: [], + selectedPostMetas: [{ + key: '', + value: '' + }], isSaved: false } }, @@ -105,6 +111,7 @@ export default { vm.postToStage = post vm.selectedTagIds = post.tagIds vm.selectedCategoryIds = post.categoryIds + vm.selectedPostMetas = post.postMetas }) } }) @@ -239,6 +246,9 @@ export default { onRefreshCategoryIdsFromSetting(categoryIds) { this.selectedCategoryIds = categoryIds }, + onRefreshPostMetasFromSetting(postMetas) { + this.selectedPostMetas = postMetas + }, onSaved(isSaved) { this.isSaved = isSaved } diff --git a/src/views/post/PostList.vue b/src/views/post/PostList.vue index 9ca18e35..c4a17317 100644 --- a/src/views/post/PostList.vue +++ b/src/views/post/PostList.vue @@ -495,6 +495,7 @@ :post="selectedPost" :tagIds="selectedTagIds" :categoryIds="selectedCategoryIds" + :postMetas="selectedPostMetas" :needTitle="true" :saveDraftButton="false" :savePublishButton="false" @@ -504,6 +505,7 @@ @onRefreshPost="onRefreshPostFromSetting" @onRefreshTagIds="onRefreshTagIdsFromSetting" @onRefreshCategoryIds="onRefreshCategoryIdsFromSetting" + @onRefreshPostMetas="onRefreshPostMetasFromSetting" /> +
+

元数据

+ + + + K + + + V + + + + + + + + 新增 + +
@@ -238,6 +261,10 @@ export default { type: Array, required: true }, + postMetas: { + type: Array, + required: true + }, visible: { type: Boolean, required: false, @@ -283,6 +310,9 @@ export default { selectedCategoryIds(val) { this.$emit('onRefreshCategoryIds', val) }, + selectedPostMetas(val) { + this.$emit('onRefreshPostMetas', val) + }, visible: function(newValue, oldValue) { if (newValue) { this.loadSkeleton() @@ -291,6 +321,11 @@ export default { } }, computed: { + selectedPostMetas() { + // 不能将selectedPostMetas直接定义在data里 + // 还没有获取到值就渲染视图,可以直接使用postMetas + return this.postMetas + }, pickerDefaultValue() { if (this.selectedPost.createTime) { var date = new Date(this.selectedPost.createTime) @@ -370,6 +405,8 @@ export default { this.selectedPost.categoryIds = this.selectedCategoryIds // Set tag ids this.selectedPost.tagIds = this.selectedTagIds + // Set post metas + this.selectedPost.postMetas = this.selectedPostMetas if (this.selectedPost.id) { // Update the post @@ -402,6 +439,18 @@ export default { }, onPostDateOk(value) { this.selectedPost.createTime = value.valueOf() + }, + removePostMeta(item) { + var index = this.selectedPostMetas.indexOf(item) + if (index !== -1) { + this.selectedPostMetas.splice(index, 1) + } + }, + addPostMeta() { + this.selectedPostMetas.push({ + value: '', + key: '' + }) } } }