pull/59/head
ruibaby 2019-11-23 11:46:16 +08:00
parent 1eb4c2ee03
commit 9281630827
6 changed files with 60 additions and 29 deletions

8
package-lock.json generated
View File

@ -8226,11 +8226,11 @@
} }
}, },
"halo-editor": { "halo-editor": {
"version": "2.7.8", "version": "2.7.6",
"resolved": "https://registry.npmjs.org/halo-editor/-/halo-editor-2.7.8.tgz", "resolved": "https://registry.npmjs.org/halo-editor/-/halo-editor-2.7.6.tgz",
"integrity": "sha512-Okpnv3JQMDgQsxmKNTcSNfrvV8+FeeR2MhZ1hBhVp1yvDHFyujXENmaoGplQ/aUrnpebc4RiDAuHcB+Yla1S3Q==", "integrity": "sha512-ipzW+pxWoC3JB5jAlC/7fFZnqBbXMtC6eOXZDM1dtuM4BN60kOH/tzJMlLCuEYCzWnhg+abtwtljAtOe66ASGg==",
"requires": { "requires": {
"highlight.js": "^9.16.2", "highlight.js": "^9.11.0",
"highlight.js-async-webpack": "^1.0.4" "highlight.js-async-webpack": "^1.0.4"
} }
}, },

View File

@ -15,7 +15,7 @@
"enquire.js": "^2.1.6", "enquire.js": "^2.1.6",
"filepond": "^4.7.2", "filepond": "^4.7.2",
"filepond-plugin-image-preview": "^4.5.0", "filepond-plugin-image-preview": "^4.5.0",
"halo-editor": "^2.7.8", "halo-editor": "^2.7.6",
"marked": "^0.7.0", "marked": "^0.7.0",
"moment": "^2.24.0", "moment": "^2.24.0",
"nprogress": "^0.2.0", "nprogress": "^0.2.0",

View File

