From 049d00ecd6f6dc5dd4938d2bb33a7e4883573b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E7=95=85?= Date: Thu, 9 Sep 2021 11:37:46 +0800 Subject: [PATCH] add --- .../Tinymce/components/EditorImage.vue | 111 ++++++++ src/components/Tinymce/dynamicLoadScript.js | 59 +++++ src/components/Tinymce/index.vue | 247 ++++++++++++++++++ src/components/Tinymce/plugins.js | 7 + src/components/Tinymce/toolbar.js | 6 + src/views/nested/menu1/index.vue | 30 ++- 6 files changed, 447 insertions(+), 13 deletions(-) create mode 100644 src/components/Tinymce/components/EditorImage.vue create mode 100644 src/components/Tinymce/dynamicLoadScript.js create mode 100644 src/components/Tinymce/index.vue create mode 100644 src/components/Tinymce/plugins.js create mode 100644 src/components/Tinymce/toolbar.js diff --git a/src/components/Tinymce/components/EditorImage.vue b/src/components/Tinymce/components/EditorImage.vue new file mode 100644 index 0000000..07d48e6 --- /dev/null +++ b/src/components/Tinymce/components/EditorImage.vue @@ -0,0 +1,111 @@ + + + + + diff --git a/src/components/Tinymce/dynamicLoadScript.js b/src/components/Tinymce/dynamicLoadScript.js new file mode 100644 index 0000000..185f58d --- /dev/null +++ b/src/components/Tinymce/dynamicLoadScript.js @@ -0,0 +1,59 @@ +let callbacks = [] + +function loadedTinymce() { + // to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2144 + // check is successfully downloaded script + return window.tinymce +} + +const dynamicLoadScript = (src, callback) => { + const existingScript = document.getElementById(src) + const cb = callback || function() {} + + if (!existingScript) { + const script = document.createElement('script') + script.src = src // src url for the third-party library being loaded. + script.id = src + document.body.appendChild(script) + callbacks.push(cb) + const onEnd = 'onload' in script ? stdOnEnd : ieOnEnd + onEnd(script) + } + + if (existingScript && cb) { + if (loadedTinymce()) { + cb(null, existingScript) + } else { + callbacks.push(cb) + } + } + + function stdOnEnd(script) { + script.onload = function() { + // this.onload = null here is necessary + // because even IE9 works not like others + this.onerror = this.onload = null + for (const cb of callbacks) { + cb(null, script) + } + callbacks = null + } + script.onerror = function() { + this.onerror = this.onload = null + cb(new Error('Failed to load ' + src), script) + } + } + + function ieOnEnd(script) { + script.onreadystatechange = function() { + if (this.readyState !== 'complete' && this.readyState !== 'loaded') return + this.onreadystatechange = null + for (const cb of callbacks) { + cb(null, script) // there is no way to catch loading errors in IE8 + } + callbacks = null + } + } +} + +export default dynamicLoadScript diff --git a/src/components/Tinymce/index.vue b/src/components/Tinymce/index.vue new file mode 100644 index 0000000..cb6b91c --- /dev/null +++ b/src/components/Tinymce/index.vue @@ -0,0 +1,247 @@ +