Fixed vue data warning.

pull/3445/head
ruibaby 2019-08-27 10:49:56 +08:00
parent fb80b1ea18
commit dc52f30ade
3 changed files with 65 additions and 27 deletions

View File

@ -27,11 +27,13 @@
<PostSetting <PostSetting
:post="postToStage" :post="postToStage"
:selectedTagIds="selectedTagIds" :tagIds="selectedTagIds"
:selectedCategoryIds="selectedCategoryIds" :categoryIds="selectedCategoryIds"
v-model="postSettingVisible" v-model="postSettingVisible"
@close="onPostSettingsClose" @close="onPostSettingsClose"
@onRefreshPost="onRefreshPostFromSetting" @onRefreshPost="onRefreshPostFromSetting"
@onRefreshTagIds="onRefreshTagIdsFromSetting"
@onRefreshCategoryIds="onRefreshCategoryIdsFromSetting"
/> />
<AttachmentDrawer v-model="attachmentDrawerVisible" /> <AttachmentDrawer v-model="attachmentDrawerVisible" />
@ -173,6 +175,12 @@ export default {
}, },
onRefreshPostFromSetting(post) { onRefreshPostFromSetting(post) {
this.postToStage = post this.postToStage = post
},
onRefreshTagIdsFromSetting(tagIds) {
this.selectedTagIds = tagIds
},
onRefreshCategoryIdsFromSetting(categoryIds) {
this.selectedCategoryIds = categoryIds
} }
} }
} }

View File

@ -259,8 +259,8 @@
<PostSetting <PostSetting
:post="selectedPost" :post="selectedPost"
:selectedTagIds="selectedTagIds" :tagIds="selectedTagIds"
:selectedCategoryIds="selectedCategoryIds" :categoryIds="selectedCategoryIds"
:needTitle="true" :needTitle="true"
:saveDraftButton="false" :saveDraftButton="false"
:savePublishButton="false" :savePublishButton="false"
@ -268,6 +268,8 @@
v-model="postSettingVisible" v-model="postSettingVisible"
@close="onPostSettingsClose" @close="onPostSettingsClose"
@onRefreshPost="onRefreshPostFromSetting" @onRefreshPost="onRefreshPostFromSetting"
@onRefreshTagIds="onRefreshTagIdsFromSetting"
@onRefreshCategoryIds="onRefreshCategoryIdsFromSetting"
/> />
</div> </div>
</template> </template>
@ -502,6 +504,12 @@ export default {
}, },
onRefreshPostFromSetting(post) { onRefreshPostFromSetting(post) {
this.selectedPost = post this.selectedPost = post
},
onRefreshTagIdsFromSetting(tagIds) {
this.selectedTagIds = tagIds
},
onRefreshCategoryIdsFromSetting(categoryIds) {
this.selectedCategoryIds = categoryIds
} }
} }
} }

View File