@ -5,7 +5,6 @@
<div style="margin-bottom: 16px"> <div style="margin-bottom: 16px">
<a-input <a-input
v-model="postToStage.title" v-model="postToStage.title"
v-decorator="['title', { rules: [{ required: true, message: '请输入文章标题' }] }]"
size="large" size="large"
placeholder="请输入文章标题" placeholder="请输入文章标题"
/> />
@ -36,6 +35,7 @@
@onRefreshPost="onRefreshPostFromSetting" @onRefreshPost="onRefreshPostFromSetting"
@onRefreshTagIds="onRefreshTagIdsFromSetting" @onRefreshTagIds="onRefreshTagIdsFromSetting"
@onRefreshCategoryIds="onRefreshCategoryIdsFromSetting" @onRefreshCategoryIds="onRefreshCategoryIdsFromSetting"
@onSaved="onSaved"
/> />
<AttachmentDrawer v-model="attachmentDrawerVisible" /> <AttachmentDrawer v-model="attachmentDrawerVisible" />
@ -91,7 +91,8 @@ export default {
postSettingVisible: false, postSettingVisible: false,
postToStage: {}, postToStage: {},
selectedTagIds: [], selectedTagIds: [],
selectedCategoryIds: [] selectedCategoryIds: [],
isSaved: false
} }
}, },
beforeRouteEnter(to, from, next) { beforeRouteEnter(to, from, next) {
@ -115,7 +116,9 @@ export default {
if (this.attachmentDrawerVisible) { if (this.attachmentDrawerVisible) {
this.attachmentDrawerVisible = false this.attachmentDrawerVisible = false
} }
window.onbeforeunload = null if (window.onbeforeunload) {
window.onbeforeunload = null
}
}, },
beforeRouteLeave(to, from, next) { beforeRouteLeave(to, from, next) {
if (this.postSettingVisible) { if (this.postSettingVisible) {
@ -124,24 +127,31 @@ export default {
if (this.attachmentDrawerVisible) { if (this.attachmentDrawerVisible) {
this.attachmentDrawerVisible = false this.attachmentDrawerVisible = false
} }
if (this.postToStage.originalContent) {
const answer = window.confirm('当前文章数据未保存,确定要离开吗?') if (!this.postToStage.originalContent) {
if (answer) {
next()
} else {
next(false)
}
} else {
next() next()
} else if (this.isSaved) {
next()
} else {
this.$confirm({
title: '当前页面数据未保存,确定要离开吗?',
content: h => <div style="color:red;">如果离开当面页面你的数据很可能会丢失</div>,
onOk() {
next()
},
onCancel() {
next(false)
}
})
} }
}, },
mounted() { mounted() {
window.onbeforeunload = function(e) { window.onbeforeunload = function(e) {
e = e || window.event e = e || window.event
if (e) { if (e) {
e.returnValue = '当前文章数据未保存,确定要离开吗?' e.returnValue = '当前页面数据未保存,确定要离开吗?'
} }
return '当前文章数据未保存,确定要离开吗?' return '当前页面数据未保存,确定要离开吗?'
} }
}, },
computed: { computed: {
@ -228,6 +238,9 @@ export default {
}, },
onRefreshCategoryIdsFromSetting(categoryIds) { onRefreshCategoryIdsFromSetting(categoryIds) {
this.selectedCategoryIds = categoryIds this.selectedCategoryIds = categoryIds
},
onSaved(isSaved) {
this.isSaved = isSaved
} }
} }
} }

View File

@ -377,6 +377,7 @@ export default {
this.$log.debug('Updated post', response.data.data) this.$log.debug('Updated post', response.data.data)
if (updateSuccess) { if (updateSuccess) {
updateSuccess() updateSuccess()
this.$emit('onSaved', true)
this.$router.push({ name: 'PostList' }) this.$router.push({ name: 'PostList' })
} }
}) })
@ -386,6 +387,7 @@ export default {
this.$log.debug('Created post', response.data.data) this.$log.debug('Created post', response.data.data)
if (createSuccess) { if (createSuccess) {
createSuccess() createSuccess()
this.$emit('onSaved', true)
this.$router.push({ name: 'PostList' }) this.$router.push({ name: 'PostList' })
} }
this.selectedPost = response.data.data this.selectedPost = response.data.data

View File

@ -5,7 +5,6 @@
<div style="margin-bottom: 16px"> <div style="margin-bottom: 16px">
<a-input <a-input
v-model="sheetToStage.title" v-model="sheetToStage.title"
v-decorator="['title', { rules: [{ required: true, message: '请输入页面标题' }] }]"
size="large" size="large"
placeholder="请输入页面标题" placeholder="请输入页面标题"
/> />
@ -31,6 +30,7 @@
:visible="sheetSettingVisible" :visible="sheetSettingVisible"
@close="onSheetSettingsClose" @close="onSheetSettingsClose"
@onRefreshSheet="onRefreshSheetFromSetting" @onRefreshSheet="onRefreshSheetFromSetting"
@onSaved="onSaved"
/> />
<AttachmentDrawer v-model="attachmentDrawerVisible" /> <AttachmentDrawer v-model="attachmentDrawerVisible" />
@ -82,7 +82,8 @@ export default {
toolbars, toolbars,
attachmentDrawerVisible: false, attachmentDrawerVisible: false,
sheetSettingVisible: false, sheetSettingVisible: false,
sheetToStage: {} sheetToStage: {},
isSaved: false
} }
}, },
beforeRouteEnter(to, from, next) { beforeRouteEnter(to, from, next) {
@ -105,7 +106,9 @@ export default {
if (this.attachmentDrawerVisible) { if (this.attachmentDrawerVisible) {
this.attachmentDrawerVisible = false this.attachmentDrawerVisible = false
} }
window.onbeforeunload = null if (window.onbeforeunload) {
window.onbeforeunload = null
}
}, },
beforeRouteLeave(to, from, next) { beforeRouteLeave(to, from, next) {
if (this.sheetSettingVisible) { if (this.sheetSettingVisible) {
@ -114,15 +117,21 @@ export default {
if (this.attachmentDrawerVisible) { if (this.attachmentDrawerVisible) {
this.attachmentDrawerVisible = false this.attachmentDrawerVisible = false
} }
if (this.sheetToStage.originalContent) { if (!this.sheetToStage.originalContent) {
const answer = window.confirm('当前页面数据未保存,确定要离开吗?')
if (answer) {
next()
} else {
next(false)
}
} else {
next() next()
} else if (this.isSaved) {
next()
} else {
this.$confirm({
title: '当前页面数据未保存,确定要离开吗?',
content: h => <div style="color:red;">如果离开当面页面你的数据很可能会丢失</div>,
onOk() {
next()
},
onCancel() {
next(false)
}
})
} }
}, },
mounted() { mounted() {
@ -207,6 +216,9 @@ export default {
}, },
onRefreshSheetFromSetting(sheet) { onRefreshSheetFromSetting(sheet) {
this.sheetToStage = sheet this.sheetToStage = sheet
},
onSaved(isSaved) {
this.isSaved = isSaved
} }
} }
} }

View File

@ -222,6 +222,8 @@ export default {
this.$log.debug('Updated sheet', response.data.data) this.$log.debug('Updated sheet', response.data.data)
if (updateSuccess) { if (updateSuccess) {
updateSuccess() updateSuccess()
this.$emit('onSaved', true)
this.$router.push({ name: 'SheetList' })
} }
}) })
} else { } else {
@ -229,6 +231,8 @@ export default {
this.$log.debug('Created sheet', response.data.data) this.$log.debug('Created sheet', response.data.data)
if (createSuccess) { if (createSuccess) {
createSuccess() createSuccess()
this.$emit('onSaved', true)
this.$router.push({ name: 'SheetList' })
} }
this.selectedSheet = response.data.data this.selectedSheet = response.data.data
}) })