mirror of https://github.com/halo-dev/halo-admin
refactor: pull out the markdown editor component. (#75)
parent
07e953a06d
commit
6ced7f7f83
|
@ -0,0 +1,67 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<halo-editor
|
||||||
|
ref="md"
|
||||||
|
v-model="originalContentData"
|
||||||
|
:boxShadow="false"
|
||||||
|
:toolbars="toolbars"
|
||||||
|
:ishljs="true"
|
||||||
|
:autofocus="false"
|
||||||
|
@imgAdd="handleAttachmentUpload"
|
||||||
|
@save="handleSaveDraft"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import { toolbars } from '@/core/const'
|
||||||
|
import { haloEditor } from 'halo-editor'
|
||||||
|
import 'halo-editor/dist/css/index.css'
|
||||||
|
import attachmentApi from '@/api/attachment'
|
||||||
|
export default {
|
||||||
|
name: 'MarkdownEditor',
|
||||||
|
components: {
|
||||||
|
haloEditor
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
originalContent: {
|
||||||
|
type: String,
|
||||||
|
required: false,
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
toolbars,
|
||||||
|
originalContentData: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
originalContent(val) {
|
||||||
|
this.originalContentData = val
|
||||||
|
},
|
||||||
|
originalContentData(val) {
|
||||||
|
this.$emit('onChange', val)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleAttachmentUpload(pos, $file) {
|
||||||
|
var formdata = new FormData()
|
||||||
|
formdata.append('file', $file)
|
||||||
|
attachmentApi.upload(formdata).then(response => {
|
||||||
|
var responseObject = response.data
|
||||||
|
|
||||||
|
if (responseObject.status === 200) {
|
||||||
|
var HaloEditor = this.$refs.md
|
||||||
|
HaloEditor.$img2Url(pos, encodeURI(responseObject.data.path))
|
||||||
|
this.$message.success('图片上传成功!')
|
||||||
|
} else {
|
||||||
|
this.$message.error('图片上传失败:' + responseObject.message)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
handleSaveDraft() {
|
||||||
|
this.$emit('onSaveDraft')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -11,15 +11,10 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="editor">
|
<div id="editor">
|
||||||
<halo-editor
|
<MarkdownEditor
|
||||||
ref="md"
|
:originalContent="postToStage.originalContent"
|
||||||
v-model="postToStage.originalContent"
|
@onSaveDraft="handleSaveDraft(true)"
|
||||||
:boxShadow="false"
|
@onChange="onContentChange"
|
||||||
:toolbars="toolbars"
|
|
||||||
:ishljs="true"
|
|
||||||
:autofocus="false"
|
|
||||||
@imgAdd="handleAttachmentUpload"
|
|
||||||
@save="handleSaveDraft(true)"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</a-col>
|
</a-col>
|
||||||
|
@ -73,23 +68,19 @@ import moment from 'moment'
|
||||||
import PostSettingDrawer from './components/PostSettingDrawer'
|
import PostSettingDrawer from './components/PostSettingDrawer'
|
||||||
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
|
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
|
||||||
import FooterToolBar from '@/components/FooterToolbar'
|
import FooterToolBar from '@/components/FooterToolbar'
|
||||||
import { toolbars } from '@/core/const'
|
import MarkdownEditor from '@/components/editor/MarkdownEditor'
|
||||||
import { haloEditor } from 'halo-editor'
|
|
||||||
import 'halo-editor/dist/css/index.css'
|
|
||||||
|
|
||||||
import postApi from '@/api/post'
|
import postApi from '@/api/post'
|
||||||
import attachmentApi from '@/api/attachment'
|
|
||||||
export default {
|
export default {
|
||||||
mixins: [mixin, mixinDevice],
|
mixins: [mixin, mixinDevice],
|
||||||
components: {
|
components: {
|
||||||
PostSettingDrawer,
|
PostSettingDrawer,
|
||||||
haloEditor,
|
|
||||||
FooterToolBar,
|
FooterToolBar,
|
||||||
AttachmentDrawer
|
AttachmentDrawer,
|
||||||
|
MarkdownEditor
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
toolbars,
|
|
||||||
attachmentDrawerVisible: false,
|
attachmentDrawerVisible: false,
|
||||||
postSettingVisible: false,
|
postSettingVisible: false,
|
||||||
postToStage: {},
|
postToStage: {},
|
||||||
|
@ -218,21 +209,6 @@ export default {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleAttachmentUpload(pos, $file) {
|
|
||||||
var formdata = new FormData()
|
|
||||||
formdata.append('file', $file)
|
|
||||||
attachmentApi.upload(formdata).then(response => {
|
|
||||||
var responseObject = response.data
|
|
||||||
|
|
||||||
if (responseObject.status === 200) {
|
|
||||||
var HaloEditor = this.$refs.md
|
|
||||||
HaloEditor.$img2Url(pos, encodeURI(responseObject.data.path))
|
|
||||||
this.$message.success('图片上传成功!')
|
|
||||||
} else {
|
|
||||||
this.$message.error('图片上传失败:' + responseObject.message)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
handleShowPostSetting() {
|
handleShowPostSetting() {
|
||||||
this.postSettingVisible = true
|
this.postSettingVisible = true
|
||||||
},
|
},
|
||||||
|
@ -271,6 +247,9 @@ export default {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onContentChange(val) {
|
||||||
|
this.postToStage.originalContent = val
|
||||||
|
},
|
||||||
// 关闭文章设置抽屉
|
// 关闭文章设置抽屉
|
||||||
onPostSettingsClose() {
|
onPostSettingsClose() {
|
||||||
this.postSettingVisible = false
|
this.postSettingVisible = false
|
||||||
|
|
|
@ -10,15 +10,10 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div id="editor">
|
<div id="editor">
|
||||||
<halo-editor
|
<MarkdownEditor
|
||||||
ref="md"
|
:originalContent="sheetToStage.originalContent"
|
||||||
v-model="sheetToStage.originalContent"
|
@onSaveDraft="handleSaveDraft"
|
||||||
:boxShadow="false"
|
@onChange="onContentChange"
|
||||||
:toolbars="toolbars"
|
|
||||||
:ishljs="true"
|
|
||||||
:autofocus="false"
|
|
||||||
@imgAdd="handleAttachmentUpload"
|
|
||||||
@save="handleSaveDraft"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</a-col>
|
</a-col>
|
||||||
|
@ -64,25 +59,21 @@
|
||||||
import { mixin, mixinDevice } from '@/utils/mixin.js'
|
import { mixin, mixinDevice } from '@/utils/mixin.js'
|
||||||
import { mapGetters } from 'vuex'
|
import { mapGetters } from 'vuex'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import { toolbars } from '@/core/const'
|
|
||||||
import SheetSettingDrawer from './components/SheetSettingDrawer'
|
import SheetSettingDrawer from './components/SheetSettingDrawer'
|
||||||
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
|
import AttachmentDrawer from '../attachment/components/AttachmentDrawer'
|
||||||
import FooterToolBar from '@/components/FooterToolbar'
|
import FooterToolBar from '@/components/FooterToolbar'
|
||||||
import { haloEditor } from 'halo-editor'
|
import MarkdownEditor from '@/components/editor/MarkdownEditor'
|
||||||
import 'halo-editor/dist/css/index.css'
|
|
||||||
import sheetApi from '@/api/sheet'
|
import sheetApi from '@/api/sheet'
|
||||||
import attachmentApi from '@/api/attachment'
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
haloEditor,
|
|
||||||
FooterToolBar,
|
FooterToolBar,
|
||||||
AttachmentDrawer,
|
AttachmentDrawer,
|
||||||
SheetSettingDrawer
|
SheetSettingDrawer,
|
||||||
|
MarkdownEditor
|
||||||
},
|
},
|
||||||
mixins: [mixin, mixinDevice],
|
mixins: [mixin, mixinDevice],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
toolbars,
|
|
||||||
attachmentDrawerVisible: false,
|
attachmentDrawerVisible: false,
|
||||||
sheetSettingVisible: false,
|
sheetSettingVisible: false,
|
||||||
sheetToStage: {},
|
sheetToStage: {},
|
||||||
|
@ -193,21 +184,6 @@ export default {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleAttachmentUpload(pos, $file) {
|
|
||||||
var formdata = new FormData()
|
|
||||||
formdata.append('file', $file)
|
|
||||||
attachmentApi.upload(formdata).then(response => {
|
|
||||||
var responseObject = response.data
|
|
||||||
|
|
||||||
if (responseObject.status === 200) {
|
|
||||||
var HaloEditor = this.$refs.md
|
|
||||||
HaloEditor.$img2Url(pos, encodeURI(responseObject.data.path))
|
|
||||||
this.$message.success('图片上传成功!')
|
|
||||||
} else {
|
|
||||||
this.$message.error('图片上传失败:' + responseObject.message)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
handleShowSheetSetting() {
|
handleShowSheetSetting() {
|
||||||
this.sheetSettingVisible = true
|
this.sheetSettingVisible = true
|
||||||
},
|
},
|
||||||
|
@ -244,6 +220,9 @@ export default {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onContentChange(val) {
|
||||||
|
this.sheetToStage.originalContent = val
|
||||||
|
},
|
||||||
onSheetSettingsClose() {
|
onSheetSettingsClose() {
|
||||||
this.sheetSettingVisible = false
|
this.sheetSettingVisible = false
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue