index.871602d4.js 3.4 KB

1
  1. import{d as p,E as r,ai as u,c as a,ah as h,x as g,l as d,aj as n,a as f}from"./vendor.af53403a.js";import{o as y,g as m,i as b}from"./index.58649a4a.js";const U="_colUpload_or6a6_1",S="_uploadSection_or6a6_4",k="_uploadFile_or6a6_14",x="_fileUpload_or6a6_28",_="_uploadClass_or6a6_43";var s={colUpload:U,uploadSection:S,uploadFile:k,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://${this.bucket}.ks3-cn-beijing.ksyuncs.com/`,dataObj:{policy:"",signature:"",key:"",KSSAccessKeyId:"",acl:"public-read",name:""},fileList:[],loading:null}},methods:{async handleSuccess(e){var t;try{const o={policy:e.data.policy,signature:e.data.signature,key:e.data.key,KSSAccessKeyId:e.data.kssAccessKeyId,acl:"public-read",name:e.data.key,file:e.file},l=await y(this.ossUploadUrl,o);this.$emit("update:modelValue",l),this.onChange(l)}catch{}(t=this.loading)==null||t.close()},handleRemove(){console.log("remove")},handleChange(){console.log("handleChange")},handleProgress(){console.log("handleProgress")},handleError(){var e;(e=this.loading)==null||e.close()},async beforeUpload(e){console.log(e);let t=!0;if(this.size&&(t=e.size/1024/1024<this.size,!t))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{const o=e.name.replaceAll(" ","_"),l=new Date().getTime()+o,c={filename:l,bucketName:this.bucket,postData:{filename:l,acl:"public-read",key:l}},{data:i}=await m(c);this.dataObj={policy:i.policy,signature:i.signature,key:l,KSSAccessKeyId:i.kssAccessKeyId,acl:"public-read",name:l}}catch{this.loading.close()}},fileName(e=""){return e.split("/").pop()},handleExceed(){}},render(){return a("div",{class:[s.colUpload,"w-full"]},[a(h,{disabled:this.disabled,action:this.ossUploadUrl,data:this.dataObj,httpRequest: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"?s.fileUpload:"",style:{lineHeight:"0"}},{default:()=>[a("div",{ref:"uploadDom",class:[s.uploadClass,"w-full"],style:{height:this.uploadType==="image"?"85px":"48px"}},[this.modelValue?this.uploadType==="image"?a(g,{src:this.modelValue,fit:"cover",class:s.uploadSection},null):a("div",{class:s.uploadFile},[a(d,null,{default:()=>[a(n,null,null)]}),a("span",{class:"whitespace-nowrap overflow-hidden text-ellipsis",style:{lineHeight:"1.2"}},[this.fileName(this.modelValue)])]):this.uploadType==="image"?a("div",{class:[s.uploadSection,"flex items-center flex-col justify-center"]},[a("img",{src:b,class:"w-8 h-7 mb-3"},null),a("p",null,[this.tips])]):a("div",{class:s.uploadFile},[a(d,null,{default:()=>[a(n,null,null)]}),f("\u4E0A\u4F20\u6587\u4EF6")])])]}),a("p",{class:"text-3 text-[#999999] leading-6 pt-1"},[this.extraTips])])}});export{C};