diff --git a/src/views/post/PostEdit.vue b/src/views/post/PostEdit.vue
index 24ca8c60..0bd974e9 100644
--- a/src/views/post/PostEdit.vue
+++ b/src/views/post/PostEdit.vue
@@ -20,6 +20,8 @@
:ishljs="true"
:autofocus="false"
@imgAdd="handleAttachmentUpload"
+ @keydown.ctrl.83.native="handleSaveDraft"
+ @keydown.meta.83.native="handleSaveDraft"
/>
@@ -39,9 +41,14 @@
+ 保存草稿
发布
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)
diff --git a/src/views/sheet/SheetEdit.vue b/src/views/sheet/SheetEdit.vue
index f6663354..b53a21c6 100644
--- a/src/views/sheet/SheetEdit.vue
+++ b/src/views/sheet/SheetEdit.vue
@@ -19,6 +19,8 @@
:ishljs="true"
:autofocus="false"
@imgAdd="handleAttachmentUpload"
+ @keydown.ctrl.83.native="handleSaveDraft"
+ @keydown.meta.83.native="handleSaveDraft"
/>
@@ -33,8 +35,13 @@
+ 保存草稿
发布
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)