Remove timer of auto save post or sheet.

pull/40/head
ruibaby 5 years ago
parent 5350704282
commit eb3879c91d

@ -20,6 +20,8 @@
:ishljs="true"
:autofocus="false"
@imgAdd="handleAttachmentUpload"
@keydown.ctrl.83.native="handleSaveDraft"
@keydown.meta.83.native="handleSaveDraft"
/>
</div>
</a-col>
@ -39,9 +41,14 @@
<AttachmentDrawer v-model="attachmentDrawerVisible" />
<footer-tool-bar :style="{ width: isSideMenu() && isDesktop() ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%'}">
<a-button
type="danger"
@click="handleSaveDraft"
>保存草稿</a-button>
<a-button
type="primary"
@click="handleShowPostSetting"
style="margin-left: 8px;"
>发布</a-button>
<a-button
type="dashed"
@ -54,6 +61,7 @@
<script>
import { mixin, mixinDevice } from '@/utils/mixin.js'
import moment from 'moment'
import PostSetting from './components/PostSetting'
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
import FooterToolBar from '@/components/FooterToolbar'
@ -83,27 +91,9 @@ export default {
postSettingVisible: false,
postToStage: {},
selectedTagIds: [],
selectedCategoryIds: [],
timer: null
selectedCategoryIds: []
}
},
created() {
clearInterval(this.timer)
this.timer = null
this.autoSaveTimer()
},
destroyed: function() {
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
@ -119,6 +109,20 @@ export default {
})
},
methods: {
handleSaveDraft() {
this.postToStage.status = 'DRAFT'
if (!this.postToStage.title) {
this.postToStage.title = moment(new Date())
}
if (!this.postToStage.originalContent) {
this.postToStage.originalContent = '开始编辑...'
}
this.createOrUpdatePost(
() => this.$message.success('保存草稿成功!'),
() => this.$message.success('保存草稿成功!'),
false
)
},
createOrUpdatePost(createSuccess, updateSuccess, autoSave) {
if (this.postToStage.id) {
// Update the post
@ -139,18 +143,6 @@ export default {
})
}
},
autoSavePost() {
if (this.postToStage.title != null && this.postToStage.originalContent != null) {
this.createOrUpdatePost(null, null, true)
}
},
autoSaveTimer() {
if (this.timer == null) {
this.timer = setInterval(() => {
this.autoSavePost()
}, 15000)
}
},
handleAttachmentUpload(pos, $file) {
var formdata = new FormData()
formdata.append('file', $file)

@ -19,6 +19,8 @@
:ishljs="true"
:autofocus="false"
@imgAdd="handleAttachmentUpload"
@keydown.ctrl.83.native="handleSaveDraft"
@keydown.meta.83.native="handleSaveDraft"
/>
</div>
</a-col>
@ -33,8 +35,13 @@
<AttachmentDrawer v-model="attachmentDrawerVisible" />
<footer-tool-bar :style="{ width: isSideMenu() && isDesktop() ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%'}">
<a-button
type="danger"
@click="handleSaveDraft"
>保存草稿</a-button>
<a-button
type="primary"
style="margin-left: 8px;"
@click="handleShowSheetSetting"
>发布</a-button>
<a-button
@ -48,6 +55,7 @@
<script>
import { mixin, mixinDevice } from '@/utils/mixin.js'
import moment from 'moment'
import { toolbars } from '@/core/const'
import SheetSetting from './components/SheetSetting'
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
@ -74,27 +82,9 @@ export default {
},
attachmentDrawerVisible: false,
sheetSettingVisible: false,
sheetToStage: {},
timer: null
sheetToStage: {}
}
},
created() {
clearInterval(this.timer)
this.timer = null
this.autoSaveTimer()
},
destroyed: function() {
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
@ -109,6 +99,20 @@ export default {
})
},
methods: {
handleSaveDraft() {
this.sheetToStage.status = 'DRAFT'
if (!this.sheetToStage.title) {
this.sheetToStage.title = moment(new Date())
}
if (!this.sheetToStage.originalContent) {
this.sheetToStage.originalContent = '开始编辑...'
}
this.createOrUpdateSheet(
() => this.$message.success('保存草稿成功!'),
() => this.$message.success('保存草稿成功!'),
false
)
},
createOrUpdateSheet(createSuccess, updateSuccess, autoSave) {
if (this.sheetToStage.id) {
sheetApi.update(this.sheetToStage.id, this.sheetToStage, autoSave).then(response => {
@ -127,18 +131,6 @@ export default {
})
}
},
autoSaveSheet() {
if (this.sheetToStage.title != null && this.sheetToStage.originalContent != null) {
this.createOrUpdateSheet(null, null, true)
}
},
autoSaveTimer() {
if (this.timer == null) {
this.timer = setInterval(() => {
this.autoSaveSheet()
}, 15000)
}
},
handleAttachmentUpload(pos, $file) {
var formdata = new FormData()
formdata.append('file', $file)

Loading…
Cancel
Save