mirror of https://github.com/halo-dev/halo-admin
feat: allow add and modify post metas
parent
f3574ef134
commit
c80138aff1
|
@ -30,11 +30,13 @@
|
||||||
:post="postToStage"
|
:post="postToStage"
|
||||||
:tagIds="selectedTagIds"
|
:tagIds="selectedTagIds"
|
||||||
:categoryIds="selectedCategoryIds"
|
:categoryIds="selectedCategoryIds"
|
||||||
|
:postMetas="selectedPostMetas"
|
||||||
:visible="postSettingVisible"
|
:visible="postSettingVisible"
|
||||||
@close="onPostSettingsClose"
|
@close="onPostSettingsClose"
|
||||||
@onRefreshPost="onRefreshPostFromSetting"
|
@onRefreshPost="onRefreshPostFromSetting"
|
||||||
@onRefreshTagIds="onRefreshTagIdsFromSetting"
|
@onRefreshTagIds="onRefreshTagIdsFromSetting"
|
||||||
@onRefreshCategoryIds="onRefreshCategoryIdsFromSetting"
|
@onRefreshCategoryIds="onRefreshCategoryIdsFromSetting"
|
||||||
|
@onRefreshPostMetas="onRefreshPostMetasFromSetting"
|
||||||
@onSaved="onSaved"
|
@onSaved="onSaved"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -92,6 +94,10 @@ export default {
|
||||||
postToStage: {},
|
postToStage: {},
|
||||||
selectedTagIds: [],
|
selectedTagIds: [],
|
||||||
selectedCategoryIds: [],
|
selectedCategoryIds: [],
|
||||||
|
selectedPostMetas: [{
|
||||||
|
key: '',
|
||||||
|
value: ''
|
||||||
|
}],
|
||||||
isSaved: false
|
isSaved: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -105,6 +111,7 @@ export default {
|
||||||
vm.postToStage = post
|
vm.postToStage = post
|
||||||
vm.selectedTagIds = post.tagIds
|
vm.selectedTagIds = post.tagIds
|
||||||
vm.selectedCategoryIds = post.categoryIds
|
vm.selectedCategoryIds = post.categoryIds
|
||||||
|
vm.selectedPostMetas = post.postMetas
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -239,6 +246,9 @@ export default {
|
||||||
onRefreshCategoryIdsFromSetting(categoryIds) {
|
onRefreshCategoryIdsFromSetting(categoryIds) {
|
||||||
this.selectedCategoryIds = categoryIds
|
this.selectedCategoryIds = categoryIds
|
||||||
},
|
},
|
||||||
|
onRefreshPostMetasFromSetting(postMetas) {
|
||||||
|
this.selectedPostMetas = postMetas
|
||||||
|
},
|
||||||
onSaved(isSaved) {
|
onSaved(isSaved) {
|
||||||
this.isSaved = isSaved
|
this.isSaved = isSaved
|
||||||
}
|
}
|
||||||
|
|
|
@ -495,6 +495,7 @@
|
||||||
:post="selectedPost"
|
:post="selectedPost"
|
||||||
:tagIds="selectedTagIds"
|
:tagIds="selectedTagIds"
|
||||||
:categoryIds="selectedCategoryIds"
|
:categoryIds="selectedCategoryIds"
|
||||||
|
:postMetas="selectedPostMetas"
|
||||||
:needTitle="true"
|
:needTitle="true"
|
||||||
:saveDraftButton="false"
|
:saveDraftButton="false"
|
||||||
:savePublishButton="false"
|
:savePublishButton="false"
|
||||||
|
@ -504,6 +505,7 @@
|
||||||
@onRefreshPost="onRefreshPostFromSetting"
|
@onRefreshPost="onRefreshPostFromSetting"
|
||||||
@onRefreshTagIds="onRefreshTagIdsFromSetting"
|
@onRefreshTagIds="onRefreshTagIdsFromSetting"
|
||||||
@onRefreshCategoryIds="onRefreshCategoryIdsFromSetting"
|
@onRefreshCategoryIds="onRefreshCategoryIdsFromSetting"
|
||||||
|
@onRefreshPostMetas="onRefreshPostMetasFromSetting"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TargetCommentDrawer
|
<TargetCommentDrawer
|
||||||
|
@ -605,6 +607,10 @@ export default {
|
||||||
columns,
|
columns,
|
||||||
selectedRowKeys: [],
|
selectedRowKeys: [],
|
||||||
categories: [],
|
categories: [],
|
||||||
|
selectedPostMetas: [{
|
||||||
|
key: '',
|
||||||
|
value: ''
|
||||||
|
}],
|
||||||
posts: [],
|
posts: [],
|
||||||
postsLoading: false,
|
postsLoading: false,
|
||||||
postSettingVisible: false,
|
postSettingVisible: false,
|
||||||
|
@ -747,6 +753,8 @@ export default {
|
||||||
this.selectedPost = response.data.data
|
this.selectedPost = response.data.data
|
||||||
this.selectedTagIds = this.selectedPost.tagIds
|
this.selectedTagIds = this.selectedPost.tagIds
|
||||||
this.selectedCategoryIds = this.selectedPost.categoryIds
|
this.selectedCategoryIds = this.selectedPost.categoryIds
|
||||||
|
this.selectedPostMetaIds = this.selectedPost.postMetaIds
|
||||||
|
this.selectedPostMetas = this.selectedPost.postMetas
|
||||||
this.postSettingVisible = true
|
this.postSettingVisible = true
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -787,6 +795,9 @@ export default {
|
||||||
},
|
},
|
||||||
onRefreshCategoryIdsFromSetting(categoryIds) {
|
onRefreshCategoryIdsFromSetting(categoryIds) {
|
||||||
this.selectedCategoryIds = categoryIds
|
this.selectedCategoryIds = categoryIds
|
||||||
|
},
|
||||||
|
onRefreshPostMetasFromSetting(postMetas) {
|
||||||
|
this.selectedPostMetas = postMetas
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,6 +167,29 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div :style="{ marginBottom: '16px' }">
|
||||||
|
<h3 class="post-setting-drawer-title">元数据</h3>
|
||||||
|
<a-form-item
|
||||||
|
v-for="(postMeta, index) in selectedPostMetas"
|
||||||
|
:key="index"
|
||||||
|
:prop="'postMetas.' + index + '.value'"
|
||||||
|
>
|
||||||
|
<a-row :gutter="10">
|
||||||
|
<a-col :span="11">
|
||||||
|
<a-input v-model="postMeta.key"><i slot="addonBefore">K</i></a-input>
|
||||||
|
</a-col>
|
||||||
|
<a-col :span="11">
|
||||||
|
<a-input v-model="postMeta.value"><i slot="addonBefore">V</i></a-input>
|
||||||
|
</a-col>
|
||||||
|
<a-col :span="2">
|
||||||
|
<a-icon type="close" @click.prevent="removePostMeta(postMeta)"/>
|
||||||
|
</a-col>
|
||||||
|
</a-row>
|
||||||
|
</a-form-item>
|
||||||
|
<a-form-item>
|
||||||
|
<a-button @click="addPostMeta">新增</a-button>
|
||||||
|
</a-form-item>
|
||||||
|
</div>
|
||||||
<a-divider class="divider-transparent" />
|
<a-divider class="divider-transparent" />
|
||||||
</div>
|
</div>
|
||||||
</a-skeleton>
|
</a-skeleton>
|
||||||
|
@ -238,6 +261,10 @@ export default {
|
||||||
type: Array,
|
type: Array,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
postMetas: {
|
||||||
|
type: Array,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
visible: {
|
visible: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
required: false,
|
required: false,
|
||||||
|
@ -283,6 +310,9 @@ export default {
|
||||||
selectedCategoryIds(val) {
|
selectedCategoryIds(val) {
|
||||||
this.$emit('onRefreshCategoryIds', val)
|
this.$emit('onRefreshCategoryIds', val)
|
||||||
},
|
},
|
||||||
|
selectedPostMetas(val) {
|
||||||
|
this.$emit('onRefreshPostMetas', val)
|
||||||
|
},
|
||||||
visible: function(newValue, oldValue) {
|
visible: function(newValue, oldValue) {
|
||||||
if (newValue) {
|
if (newValue) {
|
||||||
this.loadSkeleton()
|
this.loadSkeleton()
|
||||||
|
@ -291,6 +321,11 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
selectedPostMetas() {
|
||||||
|
// 不能将selectedPostMetas直接定义在data里
|
||||||
|
// 还没有获取到值就渲染视图,可以直接使用postMetas
|
||||||
|
return this.postMetas
|
||||||
|
},
|
||||||
pickerDefaultValue() {
|
pickerDefaultValue() {
|
||||||
if (this.selectedPost.createTime) {
|
if (this.selectedPost.createTime) {
|
||||||
var date = new Date(this.selectedPost.createTime)
|
var date = new Date(this.selectedPost.createTime)
|
||||||
|
@ -370,6 +405,8 @@ export default {
|
||||||
this.selectedPost.categoryIds = this.selectedCategoryIds
|
this.selectedPost.categoryIds = this.selectedCategoryIds
|
||||||
// Set tag ids
|
// Set tag ids
|
||||||
this.selectedPost.tagIds = this.selectedTagIds
|
this.selectedPost.tagIds = this.selectedTagIds
|
||||||
|
// Set post metas
|
||||||
|
this.selectedPost.postMetas = this.selectedPostMetas
|
||||||
|
|
||||||
if (this.selectedPost.id) {
|
if (this.selectedPost.id) {
|
||||||
// Update the post
|
// Update the post
|
||||||
|
@ -402,6 +439,18 @@ export default {
|
||||||
},
|
},
|
||||||
onPostDateOk(value) {
|
onPostDateOk(value) {
|
||||||
this.selectedPost.createTime = value.valueOf()
|
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: ''
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue