var e=Object.defineProperty,t=Object.defineProperties,i=Object.getOwnPropertyDescriptors,s=Object.getOwnPropertySymbols,l=Object.prototype.hasOwnProperty,o=Object.prototype.propertyIsEnumerable,r=(t,i,s)=>i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[i]=s,a=(e,t)=>{for(var i in t||(t={}))l.call(t,i)&&r(e,i,t[i]);if(s)for(var i of s(t))o.call(t,i)&&r(e,i,t[i]);return e};import{T as n,V as d,W as u,q as h,X as c,Y as p,o as f,c as m,w as y,d as g,r as b,v as F,a as x,Z as k,f as _,b as w,F as v,u as P,g as I,i as S,_ as T,x as $,t as O,l as C,$ as L,h as M,A as j}from"./index.e9f016fd.js";import{S as E}from"./uni-cloud.es.aef258d0.js";import{_ as U}from"./plugin-vue_export-helper.21dcd24c.js";const V="chooseAndUploadFile:fail";function B(e,t){return e.tempFiles.forEach(((e,i)=>{e.name||(e.name=e.path.substring(e.path.lastIndexOf("/")+1)),t&&(e.fileType=t),e.cloudPath=Date.now()+"_"+i+e.name.substring(e.name.lastIndexOf("."))})),e.tempFilePaths||(e.tempFilePaths=e.tempFiles.map((e=>e.path))),e}function D(e,t=5,i){const s=(e=JSON.parse(JSON.stringify(e))).length;let l=0,o=this;return new Promise((r=>{for(;l=s)return void(!e.find((e=>!e.url&&!e.errMsg))&&r(e));const n=e[t],d=o.files.findIndex((e=>e.uuid===n.uuid));n.url="",delete n.errMsg,E.uploadFile({filePath:n.path,cloudPath:n.cloudPath,fileType:n.fileType,onUploadProgress:e=>{e.index=d,i&&i(e)}}).then((e=>{n.url=e.fileID,n.index=d,t{n.errMsg=e.errMsg||e.message,n.index=d,t{if(t){const i=t(e);if(void 0!==i)return Promise.resolve(i).then((t=>void 0===t?e:t))}return e})).then((e=>!1===e?{errMsg:"chooseAndUploadFile:ok",tempFilePaths:[],tempFiles:[]}:e))}function z(e={type:"all"}){return"image"===e.type?A(function(e){const{count:t,sizeType:i=["original","compressed"],sourceType:s=["album","camera"],extension:l}=e;return new Promise(((e,o)=>{n({count:t,sizeType:i,sourceType:s,extension:l,success(t){e(B(t,"image"))},fail(e){o({errMsg:e.errMsg.replace("chooseImage:fail",V)})}})}))}(e),e):"video"===e.type?A(function(e){const{camera:t,compressed:i,maxDuration:s,sourceType:l=["album","camera"],extension:o}=e;return new Promise(((e,r)=>{d({camera:t,compressed:i,maxDuration:s,sourceType:l,extension:o,success(t){const{tempFilePath:i,duration:s,size:l,height:o,width:r}=t;e(B({errMsg:"chooseVideo:ok",tempFilePaths:[i],tempFiles:[{name:t.tempFile&&t.tempFile.name||"",path:i,size:l,type:t.tempFile&&t.tempFile.type||"",width:r,height:o,duration:s,fileType:"video",cloudPath:""}]},"video"))},fail(e){r({errMsg:e.errMsg.replace("chooseVideo:fail",V)})}})}))}(e),e):A(function(e){const{count:t,extension:i}=e;return new Promise(((e,s)=>{let l=u;if("undefined"!=typeof wx&&"function"==typeof wx.chooseMessageFile&&(l=wx.chooseMessageFile),"function"!=typeof l)return s({errMsg:V+" 请指定 type 类型,该平台仅支持选择 image 或 video。"});l({type:"all",count:t,extension:i,success(t){e(B(t))},fail(e){s({errMsg:e.errMsg.replace("chooseFile:fail",V)})}})}))}(e),e)}const N=e=>{const t=e.lastIndexOf("."),i=e.length;return{name:e.substring(0,t),ext:e.substring(t+1,i)}},R=e=>{if(Array.isArray(e))return e;return e.replace(/(\[|\])/g,"").split(",")},q=async(e,t="image")=>{const i=N(e.name).ext.toLowerCase();let s={name:e.name,uuid:e.uuid,extname:i||"",cloudPath:e.cloudPath,fileType:e.fileType,url:e.path||e.path,size:e.size,image:{},path:e.path,video:{}};if("image"===t){const t=await(l=e.path,new Promise(((e,t)=>{c({src:l,success(t){e(t)},fail(e){t(e)}})})));delete s.video,s.image.width=t.width,s.image.height=t.height,s.image.location=t.path}else delete s.image;var l;return s};var J=U({name:"uniFilePicker",components:{uploadImage:U({name:"uploadImage",emits:["uploadFiles","choose","delFile"],props:{filesList:{type:Array,default:()=>[]},disabled:{type:Boolean,default:!1},disablePreview:{type:Boolean,default:!1},limit:{type:[Number,String],default:9},imageStyles:{type:Object,default:()=>({width:"auto",height:"auto",border:{}})},delIcon:{type:Boolean,default:!0},readonly:{type:Boolean,default:!1}},computed:{styles(){return Object.assign({width:"auto",height:"auto",border:{}},this.imageStyles)},boxStyle(){const{width:e="auto",height:t="auto"}=this.styles;let i={};"auto"===t?"auto"!==e?(i.height=this.value2px(e),i["padding-top"]=0):i.height=0:(i.height=this.value2px(t),i["padding-top"]=0),i.width="auto"===e?"auto"!==t?this.value2px(t):"33.3%":this.value2px(e);let s="";for(let l in i)s+=`${l}:${i[l]};`;return s},borderStyle(){let{border:e}=this.styles,t={};if("boolean"==typeof e)t.border=e?"1px #eee solid":"none";else{let i=e&&e.width||1;i=this.value2px(i);let s=e&&e.radius||3;s=this.value2px(s),t={"border-width":i,"border-style":e&&e.style||"solid","border-color":e&&e.color||"#eee","border-radius":s}}let i="";for(let s in t)i+=`${s}:${t[s]};`;return i}},methods:{uploadFiles(e,t){this.$emit("uploadFiles",e)},choose(){this.$emit("choose")},delFile(e){this.$emit("delFile",e)},prviewImage(e,t){let i=[];1===Number(this.limit)&&this.disablePreview&&!this.disabled&&this.$emit("choose"),this.disablePreview||(this.filesList.forEach((e=>{i.push(e.url)})),p({urls:i,current:t}))},value2px:e=>("number"==typeof e?e+="px":-1===e.indexOf("%")&&(e=-1!==e.indexOf("px")?e:e+"px"),e)}},[["render",function(e,t,i,s,l,o){const r=I,a=S,n=T;return f(),m(a,{class:"uni-file-picker__container"},{default:y((()=>[(f(!0),g(v,null,b(i.filesList,((e,t)=>(f(),m(a,{class:"file-picker__box",key:t,style:F(o.boxStyle)},{default:y((()=>[x(a,{class:"file-picker__box-content",style:F(o.borderStyle)},{default:y((()=>[x(r,{class:"file-image",src:e.url,mode:"aspectFill",onClick:k((i=>o.prviewImage(e,t)),["stop"])},null,8,["src","onClick"]),i.delIcon&&!i.readonly?(f(),m(a,{key:0,class:"icon-del-box",onClick:k((e=>o.delFile(t)),["stop"])},{default:y((()=>[x(a,{class:"icon-del"}),x(a,{class:"icon-del rotate"})])),_:2},1032,["onClick"])):_("",!0),e.progress&&100!==e.progress||0===e.progress?(f(),m(a,{key:1,class:"file-picker__progress"},{default:y((()=>[x(n,{class:"file-picker__progress-item",percent:-1===e.progress?0:e.progress,"stroke-width":"4",backgroundColor:e.errMsg?"#ff5a5f":"#EBEBEB"},null,8,["percent","backgroundColor"])])),_:2},1024)):_("",!0),e.errMsg?(f(),m(a,{key:2,class:"file-picker__mask",onClick:k((i=>o.uploadFiles(e,t)),["stop"])},{default:y((()=>[w(" 点击重试 ")])),_:2},1032,["onClick"])):_("",!0)])),_:2},1032,["style"])])),_:2},1032,["style"])))),128)),i.filesList.length[x(a,{class:"file-picker__box-content is-add",style:F(o.borderStyle),onClick:o.choose},{default:y((()=>[P(e.$slots,"default",{},(()=>[x(a,{class:"icon-add"}),x(a,{class:"icon-add rotate"})]),!0)])),_:3},8,["style","onClick"])])),_:3},8,["style"])):_("",!0)])),_:3})}],["__scopeId","data-v-38a8da1b"]]),uploadFile:U({name:"uploadFile",emits:["uploadFiles","choose","delFile"],props:{filesList:{type:Array,default:()=>[]},delIcon:{type:Boolean,default:!0},limit:{type:[Number,String],default:9},showType:{type:String,default:""},listStyles:{type:Object,default:()=>({border:!0,dividline:!0,borderStyle:{}})},readonly:{type:Boolean,default:!1}},computed:{list(){let e=[];return this.filesList.forEach((t=>{e.push(t)})),e},styles(){return Object.assign({border:!0,dividline:!0,"border-style":{}},this.listStyles)},borderStyle(){let{borderStyle:e,border:t}=this.styles,i={};if(t){let t=e&&e.width||1;t=this.value2px(t);let s=e&&e.radius||5;s=this.value2px(s),i={"border-width":t,"border-style":e&&e.style||"solid","border-color":e&&e.color||"#eee","border-radius":s}}else i.border="none";let s="";for(let l in i)s+=`${l}:${i[l]};`;return s},borderLineStyle(){let e={},{borderStyle:t}=this.styles;if(t&&t.color&&(e["border-color"]=t.color),t&&t.width){let i=t&&t.width||1,s=t&&t.style||0;"number"==typeof i?i+="px":i=i.indexOf("px")?i:i+"px",e["border-width"]=i,"number"==typeof s?s+="px":s=s.indexOf("px")?s:s+"px",e["border-top-style"]=s}let i="";for(let s in e)i+=`${s}:${e[s]};`;return i}},methods:{uploadFiles(e,t){this.$emit("uploadFiles",{item:e,index:t})},choose(){this.$emit("choose")},delFile(e){this.$emit("delFile",e)},value2px:e=>("number"==typeof e?e+="px":e=-1!==e.indexOf("px")?e:e+"px",e)}},[["render",function(e,t,i,s,l,o){const r=S,a=T;return f(),m(r,{class:"uni-file-picker__files"},{default:y((()=>[i.readonly?_("",!0):(f(),m(r,{key:0,class:"files-button",onClick:o.choose},{default:y((()=>[P(e.$slots,"default",{},void 0,!0)])),_:3},8,["onClick"])),o.list.length>0?(f(),m(r,{key:1,class:"uni-file-picker__lists is-text-box",style:F(o.borderStyle)},{default:y((()=>[(f(!0),g(v,null,b(o.list,((e,t)=>(f(),m(r,{class:$(["uni-file-picker__lists-box",{"files-border":0!==t&&o.styles.dividline}]),key:t,style:F(0!==t&&o.styles.dividline&&o.borderLineStyle)},{default:y((()=>[x(r,{class:"uni-file-picker__item"},{default:y((()=>[x(r,{class:"files__name"},{default:y((()=>[w(O(e.name),1)])),_:2},1024),i.delIcon&&!i.readonly?(f(),m(r,{key:0,class:"icon-del-box icon-files",onClick:e=>o.delFile(t)},{default:y((()=>[x(r,{class:"icon-del icon-files"}),x(r,{class:"icon-del rotate"})])),_:2},1032,["onClick"])):_("",!0)])),_:2},1024),e.progress&&100!==e.progress||0===e.progress?(f(),m(r,{key:0,class:"file-picker__progress"},{default:y((()=>[x(a,{class:"file-picker__progress-item",percent:-1===e.progress?0:e.progress,"stroke-width":"4",backgroundColor:e.errMsg?"#ff5a5f":"#EBEBEB"},null,8,["percent","backgroundColor"])])),_:2},1024)):_("",!0),"error"===e.status?(f(),m(r,{key:1,class:"file-picker__mask",onClick:k((i=>o.uploadFiles(e,t)),["stop"])},{default:y((()=>[w(" 点击重试 ")])),_:2},1032,["onClick"])):_("",!0)])),_:2},1032,["class","style"])))),128))])),_:1},8,["style"])):_("",!0)])),_:3})}],["__scopeId","data-v-5b82fdf4"]])},emits:["select","success","fail","progress","delete","update:modelValue","input"],props:{modelValue:{type:[Array,Object],default:()=>[]},disabled:{type:Boolean,default:!1},disablePreview:{type:Boolean,default:!1},delIcon:{type:Boolean,default:!0},autoUpload:{type:Boolean,default:!0},limit:{type:[Number,String],default:9},mode:{type:String,default:"grid"},fileMediatype:{type:String,default:"image"},fileExtname:{type:[Array,String],default:()=>[]},title:{type:String,default:""},listStyles:{type:Object,default:()=>({border:!0,dividline:!0,borderStyle:{}})},imageStyles:{type:Object,default:()=>({width:"auto",height:"auto"})},readonly:{type:Boolean,default:!1},returnType:{type:String,default:"array"},sizeType:{type:Array,default:()=>["original","compressed"]}},data:()=>({files:[],localValue:[]}),watch:{modelValue:{handler(e,t){this.setValue(e,t)},immediate:!0}},computed:{filesList(){let e=[];return this.files.forEach((t=>{e.push(t)})),e},showType(){return"image"===this.fileMediatype?this.mode:"list"},limitLength(){return"object"===this.returnType?1:this.limit?this.limit>=99?99:this.limit:1}},created(){E.config&&E.config.provider||(this.noSpace=!0,E.chooseAndUploadFile=z),this.form=this.getForm("uniForms"),this.formItem=this.getForm("uniFormsItem"),this.form&&this.formItem&&this.formItem.name&&(this.rename=this.formItem.name,this.form.inputChildrens.push(this))},methods:{clearFiles(e){0===e||e?this.files.splice(e,1):(this.files=[],this.$nextTick((()=>{this.setEmit()}))),this.$nextTick((()=>{this.setEmit()}))},upload(){let e=[];this.files.forEach(((t,i)=>{"ready"!==t.status&&"error"!==t.status||e.push(Object.assign({},t))})),this.uploadFiles(e)},async setValue(e,t){const i=async e=>{let t="";return t=e.fileID?e.fileID:e.url,/cloud:\/\/([\w.]+\/?)\S*/.test(t)&&(e.fileID=t,e.url=await this.getTempFileURL(t)),e.url&&(e.path=e.url),e};if("object"===this.returnType)e?await i(e):e={};else{e||(e=[]);for(let t=0;t0?e:[];this.files=[].concat(s)},choose(){this.disabled||(this.files.length>=Number(this.limitLength)&&"grid"!==this.showType&&"array"===this.returnType?h({title:`您最多选择 ${this.limitLength} 个文件`,icon:"none"}):this.chooseFiles())},chooseFiles(){const e=R(this.fileExtname);E.chooseAndUploadFile({type:this.fileMediatype,compressed:!1,sizeType:this.sizeType,extension:e.length>0?e:void 0,count:this.limitLength-this.files.length,onChooseFile:this.chooseFileCallback,onUploadProgress:e=>{this.setProgress(e,e.index)}}).then((e=>{this.setSuccessAndError(e.tempFiles)})).catch((e=>{C("log","at uni_modules/uni-file-picker/components/uni-file-picker/uni-file-picker.vue:362","选择失败",e)}))},async chooseFileCallback(e){const s=R(this.fileExtname);(1===Number(this.limitLength)&&this.disablePreview&&!this.disabled||"object"===this.returnType)&&(this.files=[]);let{filePaths:l,files:o}=((e,t)=>{let i=[],s=[];return t&&0!==t.length?(e.tempFiles.forEach((e=>{const l=N(e.name).ext.toLowerCase();-1!==t.indexOf(l)&&(s.push(e),i.push(e.path))})),s.length!==e.tempFiles.length&&h({title:`当前选择了${e.tempFiles.length}个文件 ,${e.tempFiles.length-s.length} 个文件格式不正确`,icon:"none",duration:5e3}),{filePaths:i,files:s}):{filePaths:i,files:s}})(e,s);s&&s.length>0||(l=e.tempFilePaths,o=e.tempFiles);let r=[];for(let u=0;u{this.setProgress(e,e.index,!0)})).then((e=>{this.setSuccessAndError(e)})).catch((e=>{C("log","at uni_modules/uni-file-picker/components/uni-file-picker/uni-file-picker.vue:427",e)}))},async setSuccessAndError(e,t){let i=[],s=[],l=[],o=[];for(let r=0;re.uuid===t.uuid)):t.index;if(-1===a||!this.files)break;if("request:fail"===t.errMsg)this.files[a].url=t.path,this.files[a].status="error",this.files[a].errMsg=t.errMsg,s.push(this.files[a]),o.push(this.files[a].url);else{this.files[a].errMsg="",this.files[a].fileID=t.url;/cloud:\/\/([\w.]+\/?)\S*/.test(t.url)?this.files[a].url=await this.getTempFileURL(t.url):this.files[a].url=t.url,this.files[a].status="success",this.files[a].progress+=1,i.push(this.files[a]),l.push(this.files[a].fileID)}}i.length>0&&(this.setEmit(),this.$emit("success",{tempFiles:this.backObject(i),tempFilePaths:l})),s.length>0&&this.$emit("fail",{tempFiles:this.backObject(s),tempFilePaths:o})},setProgress(e,t,i){this.files.length;const s=Math.round(100*e.loaded/e.total);let l=t;i||(l=this.files.findIndex((t=>t.uuid===e.tempFile.uuid))),-1!==l&&this.files[l]&&(this.files[l].progress=s-1,this.$emit("progress",{index:l,progress:parseInt(s),tempFile:this.files[l]}))},delFile(e){this.$emit("delete",{tempFile:this.files[e],tempFilePath:this.files[e].url}),this.files.splice(e,1),this.$nextTick((()=>{this.setEmit()}))},getFileExt(e){const t=e.lastIndexOf("."),i=e.length;return{name:e.substring(0,t),ext:e.substring(t+1,i)}},setEmit(){let e=[];"object"===this.returnType?(e=this.backObject(this.files)[0],this.localValue=e||null):(e=this.backObject(this.files),this.localValue||(this.localValue=[]),this.localValue=[...e]),this.$emit("update:modelValue",this.localValue)},backObject(e){let t=[];return e.forEach((e=>{t.push({extname:e.extname,fileType:e.fileType,image:e.image,name:e.name,path:e.path,size:e.size,fileID:e.fileID,url:e.url})})),t},async getTempFileURL(e){e={fileList:[].concat(e)};return(await E.getTempFileURL(e)).fileList[0].tempFileURL||""},getForm(e="uniForms"){let t=this.$parent,i=t.$options.name;for(;i!==e;){if(t=t.$parent,!t)return!1;i=t.$options.name}return t}}},[["render",function(e,t,i,s,l,o){const r=M,a=S,n=L("upload-image"),d=j,u=L("upload-file");return f(),m(a,{class:"uni-file-picker"},{default:y((()=>[i.title?(f(),m(a,{key:0,class:"uni-file-picker__header"},{default:y((()=>[x(r,{class:"file-title"},{default:y((()=>[w(O(i.title),1)])),_:1}),x(r,{class:"file-count"},{default:y((()=>[w(O(o.filesList.length)+"/"+O(o.limitLength),1)])),_:1})])),_:1})):_("",!0),"image"===i.fileMediatype&&"grid"===o.showType?(f(),m(n,{key:1,readonly:i.readonly,"image-styles":i.imageStyles,"files-list":o.filesList,limit:o.limitLength,disablePreview:i.disablePreview,delIcon:i.delIcon,onUploadFiles:o.uploadFiles,onChoose:o.choose,onDelFile:o.delFile},{default:y((()=>[P(e.$slots,"default",{},(()=>[x(a,{class:"is-add"},{default:y((()=>[x(a,{class:"icon-add"}),x(a,{class:"icon-add rotate"})])),_:1})]),!0)])),_:3},8,["readonly","image-styles","files-list","limit","disablePreview","delIcon","onUploadFiles","onChoose","onDelFile"])):_("",!0),"image"!==i.fileMediatype||"grid"!==o.showType?(f(),m(u,{key:2,readonly:i.readonly,"list-styles":i.listStyles,"files-list":o.filesList,showType:o.showType,delIcon:i.delIcon,onUploadFiles:o.uploadFiles,onChoose:o.choose,onDelFile:o.delFile},{default:y((()=>[P(e.$slots,"default",{},(()=>[x(d,{type:"primary",size:"mini"},{default:y((()=>[w("选择文件")])),_:1})]),!0)])),_:3},8,["readonly","list-styles","files-list","showType","delIcon","onUploadFiles","onChoose","onDelFile"])):_("",!0)])),_:3})}],["__scopeId","data-v-5793e686"]]);export{J as _};