1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
| <template> <div type="flex" justify="space-between" class="edit-main"> <mavon-editor v-show="document.type === 'markdown'" ref="armd" v-model="document.content" :toolbars="mdToolbars" :box-shadow="false" class="mavon-editor" @imgAdd="$imgAdd" /> <div v-show="document.type === 'html'" class="wang-editor"> <div :id="editorId + 'toobar'" class="toolbar" /> <div :id="editorId + 'text'" class="text" /> </div> </div> </template>
<script> import Vue from 'vue' import mavonEditor from 'mavon-editor' import 'mavon-editor/dist/css/index.css' import E from 'wangeditor' import { uploadImg } from '@/api/monitor/guide'
Vue.use(mavonEditor) export default { name: 'Mavon', props: { document: { type: Object, default: () => { return { content: '', type: '' } } }, editorId: 'wang-editor-' + (Math.random() * 1000).toFixed(0), editor: undefined, }, data() { return { mdToolbars: { bold: true, italic: true, header: true, underline: true, strikethrough: true, mark: true, superscript: true, subscript: true, quote: true, ol: true, ul: true, link: true, imagelink: true, code: true, table: true, fullscreen: true, readmodel: true, htmlcode: true, help: true, undo: true, redo: true, trash: true, navigation: true, alignleft: true, aligncenter: true, alignright: true, subfield: true, preview: true } } }, methods: { $imgAdd(pos, $file) { var formdata = new FormData() formdata.append('file', $file) uploadImg(formdata).then(res => {
this.$refs.armd.$img2Url(pos, res.data) }) },
wangEditorInit() { this.editor = new E( '#' + this.editorId + 'toobar', '#' + this.editorId + 'text' ) this.editor.config.onchangeTimeout = 500 this.editor.config.onchange = content => { if (this.document.type === 'html') { this.document.content = content } }
const toolbars = [ 'head', 'bold', 'fontSize', 'fontName', 'italic', 'underline', 'strikeThrough', 'indent', 'lineHeight', 'foreColor', 'backColor', 'link', 'list', 'justify', 'quote', 'image', 'table', 'code', 'splitLine', 'undo', 'redo' ] this.editor.config.menus = toolbars this.editor.config.focus = true this.editor.config.uploadFileName = 'file' this.editor.config.uploadImgServer = '/app/oss/image/upload' this.editor.config.zIndex = 1 this.editor.config.border = 0 this.editor.config.placeholder = '开始编辑...' this.editor.config.menuTooltipPosition = 'down' this.editor.config.uploadImgHooks = { customInsert: function (insertImgFn, result) { if (result.success) { insertImgFn(result.data) } } } this.editor.create() },
setHtmlContent() { if (this.document.type === 'html') { this.editor.txt.html(this.document.content) } }, }, watch: { }, mounted() { } } </script>
<style lang="less" scoped> .edit-main { height: calc(100% - 63px); } .wang-editor { .toolbar { height: 41px; min-width: 860px; width: 100%; border-bottom: 1px solid #f2f6fc; } .text { height: calc(100vh - 110px); @media screen and (max-width: 1000px) { .w-e-text { padding: 0 20px; } } @media screen and (min-width: 1000px) { .w-e-text { padding: 0 calc((100vw - 1000px) / 2); } } } } .mavon-editor { height: 100%; } </style>
|