提交 2c1b2211 编写于 作者: Q qiang

fix: 修复 editor 组件可能重复加载 Quill、QuillImageResize 依赖的问题

上级 27c1137c
......@@ -14,6 +14,7 @@ import {
} from 'uni-mixins'
import HTMLParser from 'uni-helpers/html-parser'
import * as formats from './formats'
import loadScript from './load-script'
export default {
name: 'Editor',
......@@ -78,9 +79,11 @@ export default {
if (this.showImgResize) {
imageResizeModules.push('Resize')
}
this.loadQuill(() => {
const quillSrc = __PLATFORM__ === 'app-plus' ? './__uniappquill.js' : 'https://unpkg.com/quill@1.3.7/dist/quill.min.js'
loadScript(window.Quill, quillSrc, () => {
if (imageResizeModules.length) {
this.loadImageResizeModule(() => {
const imageResizeSrc = __PLATFORM__ === 'app-plus' ? './__uniappquillimageresize.js' : 'https://unpkg.com/quill-image-resize-mp@3.0.1/image-resize.min.js'
loadScript(window.ImageResize, imageResizeSrc, () => {
this.initQuill(imageResizeModules)
})
} else {
......@@ -218,30 +221,6 @@ export default {
}, this.$page.id)
}
},
loadQuill (callback) {
if (typeof window.Quill === 'function') {
if (typeof callback === 'function') {
callback()
}
return
}
const script = document.createElement('script')
script.src = __PLATFORM__ === 'app-plus' ? './__uniappquill.js' : 'https://unpkg.com/quill@1.3.7/dist/quill.min.js'
document.body.appendChild(script)
script.onload = callback
},
loadImageResizeModule (callback) {
if (typeof window.ImageResize === 'function') {
if (typeof callback === 'function') {
callback()
}
return
}
const script = document.createElement('script')
script.src = __PLATFORM__ === 'app-plus' ? './__uniappquillimageresize.js' : 'https://unpkg.com/quill-image-resize-mp@3.0.1/image-resize.min.js'
document.body.appendChild(script)
script.onload = callback
},
initQuill (imageResizeModules) {
const Quill = window.Quill
formats.register(Quill)
......
const scripts = {}
export default function loadScript (globalName, src, callback) {
const globalObject = typeof globalName === 'string' ? window[globalName] : globalName
if (globalObject) {
callback()
return
}
let callbacks = scripts[src]
if (!callbacks) {
callbacks = scripts[src] = []
const script = document.createElement('script')
script.src = src
document.body.appendChild(script)
script.onload = function () {
callbacks.forEach(callback => callback())
delete scripts[src]
}
}
callbacks.push(callback)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册