1 |
- import{_ as c}from"./entry/index-C7JiT1GB.js";import{Z as l,_ as h}from"./vue-ByATgq5d.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:"暂无数据"},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()}})},_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}}},m=["id"];function w(t,e,i,d,s,o){return l(),h("div",{id:s.id,class:"editor"},null,8,m)}const p=c(f,[["render",w],["__scopeId","data-v-dc239293"]]);export{p as U};
|