pull/9/head
ruibaby 2019-05-10 23:49:34 +08:00
parent 5aed421693
commit 4713436d03
3 changed files with 54 additions and 67 deletions

View File

@ -28,8 +28,8 @@
:width="isMobile()?'100%':'460'"
placement="right"
closable
@close="onClose"
:visible="visible"
@close="()=>this.postSettingVisible=false"
:visible="postSettingVisible"
>
<div class="post-setting-drawer-content">
<div :style="{ marginBottom: '16px' }">
@ -143,7 +143,7 @@
<img
class="img"
:src="postToStage.thumbnail || '//i.loli.net/2019/05/05/5ccf007c0a01d.png'"
@click="handleShowThumbDrawer"
@click="()=>this.thumDrawerVisible=true"
>
<a-button
class="post-thum-remove"
@ -177,11 +177,11 @@
<footer-tool-bar :style="{ width: isSideMenu() && isDesktop() ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%'}">
<a-button
type="primary"
@click="handleShowDrawer"
@click="()=>this.postSettingVisible = true"
>发布</a-button>
<a-button
type="dashed"
@click="handleShowAttachDrawer"
@click="()=>this.attachmentDrawerVisible = true"
style="margin-left: 8px;"
>附件库</a-button>
</footer-tool-bar>
@ -222,7 +222,7 @@ export default {
xs: { span: 24 }
},
attachmentDrawerVisible: false,
visible: false,
postSettingVisible: false,
thumDrawerVisible: false,
categoryForm: false,
tags: [],
@ -245,6 +245,14 @@ export default {
clearInterval(this.timer)
this.timer = null
},
beforeRouteLeave(to, from, next) {
if (this.timer !== null) {
clearInterval(this.timer)
}
// Auto save the post
this.autoSavePost()
next()
},
beforeRouteEnter(to, from, next) {
// Get post id from query
const postId = to.query.postId
@ -300,16 +308,9 @@ export default {
this.createOrUpdatePost(() => this.$message.success('文章创建成功'), () => this.$message.success('文章更新成功'))
},
autoSavePost() {
this.createOrUpdatePost()
},
handleShowDrawer() {
this.visible = true
},
handleShowAttachDrawer() {
this.attachmentDrawerVisible = true
},
handleShowThumbDrawer() {
this.thumDrawerVisible = true
if (this.postToStage.title != null && this.postToStage.originalContent != null) {
this.createOrUpdatePost()
}
},
toggleCategoryForm() {
this.categoryForm = !this.categoryForm
@ -331,9 +332,6 @@ export default {
this.categoryToCreate = {}
})
},
onClose() {
this.visible = false
},
handleSelectPostThumb(data) {
this.postToStage.thumbnail = data.path
this.thumDrawerVisible = false
@ -345,14 +343,6 @@ export default {
}, 15000)
}
}
},
beforeRouteLeave(to, from, next) {
if (this.timer !== null) {
clearInterval(this.timer)
}
// Auto save the post
this.autoSavePost()
next()
}
}
</script>

View File