@ -17,13 +17,13 @@
label="文章标题:" label="文章标题:"
v-if="needTitle" v-if="needTitle"
> >
<a-input v-model="post.title" /> <a-input v-model="selectedPost.title" />
</a-form-item> </a-form-item>
<a-form-item <a-form-item
label="文章路径:" label="文章路径:"
:help="options.blog_url+'/archives/' + (post.url ? post.url : '{auto_generate}')" :help="options.blog_url+'/archives/' + (selectedPost.url ? selectedPost.url : '{auto_generate}')"
> >
<a-input v-model="post.url" /> <a-input v-model="selectedPost.url" />
</a-form-item> </a-form-item>
<a-form-item label="发表时间:"> <a-form-item label="发表时间:">
@ -38,7 +38,7 @@
</a-form-item> </a-form-item>
<a-form-item label="开启评论:"> <a-form-item label="开启评论:">
<a-radio-group <a-radio-group
v-model="post.disallowComment" v-model="selectedPost.disallowComment"
:defaultValue="false" :defaultValue="false"
> >
<a-radio :value="false">开启</a-radio> <a-radio :value="false">开启</a-radio>
@ -121,7 +121,7 @@
<a-input <a-input
type="textarea" type="textarea"
:autosize="{ minRows: 5 }" :autosize="{ minRows: 5 }"
v-model="post.summary" v-model="selectedPost.summary"
placeholder="不填写则会自动生成" placeholder="不填写则会自动生成"
/> />
</a-form-item> </a-form-item>
@ -136,7 +136,7 @@
<div class="post-thum"> <div class="post-thum">
<img <img
class="img" class="img"
:src="post.thumbnail || '//i.loli.net/2019/05/05/5ccf007c0a01d.png'" :src="selectedPost.thumbnail || '//i.loli.net/2019/05/05/5ccf007c0a01d.png'"
@click="()=>this.thumDrawerVisible=true" @click="()=>this.thumDrawerVisible=true"
> >
<a-button <a-button
@ -198,6 +198,9 @@ export default {
categoryFormVisible: false, categoryFormVisible: false,
options: [], options: [],
keys: ['blog_url'], keys: ['blog_url'],
selectedPost: this.post,
selectedTagIds: this.tagIds,
selectedCategoryIds: this.categoryIds,
categories: [], categories: [],
categoryToCreate: {} categoryToCreate: {}
} }
@ -211,11 +214,11 @@ export default {
type: Object, type: Object,
required: true required: true
}, },
selectedTagIds: { tagIds: {
type: Array, type: Array,
required: true required: true
}, },
selectedCategoryIds: { categoryIds: {
type: Array, type: Array,
required: true required: true
}, },
@ -249,10 +252,30 @@ export default {
this.loadOptions() this.loadOptions()
this.loadCategories() this.loadCategories()
}, },
watch: {
post(val) {
this.selectedPost = val
},
selectedPost(val) {
this.$emit('onRefreshPost', val)
},
tagIds(val) {
this.selectedTagIds = val
},
selectedTagIds(val) {
this.$emit('onRefreshTagIds', val)
},
categoryIds(val) {
this.selectedCategoryIds = val
},
selectedCategoryIds(val) {
this.$emit('onRefreshCategoryIds', val)
}
},
computed: { computed: {
pickerDefaultValue() { pickerDefaultValue() {
if (this.post.createTime) { if (this.selectedPost.createTime) {
var date = new Date(this.post.createTime) var date = new Date(this.selectedPost.createTime)
return moment(date, 'YYYY-MM-DD HH:mm:ss') return moment(date, 'YYYY-MM-DD HH:mm:ss')
} }
return moment(new Date(), 'YYYY-MM-DD HH:mm:ss') return moment(new Date(), 'YYYY-MM-DD HH:mm:ss')
@ -270,11 +293,11 @@ export default {
}) })
}, },
handleSelectPostThumb(data) { handleSelectPostThumb(data) {
this.post.thumbnail = encodeURI(data.path) this.selectedPost.thumbnail = encodeURI(data.path)
this.thumDrawerVisible = false this.thumDrawerVisible = false
}, },
handlerRemoveThumb() { handlerRemoveThumb() {
this.post.thumbnail = null this.selectedPost.thumbnail = null
}, },
handlerCreateCategory() { handlerCreateCategory() {
categoryApi.create(this.categoryToCreate).then(response => { categoryApi.create(this.categoryToCreate).then(response => {
@ -286,11 +309,11 @@ export default {
this.categoryFormVisible = !this.categoryFormVisible this.categoryFormVisible = !this.categoryFormVisible
}, },
handleDraftClick() { handleDraftClick() {
this.post.status = 'DRAFT' this.selectedPost.status = 'DRAFT'
this.savePost() this.savePost()
}, },
handlePublishClick() { handlePublishClick() {
this.post.status = 'PUBLISHED' this.selectedPost.status = 'PUBLISHED'
this.savePost() this.savePost()
}, },
savePost() { savePost() {
@ -302,13 +325,13 @@ export default {
}, },
createOrUpdatePost(createSuccess, updateSuccess, autoSave) { createOrUpdatePost(createSuccess, updateSuccess, autoSave) {
// Set category ids // Set category ids
this.post.categoryIds = this.selectedCategoryIds this.selectedPost.categoryIds = this.selectedCategoryIds
// Set tag ids // Set tag ids
this.post.tagIds = this.selectedTagIds this.selectedPost.tagIds = this.selectedTagIds
if (this.post.id) { if (this.selectedPost.id) {
// Update the post // Update the post
postApi.update(this.post.id, this.post, autoSave).then(response => { postApi.update(this.selectedPost.id, this.selectedPost, autoSave).then(response => {
this.$log.debug('Updated post', response.data.data) this.$log.debug('Updated post', response.data.data)
if (updateSuccess) { if (updateSuccess) {
updateSuccess() updateSuccess()
@ -316,24 +339,23 @@ export default {
}) })
} else { } else {
// Create the post // Create the post
postApi.create(this.post, autoSave).then(response => { postApi.create(this.selectedPost, autoSave).then(response => {
this.$log.debug('Created post', response.data.data) this.$log.debug('Created post', response.data.data)
if (createSuccess) { if (createSuccess) {
createSuccess() createSuccess()
} }
this.post = response.data.data this.selectedPost = response.data.data
}) })
} }
this.$emit('onRefreshPost', this.post)
}, },
onClose() { onClose() {
this.$emit('close', false) this.$emit('close', false)
}, },
onPostDateChange(value, dateString) { onPostDateChange(value, dateString) {
this.post.createTime = value.valueOf() this.selectedPost.createTime = value.valueOf()
}, },
onPostDateOk(value) { onPostDateOk(value) {
this.post.createTime = value.valueOf() this.selectedPost.createTime = value.valueOf()
} }
} }
} }