refactor: related functions for publishing posts. (#99)

pull/100/head
Ryan Wang 2020-03-16 11:22:38 +08:00 committed by GitHub
parent b7ff9232ff
commit 865f1729a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 114 additions and 121 deletions

6
package-lock.json generated
View File

@ -6581,9 +6581,9 @@
"optional": true
},
"filepond": {
"version": "4.12.0",
"resolved": "https://registry.npmjs.org/filepond/-/filepond-4.12.0.tgz",
"integrity": "sha512-43+WI8R3RtSiPsKTcofnf9CW3i26sENIJFC1VERlu593mg/c5o74SU+gUfoocRWqDWQxjwE2qrobe+CUCPRASg=="
"version": "4.13.0",
"resolved": "https://registry.npmjs.org/filepond/-/filepond-4.13.0.tgz",
"integrity": "sha512-M9bNneR2EBrhXqNMHZLDRZVRSPJ5fUa8hjKyfMuJ8dV61qW1oPsFWZY2Ubx7WmVKZXnBLJCef2WNGh6CaIoTew=="
},
"filepond-plugin-image-preview": {
"version": "4.6.1",

View File

@ -12,7 +12,7 @@
"ant-design-vue": "^1.5.0-beta.1",
"axios": "^0.19.2",
"enquire.js": "^2.1.6",
"filepond": "^4.12.0",
"filepond": "^4.13.0",
"filepond-plugin-image-preview": "^4.6.1",
"halo-editor": "^2.8.2",
"marked": "^0.8.0",

View File

@ -16,10 +16,15 @@
<a
href="javascript:void(0)"
@click="showOptionModal"
>
<a-tooltip
placement="bottom"
title="后台布局设置"
>
<span class="action">
<a-icon type="setting" />
</span>
</a-tooltip>
</a>
<header-comment class="action" />
<a-dropdown>

View File

@ -2,7 +2,7 @@
<div>
<halo-editor
ref="md"
v-model="originalContent"
v-model="originalContentData"
:boxShadow="false"
:toolbars="toolbars"
:ishljs="true"

View File

@ -189,7 +189,7 @@
v-if="selectAttachment"
:attachment="selectAttachment"
:addToPhoto="true"
@delete="() => this.loadAttachments()"
@delete="loadAttachments()"
/>
</page-view>
</template>

View File

@ -107,7 +107,7 @@ export default {
drawerWidth: {
type: Number,
required: false,
default: 460
default: 480
},
title: {
type: String,

View File

@ -233,7 +233,7 @@
>
<a
href="javascript:void(0);"
@click="()=>this.logListDrawerVisible = true"
@click="logListDrawerVisible = true"
>
<a-icon type="ellipsis" />
</a>

View File

@ -128,7 +128,7 @@
<a
rel="noopener noreferrer"
href="javascript:void(0);"
@click="()=>this.uploadThemeVisible = true"
@click="uploadThemeVisible = true"
>安装主题</a>
</a-menu-item>
<a-menu-item>

View File

@ -40,7 +40,7 @@
<a
href="javascript:void(0);"
slot="addonAfter"
@click="()=>this.thumbnailDrawerVisible = true"
@click="thumbnailDrawerVisible = true"
>
<a-icon type="picture" />
</a>

View File

@ -12,17 +12,16 @@
<div id="editor">
<MarkdownEditor
v-if="postToStage.editorType=='MARKDOWN'"
:originalContent="postToStage.originalContent"
@onSaveDraft="handleSaveDraft(true)"
@onContentChange="onContentChange"
/>
<RichTextEditor
<!-- <RichTextEditor
v-else
:originalContent="postToStage.originalContent"
@onContentChange="onContentChange"
/>
/> -->
</div>
</a-col>
</a-row>
@ -61,7 +60,7 @@
>发布</a-button>
<a-button
type="dashed"
@click="()=>this.attachmentDrawerVisible = true"
@click="attachmentDrawerVisible = true"
style="margin-left: 8px;"
>附件库</a-button>
</footer-tool-bar>
@ -70,13 +69,13 @@
<script>
import { mixin, mixinDevice } from '@/utils/mixin.js'
import { mapGetters } from 'vuex'
// import { mapGetters } from 'vuex'
import moment from 'moment'
import PostSettingDrawer from './components/PostSettingDrawer'
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
import FooterToolBar from '@/components/FooterToolbar'
import MarkdownEditor from '@/components/editor/MarkdownEditor'
import RichTextEditor from '@/components/editor/RichTextEditor'
// import RichTextEditor from '@/components/editor/RichTextEditor'
import postApi from '@/api/post'
export default {
@ -85,8 +84,8 @@ export default {
PostSettingDrawer,
FooterToolBar,
AttachmentDrawer,
MarkdownEditor,
RichTextEditor
MarkdownEditor
// RichTextEditor
},
data() {
return {
@ -160,9 +159,9 @@ export default {
}
return '当前页面数据未保存,确定要离开吗?'
}
if (!this.postToStage.editorType) {
this.postToStage.editorType = this.options.default_editor
}
// if (!this.postToStage.editorType) {
// this.postToStage.editorType = this.options.default_editor
// }
},
watch: {
temporaryContent: function(newValue, oldValue) {
@ -174,8 +173,8 @@ export default {
computed: {
temporaryContent() {
return this.postToStage.originalContent
},
...mapGetters(['options'])
}
// ...mapGetters(['options'])
},
methods: {
handleSaveDraft(draftOnly = false) {

View File

@ -490,8 +490,6 @@
:metas="selectedMetas"
:needTitle="true"
:saveDraftButton="false"
:savePublishButton="false"
:saveButton="true"
:visible="postSettingVisible"
@close="onPostSettingsClose"
@onRefreshPost="onRefreshPostFromSetting"

View File

@ -34,7 +34,7 @@
<a
href="javascript:void(0);"
slot="addonAfter"
@click="()=>this.thumbnailDrawerVisible = true"
@click="thumbnailDrawerVisible = true"
>
<a-icon type="picture" />
</a>

View File

@ -176,7 +176,7 @@
<img
class="img"
:src="selectedPost.thumbnail || '/images/placeholder.jpg'"
@click="()=>this.thumbDrawerVisible=true"
@click="thumbDrawerVisible=true"
>
<a-form layout="vertial">
@ -202,7 +202,7 @@
<AttachmentSelectDrawer
v-model="thumbDrawerVisible"
@listenToSelect="handleSelectPostThumb"
:drawerWidth="460"
:drawerWidth="480"
/>
<a-drawer
@ -279,7 +279,7 @@
<a-button
style="marginRight: 8px"
type="dashed"
@click="()=>this.advancedVisible = true"
@click="advancedVisible = true"
>高级</a-button>
<a-button
style="marginRight: 8px"
@ -290,15 +290,8 @@
<a-button
@click="handlePublishClick"
type="primary"
v-if="savePublishButton"
:disabled="saving"
>发布</a-button>
<a-button
@click="handlePublishClick"
type="primary"
v-if="saveButton"
:disabled="saving"
>保存</a-button>
> {{ selectedPost.id?'保存':'发布' }} </a-button>
</div>
</a-drawer>
</template>
@ -354,11 +347,6 @@ export default {
type: Array,
required: true
},
visible: {
type: Boolean,
required: false,
default: true
},
needTitle: {
type: Boolean,
required: false,
@ -369,15 +357,10 @@ export default {
required: false,
default: true
},
savePublishButton: {
visible: {
type: Boolean,
required: false,
default: true
},
saveButton: {
type: Boolean,
required: false,
default: false
}
},
watch: {
@ -484,20 +467,13 @@ export default {
},
handleDraftClick() {
this.selectedPost.status = 'DRAFT'
this.savePost()
this.createOrUpdatePost()
},
handlePublishClick() {
this.selectedPost.status = 'PUBLISHED'
this.savePost()
this.createOrUpdatePost()
},
savePost() {
this.createOrUpdatePost(
() => this.$message.success('文章发布成功'),
() => this.$message.success('文章发布成功'),
false
)
},
createOrUpdatePost(createSuccess, updateSuccess, autoSave) {
createOrUpdatePost() {
if (!this.selectedPost.title) {
this.$notification['error']({
message: '提示',
@ -515,14 +491,18 @@ export default {
if (this.selectedPost.id) {
// Update the post
postApi
.update(this.selectedPost.id, this.selectedPost, autoSave)
.update(this.selectedPost.id, this.selectedPost, false)
.then(response => {
this.$log.debug('Updated post', response.data.data)
if (updateSuccess) {
updateSuccess()
if (this.selectedPost.status === 'DRAFT') {
this.$message.success('草稿保存成功!')
} else {
this.$message.success('文章更新成功!')
}
this.$emit('onSaved', true)
this.$router.push({ name: 'PostList' })
}
})
.finally(() => {
this.saving = false
@ -530,14 +510,18 @@ export default {
} else {
// Create the post
postApi
.create(this.selectedPost, autoSave)
.create(this.selectedPost, false)
.then(response => {
this.$log.debug('Created post', response.data.data)
if (createSuccess) {
createSuccess()
if (this.selectedPost.status === 'DRAFT') {
this.$message.success('草稿保存成功!')
} else {
this.$message.success('文章发布成功!')
}
this.$emit('onSaved', true)
this.$router.push({ name: 'PostList' })
}
this.selectedPost = response.data.data
})
.finally(() => {

View File

@ -12,17 +12,16 @@
<div id="editor">
<MarkdownEditor
v-if="sheetToStage.editorType=='MARKDOWN'"
:originalContent="sheetToStage.originalContent"
@onSaveDraft="handleSaveDraft(true)"
@onContentChange="onContentChange"
/>
<RichTextEditor
<!-- <RichTextEditor
v-else
:originalContent="sheetToStage.originalContent"
@onContentChange="onContentChange"
/>
/> -->
</div>
</a-col>
</a-row>
@ -57,7 +56,7 @@
<a-button
type="dashed"
style="margin-left: 8px;"
@click="()=>this.attachmentDrawerVisible = true"
@click="attachmentDrawerVisible = true"
>附件库</a-button>
</footer-tool-bar>
</div>
@ -65,13 +64,13 @@
<script>
import { mixin, mixinDevice } from '@/utils/mixin.js'
import { mapGetters } from 'vuex'
// import { mapGetters } from 'vuex'
import moment from 'moment'
import SheetSettingDrawer from './components/SheetSettingDrawer'
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
import FooterToolBar from '@/components/FooterToolbar'
import MarkdownEditor from '@/components/editor/MarkdownEditor'
import RichTextEditor from '@/components/editor/RichTextEditor'
// import RichTextEditor from '@/components/editor/RichTextEditor'
import sheetApi from '@/api/sheet'
export default {
@ -79,8 +78,8 @@ export default {
FooterToolBar,
AttachmentDrawer,
SheetSettingDrawer,
MarkdownEditor,
RichTextEditor
MarkdownEditor
// RichTextEditor
},
mixins: [mixin, mixinDevice],
data() {
@ -151,9 +150,9 @@ export default {
}
return '当前页面数据未保存,确定要离开吗?'
}
if (!this.sheetToStage.editorType) {
this.sheetToStage.editorType = this.options.default_editor
}
// if (!this.sheetToStage.editorType) {
// this.sheetToStage.editorType = this.options.default_editor
// }
},
watch: {
temporaryContent: function(newValue, oldValue) {
@ -165,8 +164,8 @@ export default {
computed: {
temporaryContent() {
return this.sheetToStage.originalContent
},
...mapGetters(['options'])
}
// ...mapGetters(['options'])
},
methods: {
handleSaveDraft(draftOnly = false) {

View File

@ -321,6 +321,7 @@
:metas="selectedMetas"
:visible="sheetSettingVisible"
:needTitle="true"
:saveDraftButton="false"
@close="onSheetSettingsClose"
@onRefreshSheet="onRefreshSheetFromSetting"
@onRefreshSheetMetas="onRefreshSheetMetasFromSetting"

View File

@ -94,7 +94,7 @@
<img
class="img"
:src="selectedSheet.thumbnail || '/images/placeholder.jpg'"
@click="()=>this.thumbDrawerVisible = true"
@click="thumbDrawerVisible = true"
>
<a-form layout="vertial">
@ -120,7 +120,7 @@
<AttachmentSelectDrawer
v-model="thumbDrawerVisible"
@listenToSelect="handleSelectSheetThumb"
:drawerWidth="460"
:drawerWidth="480"
/>
<a-drawer
@ -197,9 +197,10 @@
<a-button
style="marginRight: 8px"
type="dashed"
@click="()=>this.advancedVisible = true"
@click="advancedVisible = true"
>高级</a-button>
<a-button
v-if="saveDraftButton"
style="marginRight: 8px"
@click="handleDraftClick"
:disabled="saving"
@ -208,7 +209,7 @@
type="primary"
@click="handlePublishClick"
:disabled="saving"
>发布</a-button>
>{{ selectedSheet.id?'保存':'发布' }}</a-button>
</div>
</a-drawer>
</template>
@ -249,6 +250,11 @@ export default {
required: false,
default: false
},
saveDraftButton: {
type: Boolean,
required: false,
default: true
},
visible: {
type: Boolean,
required: false,
@ -325,20 +331,13 @@ export default {
},
handlePublishClick() {
this.selectedSheet.status = 'PUBLISHED'
this.saveSheet()
this.createOrUpdateSheet()
},
handleDraftClick() {
this.selectedSheet.status = 'DRAFT'
this.saveSheet()
this.createOrUpdateSheet()
},
saveSheet() {
this.createOrUpdateSheet(
() => this.$message.success('页面发布成功!'),
() => this.$message.success('页面发布成功!'),
false
)
},
createOrUpdateSheet(createSuccess, updateSuccess, autoSave) {
createOrUpdateSheet() {
if (!this.selectedSheet.title) {
this.$notification['error']({
message: '提示',
@ -350,28 +349,36 @@ export default {
this.saving = true
if (this.selectedSheet.id) {
sheetApi
.update(this.selectedSheet.id, this.selectedSheet, autoSave)
.update(this.selectedSheet.id, this.selectedSheet, false)
.then(response => {
this.$log.debug('Updated sheet', response.data.data)
if (updateSuccess) {
updateSuccess()
if (this.selectedSheet.status === 'DRAFT') {
this.$message.success('草稿保存成功!')
} else {
this.$message.success('页面更新成功!')
}
this.$emit('onSaved', true)
this.$router.push({ name: 'SheetList' })
}
})
.finally(() => {
this.saving = false
})
} else {
sheetApi
.create(this.selectedSheet, autoSave)
.create(this.selectedSheet, false)
.then(response => {
this.$log.debug('Created sheet', response.data.data)
if (createSuccess) {
createSuccess()
if (this.selectedSheet.status === 'DRAFT') {
this.$message.success('草稿保存成功!')
} else {
this.$message.success('页面发布成功!')
}
this.$emit('onSaved', true)
this.$router.push({ name: 'SheetList' })
}
this.selectedSheet = response.data.data
})
.finally(() => {

View File

@ -163,7 +163,7 @@
shape="circle"
icon="setting"
size="large"
@click="()=>this.optionFormVisible=true"
@click="optionFormVisible=true"
></a-button>
</div>
<a-modal
@ -205,7 +205,7 @@
<template slot="footer">
<a-button
type="dashed"
@click="()=>this.attachmentDrawerVisible = true"
@click="attachmentDrawerVisible = true"
>附件库</a-button>
<a-button
key="submit"

View File

@ -202,7 +202,7 @@
shape="circle"
icon="setting"
size="large"
@click="()=>this.optionFormVisible=true"
@click="optionFormVisible=true"
></a-button>
</div>
<a-modal

View File

@ -122,7 +122,7 @@
shape="circle"
icon="setting"
size="large"
@click="()=>this.optionFormVisible=true"
@click="optionFormVisible=true"
></a-button>
</div>
<a-modal
@ -298,7 +298,7 @@
<AttachmentSelectDrawer
v-model="thumDrawerVisible"
@listenToSelect="selectPhotoThumb"
:drawerWidth="460"
:drawerWidth="480"
/>
<a-divider class="divider-transparent" />
<div class="bottom-control">

View File

@ -68,7 +68,7 @@
<a-button
type="primary"
style="float:right"
@click="()=>this.backupDrawerVisible = true"
@click="backupDrawerVisible = true"
>备份</a-button>
</a-card>
</a-col>

View File

@ -59,7 +59,7 @@
<a-button
type="primary"
icon="plus"
@click="()=>this.formVisible=true"
@click="formVisible=true"
>新增</a-button>
</div>
<div style="margin-top:15px">

View File

@ -26,7 +26,7 @@
<a-button
type="primary"
style="margin-right: 8px;"
@click="()=>this.loadLogs()"
@click="loadLogs()"
>刷新</a-button>
<a-button
type="dashed"

View File

@ -18,7 +18,7 @@
<a
href="javascript:void(0);"
slot="addonAfter"
@click="()=>this.logoDrawerVisible = true"
@click="logoDrawerVisible = true"
>
<a-icon type="picture" />
</a>
@ -29,7 +29,7 @@
<a
href="javascript:void(0);"
slot="addonAfter"
@click="()=>this.faviconDrawerVisible = true"
@click="faviconDrawerVisible = true"
>
<a-icon type="picture" />
</a>

View File

@ -4,12 +4,12 @@
layout="vertical"
:wrapperCol="wrapperCol"
>
<a-form-item label="默认编辑器:">
<!-- <a-form-item label="默认编辑器:">
<a-select v-model="options.default_editor">
<a-select-option value="MARKDOWN">Markdown 编辑器</a-select-option>
<a-select-option value="RICHTEXT">富文本编辑器</a-select-option>
</a-select>
</a-form-item>
</a-form-item> -->
<a-form-item label="首页文章排序:">
<a-select v-model="options.post_index_sort">
<a-select-option value="createTime">创建时间</a-select-option>

View File

@ -22,7 +22,7 @@
<div class="avatar">
<img
:src="user.avatar || '//cn.gravatar.com/avatar/?s=256&d=mm'"
@click="()=>this.attachmentDrawerVisible = true"
@click="attachmentDrawerVisible = true"
>
</div>
</a-tooltip>