@ -32,8 +32,8 @@
title="页面设置"
:width="isMobile()?'100%':'460'"
:closable="true"
@close="onClose"
:visible="visible"
@close="()=>this.sheetSettingVisible = false"
:visible="sheetSettingVisible"
>
<div class="post-setting-drawer-content">
<div :style="{ marginBottom: '16px' }">
@ -57,7 +57,10 @@
</a-form-item>
<a-form-item label="自定义模板:">
<a-select v-model="sheetToStage.template">
<a-select-option key="" value=""></a-select-option>
<a-select-option
key=""
value=""
></a-select-option>
<a-select-option
v-for="tpl in customTpls"
:key="tpl"
@ -77,7 +80,7 @@
<img
class="img"
:src="sheetToStage.thumbnail || '//i.loli.net/2019/05/05/5ccf007c0a01d.png'"
@click="handleShowThumbDrawer"
@click="()=>this.thumDrawerVisible = true"
>
<a-button
class="sheet-thum-remove"
@ -87,7 +90,7 @@
</div>
</div>
</div>
<a-divider class="divider-transparent"/>
<a-divider class="divider-transparent" />
</div>
<AttachmentSelectDrawer
v-model="thumDrawerVisible"
@ -111,12 +114,12 @@
<footer-tool-bar :style="{ width: isSideMenu() && isDesktop() ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%'}">
<a-button
type="primary"
@click="handleShowDrawer"
@click="()=>this.sheetSettingVisible = true"
>发布</a-button>
<a-button
type="dashed"
style="margin-left: 8px;"
@click="handleShowAttachDrawer"
@click="()=>this.attachmentDrawerVisible = true"
>附件库</a-button>
</footer-tool-bar>
</div>
@ -150,7 +153,7 @@ export default {
},
attachmentDrawerVisible: false,
thumDrawerVisible: false,
visible: false,
sheetSettingVisible: false,
customTpls: [],
sheetToStage: {},
timer: null
@ -166,6 +169,14 @@ export default {
clearInterval(this.timer)
this.timer = null
},
beforeRouteLeave(to, from, next) {
if (this.timer !== null) {
clearInterval(this.timer)
}
// Auto save the sheet
this.autoSaveSheet()
next()
},
beforeRouteEnter(to, from, next) {
// Get sheetId id from query
const sheetId = to.query.sheetId
@ -185,42 +196,42 @@ export default {
this.customTpls = response.data.data
})
},
handleShowAttachDrawer() {
this.attachmentDrawerVisible = true
},
handleShowThumbDrawer() {
this.thumDrawerVisible = true
},
handleShowDrawer() {
this.visible = true
},
handlePublishClick() {
this.sheetToStage.status = 'PUBLISHED'
this.createOrUpdateSheet()
this.saveSheet()
},
handleDraftClick() {
this.sheetToStage.status = 'DRAFT'
this.createOrUpdateSheet()
this.saveSheet()
},
handlerRemoveThumb() {
this.sheetToStage.thumbnail = null
},
createOrUpdateSheet() {
createOrUpdateSheet(createSuccess, updateSuccess) {
if (this.sheetToStage.id) {
sheetApi.update(this.sheetToStage.id, this.sheetToStage).then(response => {
this.$log.debug('Updated sheet', response.data.data)
this.$message.success('页面更新成功')
if (updateSuccess) {
updateSuccess()
}
})
} else {
sheetApi.create(this.sheetToStage).then(response => {
this.$log.debug('Created sheet', response.data.data)
this.$message.success('页面创建成功')
if (createSuccess) {
createSuccess()
}
this.sheetToStage = response.data.data
})
}
},
onClose() {
this.visible = false
saveSheet() {
this.createOrUpdateSheet(() => this.$message.success('页面创建成功'), () => this.$message.success('页面更新成功'))
},
autoSaveSheet() {
if (this.sheetToStage.title != null && this.sheetToStage.originalContent != null) {
this.createOrUpdateSheet()
}
},
handleSelectSheetThumb(data) {
this.sheetToStage.thumbnail = data.path
@ -229,21 +240,7 @@ export default {
autoSaveTimer() {
if (this.timer == null) {
this.timer = setInterval(() => {
if (this.sheetToStage.title != null && this.sheetToStage.originalContent != null) {
this.sheetToStage.categoryIds = this.selectedCategoryIds
this.sheetToStage.tagIds = this.selectedTagIds
if (this.sheetToStage.id) {
sheetApi.update(this.sheetToStage.id, this.sheetToStage).then(response => {
this.$log.debug('Auto updated sheet', response.data.data)
})
} else {
sheetApi.create(this.sheetToStage).then(response => {
this.$log.debug('Auto saved sheet', response.data.data)
this.sheetToStage = response.data.data
})
}
}
this.autoSaveSheet()
}, 15000)
}
}

View File

@ -1,6 +1,6 @@
const path = require('path')
const webpack = require('webpack')
const GenerateAssetPlugin = require('generate-asset-webpack-plugin')
// const GenerateAssetPlugin = require('generate-asset-webpack-plugin')
function resolve(dir) {
return path.join(__dirname, dir)