提交 11a2a4dd 编写于 作者: Q qiang

fix: editor quill import

上级 6065f96a
...@@ -13,9 +13,6 @@ import { ...@@ -13,9 +13,6 @@ import {
import HTMLParser from 'uni-helpers/html-parser' import HTMLParser from 'uni-helpers/html-parser'
import * as formats from './formats' import * as formats from './formats'
let Quill
let ImageResize
export default { export default {
name: 'Editor', name: 'Editor',
mixins: [subscriber, emitter, keyboard], mixins: [subscriber, emitter, keyboard],
...@@ -80,11 +77,8 @@ export default { ...@@ -80,11 +77,8 @@ export default {
imageResizeModules.push('Resize') imageResizeModules.push('Resize')
} }
this.loadQuill(() => { this.loadQuill(() => {
Quill = window.Quill
if (imageResizeModules.length) { if (imageResizeModules.length) {
this.loadImageResizeModule(() => { this.loadImageResizeModule(() => {
ImageResize = window.ImageResize
Quill.register('modules/ImageResize', ImageResize.default)
this.initQuill(imageResizeModules) this.initQuill(imageResizeModules)
}) })
} else { } else {
...@@ -99,6 +93,7 @@ export default { ...@@ -99,6 +93,7 @@ export default {
}) { }) {
const { options, callbackId } = data const { options, callbackId } = data
const quill = this.quill const quill = this.quill
const Quill = window.Quill
let res let res
let range let range
let errMsg let errMsg
...@@ -204,19 +199,19 @@ export default { ...@@ -204,19 +199,19 @@ export default {
} }
}, },
loadQuill (callback) { loadQuill (callback) {
if (typeof Quill === 'function') { if (typeof window.Quill === 'function') {
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback() callback()
} }
return return
} }
let script = document.createElement('script') let script = document.createElement('script')
script.src = 'https://unpkg.com/quill@1.3.6/dist/quill.min.js' script.src = 'https://unpkg.com/quill@1.3.7/dist/quill.min.js'
document.body.appendChild(script) document.body.appendChild(script)
script.onload = callback script.onload = callback
}, },
loadImageResizeModule (callback) { loadImageResizeModule (callback) {
if (typeof ImageResize === 'function') { if (typeof window.ImageResize === 'function') {
if (typeof callback === 'function') { if (typeof callback === 'function') {
callback() callback()
} }
...@@ -228,6 +223,10 @@ export default { ...@@ -228,6 +223,10 @@ export default {
script.onload = callback script.onload = callback
}, },
initQuill (imageResizeModules) { initQuill (imageResizeModules) {
const Quill = window.Quill
Quill.register('modules/ImageResize', window.ImageResize.default)
formats.register(Quill)
const quill = this.quill = new Quill(this.$el, { const quill = this.quill = new Quill(this.$el, {
toolbar: false, toolbar: false,
readOnly: this.readOnly, readOnly: this.readOnly,
...@@ -238,7 +237,6 @@ export default { ...@@ -238,7 +237,6 @@ export default {
} }
} }
}) })
formats.register(Quill)
const $el = quill.root const $el = quill.root
const events = ['focus', 'blur'] const events = ['focus', 'blur']
events.forEach(name => { events.forEach(name => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册