Editor.442f558b.js 3.4 KB

1
  1. import{aw as c,o as l,h}from"./index.7e08ba81.js";class u{constructor(){this.listeners={}}on(e,i){this.listeners[e]===void 0&&(this.listeners[e]=[]),this.listeners[e].push(i)}emit(e){this.listeners[e]&&this.listeners[e].forEach(i=>i())}}const f={name:"vueEditor3",data(){return{id:"vuEditor3_"+Math.round(Math.random()*100),editor:null,defaultConfig:{UEDITOR_HOME_URL:"../ueditor/",enableAutoSave:!1}}},props:{modelValue:{type:String,default:"\u6682\u65E0\u6570\u636E"},config:{type:Object,default:function(){return{}}},configPath:{type:String,default:"/ueditor/config/ueditor.config.js"},init:{type:Function,default:function(){return()=>{}}},destroy:Boolean},computed:{mixedConfig(){return Object.assign({},this.defaultConfig,this.config)}},methods:{registerButton:({name:t,icon:e,tip:i,handler:d,UE:s=window.UE})=>{s.registerUI(t,(o,n)=>{o.registerCommand(n,{execCommand:()=>{d(o,n)}});const r=new s.ui.Button({name:n,title:i,cssRules:`background-image: url(${e}) !important;background-size: cover;`,onclick(){o.execCommand(n)}});return o.addListener("selectionchange",()=>{const a=o.queryCommandState(n);a===-1?(r.setDisabled(!0),r.setChecked(!1)):(r.setDisabled(!1),r.setChecked(a))}),r})},_beforeInitEditor(t){!!window.UE&&!!window.UEDITOR_CONFIG&&Object.keys(window.UEDITOR_CONFIG).length!==0&&!!window.UE.getEditor?this._initEditor(t):this._loadScripts().then(()=>this._initEditor(t))},_initEditor(t){this.$nextTick(()=>{this.init(),this.editor=window.UE.getEditor(this.id,this.mixedConfig),this.editor.addListener("ready",()=>{this.$emit("ready",this.editor),this.editor.setContent(t),this.editor.execCommand("serverparam",function(){return{auth_token:localStorage.getItem("token")}}),this.editor.queryCommandValue("serverparam"),this.editor.addListener("contentChange",()=>{setTimeout(()=>{this.$emit("update:modelValue",this.editor.getContent()),this.$emit("puretxt",this.editor.getContentTxt())},100)})})})},_loadScripts(){return window.loadEnv?new Promise(t=>{window.loadEnv.on("scriptsLoaded",function(){t()})}):(window.loadEnv=new u,new Promise(t=>{this._loadConfig().then(()=>this._loadCore()).then(()=>{window.loadEnv.emit("scriptsLoaded"),t()})}))},_loadConfig(){return new Promise(t=>{if(!!window.UE&&!!window.UEDITOR_CONFIG&&Object.keys(window.UEDITOR_CONFIG).length!==0){t();return}const e=document.createElement("script");e.type="text/javascript",e.src=this.configPath,document.getElementsByTagName("head")[0].appendChild(e),e.onload=function(){!!window.UE&&!!window.UEDITOR_CONFIG&&Object.keys(window.UEDITOR_CONFIG).length!==0?t():console.error("UE\u914D\u7F6E\u6587\u4EF6\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84\u662F\u5426\u6B63\u786E\u3002")}})},_loadCore(){return new Promise(t=>{if(!!window.UE&&!!window.UE.getEditor)return t();const e=document.createElement("script");e.type="text/javascript",e.src=this.mixedConfig.UEDITOR_HOME_URL+"ueditor.all.js",document.getElementsByTagName("head")[0].appendChild(e),e.onload=function(){!!window.UE&&!!window.UE.getEditor&&t()}})},_setContent(t){t===this.editor.getContent()||this.editor.setContent(t)}},beforeUnmount(){this.destroy&&this.editor&&this.editor.destroy&&(this.editor.destroy(),this.editor=null)},watch:{modelValue:{handler(t){this.editor?this._setContent(t):this._beforeInitEditor(t)},immediate:!0}}},w=["id"];function m(t,e,i,d,s,o){return l(),h("div",{id:s.id,class:"editor"},null,8,w)}var E=c(f,[["render",m],["__scopeId","data-v-6e7e63c5"]]);export{E as U};