"use strict";const t=require("vue"),a=require("../Shared/base-iCmnU-fv.js"),B=require("../Shared/Index.vue_vue_type_script_setup_true_lang-SO7WBNgE.js"),g=require("../Element/ClButton.cjs"),f=require("../Shared/Index.vue_vue_type_script_setup_true_lang-BSTGdmJD.js"),k=require("../Shared/Index.vue_vue_type_script_setup_true_lang-D5cJAhwe.js"),E={class:"box-flex"},_=t.defineComponent({name:"ClCropperPreview",__name:"Index",props:{className:String,previewImageUrl:String,coverImageUrl:String,width:{type:Number,default:400},height:{type:Number,default:400},widthPreview:Number,heightPreview:Number,previewShape:{type:String,default:"square"},isCenterBox:{type:Boolean,default:!0},isShowUploadBtn:{type:Boolean,default:!0},getCropperImageUrl:Function,saveImageBase64:Function},emits:["onInitCoverImage"],setup(l,{expose:u,emit:v}){const i=l,C=v,s=t.ref(null),n=t.reactive({isEmptyPrevieUrl:!1,isEmptyCoverUrl:!1,isInitCover:!1,isAgainCropper:!1,coverImageUrlOriginal:""}),h=t.computed(()=>{const{width:r,widthPreview:e}=i;let o;return e&&!a.CommonBase.isEmpty(e)?o=e:o=r,o}),I=t.computed(()=>{const{height:r,heightPreview:e}=i;let o;return e&&!a.CommonBase.isEmpty(e)?o=e:o=r,o}),d=t.computed(()=>{const{className:r}=i,e={"panel-cropperPreview":!0};return r&&!a.CommonBase.isEmpty(r)&&r.split(" ").forEach(o=>{a.CommonBase.isEmpty(o)||(e[o]=!0)}),e}),m=()=>{const{previewImageUrl:r}=i,e=a.CommonBase.isEmpty(r);n.isEmptyPrevieUrl=e,n.isAgainCropper=e},p=()=>{const{coverImageUrl:r}=i,e=a.CommonBase.isEmpty(r);n.isEmptyCoverUrl=e,n.coverImageUrlOriginal=e?"":r},w=()=>{m(),p()};t.onMounted(()=>{t.nextTick(()=>{w()})}),t.watch(()=>i.previewImageUrl,()=>{m()}),t.watch(()=>i.coverImageUrl,()=>{p()});const U=r=>{r&&C("onInitCoverImage")},y=(r,e)=>{a.CommonBase.getBase64ByFile(r).then(o=>{n.isAgainCropper=!0,n.coverImageUrlOriginal=o})};return u({getValue:async()=>s.value?await s.value.getImageBase64().then(e=>e):"",getCropperUrl:async r=>{let e="";if(s.value&&i.getCropperImageUrl)e=await i.getCropperImageUrl(s.value,r);else{const{previewImageUrl:o,coverImageUrl:c}=i;e=a.CommonBase.isEmpty(o)?c:o}return e},getCoverUrlOriginal:async r=>{let e="";const{coverImageUrlOriginal:o}=n;if(o.substring(0,5)==="data:"&&i.saveImageBase64){const c=await i.saveImageBase64(o,r);e=c.success?c.imageUrl:""}else/^(http|https):\/\/[^\s]+$/.test(o)&&(e=o);return e}}),(r,e)=>(t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass(d.value)},[t.createElementVNode("div",E,[n.isEmptyPrevieUrl?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock(t.Fragment,{key:0},[n.isAgainCropper?(t.openBlock(),t.createBlock(g,{key:0,className:"m-b-5 w-120 m-r-10",icon:"clIconFont clIcon-reply",label:"返回",color:"transparent",onOnClick:e[0]||(e[0]=o=>n.isAgainCropper=!1)})):n.isEmptyCoverUrl?t.createCommentVNode("",!0):(t.openBlock(),t.createBlock(g,{key:1,className:"m-b-5 w-120",icon:"clIconFont clIcon-cropper",label:"重新裁切",color:"transparent",onOnClick:e[1]||(e[1]=o=>n.isAgainCropper=!0)}))],64)),l.isShowUploadBtn&&(n.isAgainCropper||n.isEmptyCoverUrl)?(t.openBlock(),t.createBlock(f._sfc_main,{key:1,className:"m-b-5",theme:"button",checkFormat:"jpg,png",buttonIcon:"clIconFont clIcon-upload-cloud",buttonColor:"white",buttonLabel:"选择图片",isShowUploadResult:!1,isShowUploadIng:!1,onOnChange:y})):t.createCommentVNode("",!0)]),!n.isEmptyPrevieUrl&&!n.isAgainCropper?(t.openBlock(),t.createBlock(k._sfc_main,{key:0,type:"image",list:[{value:l.previewImageUrl||"",imgUrl:"",label:""}],width:h.value,height:I.value},null,8,["list","width","height"])):n.coverImageUrlOriginal.length>0?(t.openBlock(),t.createBlock(B._sfc_main,{key:1,ref_key:"refElCropper",ref:s,previewShape:l.previewShape,isCenterBox:l.isCenterBox,src:n.coverImageUrlOriginal,width:l.width,height:l.height,isModal:!1,isShowUpload:!1,onOnImgLoad:U},null,8,["previewShape","isCenterBox","src","width","height"])):t.createCommentVNode("",!0)],2))}});module.exports=_;
//# sourceMappingURL=ClCropperPreview.cjs.map
