mirror of https://github.com/halo-dev/halo
Remove timer of auto save post or sheet.
parent
9866ae1a18
commit
7d7f155f47
|
@ -20,6 +20,8 @@
|
||||||
:ishljs="true"
|
:ishljs="true"
|
||||||
:autofocus="false"
|
:autofocus="false"
|
||||||
@imgAdd="handleAttachmentUpload"
|
@imgAdd="handleAttachmentUpload"
|
||||||
|
@keydown.ctrl.83.native="handleSaveDraft"
|
||||||
|
@keydown.meta.83.native="handleSaveDraft"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</a-col>
|
</a-col>
|
||||||
|
@ -39,9 +41,14 @@
|
||||||
<AttachmentDrawer v-model="attachmentDrawerVisible" />
|
<AttachmentDrawer v-model="attachmentDrawerVisible" />
|
||||||
|
|
||||||
<footer-tool-bar :style="{ width: isSideMenu() && isDesktop() ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%'}">
|
<footer-tool-bar :style="{ width: isSideMenu() && isDesktop() ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%'}">
|
||||||
|
<a-button
|
||||||
|
type="danger"
|
||||||
|
@click="handleSaveDraft"
|
||||||
|
>保存草稿</a-button>
|
||||||
<a-button
|
<a-button
|
||||||
type="primary"
|
type="primary"
|
||||||
@click="handleShowPostSetting"
|
@click="handleShowPostSetting"
|
||||||
|
style="margin-left: 8px;"
|
||||||
>发布</a-button>
|
>发布</a-button>
|
||||||
<a-button
|
<a-button
|
||||||
type="dashed"
|
type="dashed"
|
||||||
|
@ -54,6 +61,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mixin, mixinDevice } from '@/utils/mixin.js'
|
import { mixin, mixinDevice } from '@/utils/mixin.js'
|
||||||
|
import moment from 'moment'
|
||||||
import PostSetting from './components/PostSetting'
|
import PostSetting from './components/PostSetting'
|
||||||
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
|
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
|
||||||
import FooterToolBar from '@/components/FooterToolbar'
|
import FooterToolBar from '@/components/FooterToolbar'
|
||||||
|
@ -83,27 +91,9 @@ export default {
|
||||||
postSettingVisible: false,
|
postSettingVisible: false,
|
||||||
postToStage: {},
|
postToStage: {},
|
||||||
selectedTagIds: [],
|
selectedTagIds: [],
|
||||||
selectedCategoryIds: [],
|
selectedCategoryIds: []
|
||||||
timer: null
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
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) {
|
beforeRouteEnter(to, from, next) {
|
||||||
// Get post id from query
|
// Get post id from query
|
||||||
const postId = to.query.postId
|
const postId = to.query.postId
|
||||||
|
@ -119,6 +109,20 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
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) {
|
createOrUpdatePost(createSuccess, updateSuccess, autoSave) {
|
||||||
if (this.postToStage.id) {
|
if (this.postToStage.id) {
|
||||||
// Update the post
|
// 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) {
|
handleAttachmentUpload(pos, $file) {
|
||||||
var formdata = new FormData()
|
var formdata = new FormData()
|
||||||
formdata.append('file', $file)
|
formdata.append('file', $file)
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
:ishljs="true"
|
:ishljs="true"
|
||||||
:autofocus="false"
|
:autofocus="false"
|
||||||
@imgAdd="handleAttachmentUpload"
|
@imgAdd="handleAttachmentUpload"
|
||||||
|
@keydown.ctrl.83.native="handleSaveDraft"
|
||||||
|
@keydown.meta.83.native="handleSaveDraft"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</a-col>
|
</a-col>
|
||||||
|
@ -33,8 +35,13 @@
|
||||||
|
|
||||||
<AttachmentDrawer v-model="attachmentDrawerVisible" />
|
<AttachmentDrawer v-model="attachmentDrawerVisible" />
|
||||||
<footer-tool-bar :style="{ width: isSideMenu() && isDesktop() ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%'}">
|
<footer-tool-bar :style="{ width: isSideMenu() && isDesktop() ? `calc(100% - ${sidebarOpened ? 256 : 80}px)` : '100%'}">
|
||||||
|
<a-button
|
||||||
|
type="danger"
|
||||||
|
@click="handleSaveDraft"
|
||||||
|
>保存草稿</a-button>
|
||||||
<a-button
|
<a-button
|
||||||
type="primary"
|
type="primary"
|
||||||
|
style="margin-left: 8px;"
|
||||||
@click="handleShowSheetSetting"
|
@click="handleShowSheetSetting"
|
||||||
>发布</a-button>
|
>发布</a-button>
|
||||||
<a-button
|
<a-button
|
||||||
|
@ -48,6 +55,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mixin, mixinDevice } from '@/utils/mixin.js'
|
import { mixin, mixinDevice } from '@/utils/mixin.js'
|
||||||
|
import moment from 'moment'
|
||||||
import { toolbars } from '@/core/const'
|
import { toolbars } from '@/core/const'
|
||||||
import SheetSetting from './components/SheetSetting'
|
import SheetSetting from './components/SheetSetting'
|
||||||
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
|
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
|
||||||
|
@ -74,27 +82,9 @@ export default {
|
||||||
},
|
},
|
||||||
attachmentDrawerVisible: false,
|
attachmentDrawerVisible: false,
|
||||||
sheetSettingVisible: false,
|
sheetSettingVisible: false,
|
||||||
sheetToStage: {},
|
sheetToStage: {}
|
||||||
timer: null
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
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) {
|
beforeRouteEnter(to, from, next) {
|
||||||
// Get sheetId id from query
|
// Get sheetId id from query
|
||||||
const sheetId = to.query.sheetId
|
const sheetId = to.query.sheetId
|
||||||
|
@ -109,6 +99,20 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
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) {
|
createOrUpdateSheet(createSuccess, updateSuccess, autoSave) {
|
||||||
if (this.sheetToStage.id) {
|
if (this.sheetToStage.id) {
|
||||||
sheetApi.update(this.sheetToStage.id, this.sheetToStage, autoSave).then(response => {
|
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) {
|
handleAttachmentUpload(pos, $file) {
|
||||||
var formdata = new FormData()
|
var formdata = new FormData()
|
||||||
formdata.append('file', $file)
|
formdata.append('file', $file)
|
||||||
|
|
Loading…
Reference in New Issue