import{d as p,E as r,af as u,c as e,ae as h,x as f,l as d,ag as n,a as g}from"./vendor.9f3c6e4d.js";import{i as m}from"./index.f892c01e.js";import{r as y}from"./index.1f84bfe1.js";const b="_colUpload_or6a6_1",U="_uploadSection_or6a6_4",S="_uploadFile_or6a6_14",x="_fileUpload_or6a6_28",_="_uploadClass_or6a6_43";var a={colUpload:b,uploadSection:U,uploadFile:S,fileUpload:x,uploadClass:_},C=p({name:"col-upload",props:{modelValue:{type:String,default:""},uploadType:{type:String,default:"image"},disabled:{type:Boolean,default:!1},bucket:{type:String,default:"daya"},size:{type:Number,default:5},accept:{type:String,default:".png,.jpg,.jpeg"},tips:{type:String,default:"\u8BF7\u4E0A\u4F20\u56FE\u7247"},extraTips:{type:String,default:"\u56FE\u7247\u6700\u5927\u4E0D\u80FD\u8D85\u8FC75MB"},onChange:{type:Function,default:()=>{}}},data(){return{ossUploadUrl:"https://ks3-cn-beijing.ksyuncs.com/"+this.bucket,dataObj:{policy:"",signature:"",key:"",KSSAccessKeyId:"",acl:"public-read",name:""},fileList:[],loading:null}},methods:{handleSuccess(){var s;(s=this.loading)==null||s.close();let l=this.ossUploadUrl+"/"+this.dataObj.key;console.log(l),this.$emit("update:modelValue",l),this.onChange(l)},handleRemove(){console.log("remove")},handleChange(){console.log("handleChange")},handleProgress(){console.log("handleProgress")},handleError(){var l;(l=this.loading)==null||l.close()},async beforeUpload(l){console.log(l);let s=!0;if(this.size&&(s=l.size/1024/1024<this.size,!s))return r.error(`\u6587\u4EF6\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC7${this.size}M!`),!1;this.loading=u.service({target:this.$refs.uploadDom,lock:!0,fullscreen:!1,text:"\u4E0A\u4F20\u4E2D...",background:"rgba(0, 0, 0, 0.7)"}),console.log(this.loading);try{let t=l.name.replaceAll(" ","_"),i=new Date().getTime()+t,c={filename:t,bucketName:this.bucket,postData:{filename:t,acl:"public-read",key:i,unknowValueField:[]}};const{data:o}=await y.post("/api-website/getUploadSign",{data:c});this.dataObj={policy:o.policy,signature:o.signature,key:i,KSSAccessKeyId:o.kssAccessKeyId,acl:"public-read",name:t}}catch{this.loading.close()}},fileName(l=""){return l.split("/").pop()},handleExceed(){}},render(){return e("div",{class:[a.colUpload,"w-full"]},[e(h,{disabled:this.disabled,action:this.ossUploadUrl,data:this.dataObj,onSuccess:this.handleSuccess,onRemove:this.handleRemove,onChange:this.handleChange,onProgress:this.handleProgress,onError:this.handleError,fileList:this.fileList,showFileList:!1,accept:this.accept,beforeUpload:this.beforeUpload,onExceed:this.handleExceed,ref:"uploadRef",class:this.uploadType==="file"?a.fileUpload:"",style:{lineHeight:"0"}},{default:()=>[e("div",{ref:"uploadDom",class:[a.uploadClass,"w-full"],style:{height:this.uploadType==="image"?"85px":"48px"}},[this.modelValue?this.uploadType==="image"?e(f,{src:this.modelValue,fit:"cover",class:a.uploadSection},null):e("div",{class:a.uploadFile},[e(d,null,{default:()=>[e(n,null,null)]}),e("span",{class:"whitespace-nowrap overflow-hidden text-ellipsis",style:{lineHeight:"1.2"}},[this.fileName(this.modelValue)])]):this.uploadType==="image"?e("div",{class:[a.uploadSection,"flex items-center flex-col justify-center"]},[e("img",{src:m,class:"w-8 h-7 mb-3"},null),e("p",null,[this.tips])]):e("div",{class:a.uploadFile},[e(d,null,{default:()=>[e(n,null,null)]}),g("\u4E0A\u4F20\u6587\u4EF6")])])]}),e("p",{class:"text-3 text-[#999999] leading-6 pt-1"},[this.extraTips])])}});export{C};
