| 1 |
- import{a9 as e,aa as t,ab as l,ac as s,A as i,ad as a,_ as o,ae as r,i as u,j as d,k as n,E as p,J as c,K as h,L as m,l as f,q as y,s as g,n as b,R as v,I as w,x,af as F,G as _,t as k,ag as S,v as P,z as I,ah as T,u as C,r as $,c as V,f as A,g as M,m as B,a5 as E,a as O}from"./index-DVmtlnMb.js";import{c as j}from"./index.BeoSXJcF.js";const L={password:/^(?:(?=.*[a-z])(?=.*[A-Z])(?=.*\d)|(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()_+=-])|(?=.*[a-z])(?=.*\d)(?=.*[!@#$%^&*()_+=-])|(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+=-]))[\w!@#$%^&*()+=-]{8,20}$/,email:/^[\w.+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,idNumber:/^[A-Z0-9]{6,18}$/i,mobile:/^\d{6,15}$/,postcode:/^[a-z0-9]{1,15}$/i,address:/^[A-Z0-9\s\-.,/#']+$/i,addressCn:/^[\u4E00-\u9FA5A-Z0-9\s\-·,。、《》()()#]+$/i},D={required:(e,t="blur")=>({required:!0,message:e,trigger:t}),pattern:(e,t,l="blur")=>({pattern:e,message:t,trigger:l}),custom:(e,t="blur")=>({validator:e,trigger:t})},U="chooseAndUploadFile:fail";function z(e,t){return e.tempFiles.forEach((e,l)=>{e.name||(e.name=e.path.substring(e.path.lastIndexOf("/")+1)),t&&(e.fileType=t),e.cloudPath=Date.now()+"_"+l+e.name.substring(e.name.lastIndexOf("."))}),e.tempFilePaths||(e.tempFilePaths=e.tempFiles.map(e=>e.path)),e}function N(t,l=5,s){const i=(t=JSON.parse(JSON.stringify(t))).length;let a=0,o=this;return new Promise(r=>{for(;a<l;)u();function u(){let l=a++;if(l>=i)return void(!t.find(e=>!e.url&&!e.errMsg)&&r(t));const d=t[l],n=o.files.findIndex(e=>e.uuid===d.uuid);d.url="",delete d.errMsg,e.uploadFile({filePath:d.path,cloudPath:d.cloudPath,fileType:d.fileType,onUploadProgress:e=>{e.index=n,s&&s(e)}}).then(e=>{d.url=e.fileID,d.index=n,l<i&&u()}).catch(e=>{d.errMsg=e.errMsg||e.message,d.index=n,l<i&&u()})}})}function R(e,{onChooseFile:t,onUploadProgress:l}){return e.then(e=>{if(t){const l=t(e);if(void 0!==l)return Promise.resolve(l).then(t=>void 0===t?e:t)}return e}).then(e=>!1===e?{errMsg:"chooseAndUploadFile:ok",tempFilePaths:[],tempFiles:[]}:e)}function H(e={type:"all"}){return"image"===e.type?R(function(e){const{count:l,sizeType:s=["original","compressed"],sourceType:i,extension:a}=e;return new Promise((e,o)=>{t({count:l,sizeType:s,sourceType:i,extension:a,success(t){e(z(t,"image"))},fail(e){o({errMsg:e.errMsg.replace("chooseImage:fail",U)})}})})}(e),e):"video"===e.type?R(function(e){const{count:t,camera:s,compressed:i,maxDuration:a,sourceType:o,extension:r}=e;return new Promise((e,t)=>{l({camera:s,compressed:i,maxDuration:a,sourceType:o,extension:r,success(t){const{tempFilePath:l,duration:s,size:i,height:a,width:o}=t;e(z({errMsg:"chooseVideo:ok",tempFilePaths:[l],tempFiles:[{name:t.tempFile&&t.tempFile.name||"",path:l,size:i,type:t.tempFile&&t.tempFile.type||"",width:o,height:a,duration:s,fileType:"video",cloudPath:""}]},"video"))},fail(e){t({errMsg:e.errMsg.replace("chooseVideo:fail",U)})}})})}(e),e):R(function(e){const{count:t,extension:l}=e;return new Promise((e,i)=>{let a=s;if("undefined"!=typeof wx&&"function"==typeof wx.chooseMessageFile&&(a=wx.chooseMessageFile),"function"!=typeof a)return i({errMsg:U+" 请指定 type 类型,该平台仅支持选择 image 或 video。"});a({type:"all",count:t,extension:l,success(t){e(z(t))},fail(e){i({errMsg:e.errMsg.replace("chooseFile:fail",U)})}})})}(e),e)}const Z=e=>{const t=e.lastIndexOf("."),l=e.length;return{name:e.substring(0,t),ext:e.substring(t+1,l)}},q=e=>{if(Array.isArray(e))return e;return e.replace(/(\[|\])/g,"").split(",")},G=async(e,t="image")=>{const l=Z(e.name).ext.toLowerCase();let s={name:e.name,uuid:e.uuid,extname:l||"",cloudPath:e.cloudPath,fileType:e.fileType,thumbTempFilePath:e.thumbTempFilePath,url:e.path||e.path,size:e.size,image:{},path:e.path,video:{}};if("image"===t){const t=await(i=e.path,new Promise((e,t)=>{a({src:i,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 i;return s};const W=o({name:"uniFilePicker",components:{uploadImage:o({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 l={};"auto"===t?"auto"!==e?(l.height=this.value2px(e),l["padding-top"]=0):l.height=0:(l.height=this.value2px(t),l["padding-top"]=0),l.width="auto"===e?"auto"!==t?this.value2px(t):"33.3%":this.value2px(e);let s="";for(let i in l)s+=`${i}:${l[i]};`;return s},borderStyle(){let{border:e}=this.styles,t={};if("boolean"==typeof e)t.border=e?"1px #eee solid":"none";else{let l=e&&e.width||1;l=this.value2px(l);let s=e&&e.radius||3;s=this.value2px(s),t={"border-width":l,"border-style":e&&e.style||"solid","border-color":e&&e.color||"#eee","border-radius":s}}let l="";for(let s in t)l+=`${s}:${t[s]};`;return l}},methods:{uploadFiles(e,t){this.$emit("uploadFiles",e)},choose(){this.readonly||this.$emit("choose")},delFile(e){this.readonly||this.$emit("delFile",e)},prviewImage(e,t){if(this.readonly)return;let l=[];1===Number(this.limit)&&this.disablePreview&&!this.disabled&&this.$emit("choose"),this.disablePreview||(this.filesList.forEach(e=>{l.push(e.url)}),r({urls:l,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,l,s,i,a){const o=w,r=x,_=F;return u(),d(r,{class:"uni-file-picker__container"},{default:n(()=>[(u(!0),p(c,null,h(l.filesList,(e,t)=>(u(),d(r,{class:"file-picker__box",key:t,style:m(a.boxStyle)},{default:n(()=>[f(r,{class:"file-picker__box-content",style:m(a.borderStyle)},{default:n(()=>[f(o,{class:"file-image",src:e.url,mode:"aspectFill",onClick:y(l=>a.prviewImage(e,t),["stop"])},null,8,["src","onClick"]),l.delIcon&&!l.readonly?(u(),d(r,{key:0,class:"icon-del-box",onClick:y(e=>a.delFile(t),["stop"])},{default:n(()=>[f(r,{class:"icon-del"}),f(r,{class:"icon-del rotate"})]),_:2},1032,["onClick"])):g("",!0),e.progress&&100!==e.progress||0===e.progress?(u(),d(r,{key:1,class:"file-picker__progress"},{default:n(()=>[f(_,{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)):g("",!0),e.errMsg?(u(),d(r,{key:2,class:"file-picker__mask",onClick:y(l=>a.uploadFiles(e,t),["stop"])},{default:n(()=>[b(" 点击重试 ")]),_:2},1032,["onClick"])):g("",!0)]),_:2},1032,["style"])]),_:2},1032,["style"]))),128)),l.filesList.length<l.limit?(u(),d(r,{key:0,class:"file-picker__box",style:m(a.boxStyle)},{default:n(()=>[f(r,{class:"file-picker__box-content is-add",style:m(a.borderStyle),onClick:a.choose},{default:n(()=>[v(e.$slots,"default",{},void 0,!0)]),_:3},8,["style","onClick"])]),_:3},8,["style"])):g("",!0)]),_:3})}],["__scopeId","data-v-bec5daab"]]),uploadFile:o({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,l={};if(t){let t=e&&e.width||1;t=this.value2px(t);let s=e&&e.radius||5;s=this.value2px(s),l={"border-width":t,"border-style":e&&e.style||"solid","border-color":e&&e.color||"#eee","border-radius":s}}else l.border="none";let s="";for(let i in l)s+=`${i}:${l[i]};`;return s},borderLineStyle(){let e={},{borderStyle:t}=this.styles;if(t&&t.color&&(e["border-color"]=t.color),t&&t.width){let l=t&&t.width||1,s=t&&t.style||0;"number"==typeof l?l+="px":l=l.indexOf("px")?l:l+"px",e["border-width"]=l,"number"==typeof s?s+="px":s=s.indexOf("px")?s:s+"px",e["border-top-style"]=s}let l="";for(let s in e)l+=`${s}:${e[s]};`;return l}},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,l,s,i,a){const o=x,r=F;return u(),d(o,{class:"uni-file-picker__files"},{default:n(()=>[l.readonly?g("",!0):(u(),d(o,{key:0,class:"files-button",onClick:a.choose},{default:n(()=>[v(e.$slots,"default",{},void 0,!0)]),_:3},8,["onClick"])),a.list.length>0?(u(),d(o,{key:1,class:"uni-file-picker__lists is-text-box",style:m(a.borderStyle)},{default:n(()=>[(u(!0),p(c,null,h(a.list,(e,t)=>(u(),d(o,{class:_(["uni-file-picker__lists-box",{"files-border":0!==t&&a.styles.dividline}]),key:t,style:m(0!==t&&a.styles.dividline&&a.borderLineStyle)},{default:n(()=>[f(o,{class:"uni-file-picker__item"},{default:n(()=>[f(o,{class:"files__name"},{default:n(()=>[b(k(e.name),1)]),_:2},1024),l.delIcon&&!l.readonly?(u(),d(o,{key:0,class:"icon-del-box icon-files",onClick:e=>a.delFile(t)},{default:n(()=>[f(o,{class:"icon-del icon-files"}),f(o,{class:"icon-del rotate"})]),_:2},1032,["onClick"])):g("",!0)]),_:2},1024),e.progress&&100!==e.progress||0===e.progress?(u(),d(o,{key:0,class:"file-picker__progress"},{default:n(()=>[f(r,{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)):g("",!0),"error"===e.status?(u(),d(o,{key:1,class:"file-picker__mask",onClick:y(l=>a.uploadFiles(e,t),["stop"])},{default:n(()=>[b(" 点击重试 ")]),_:2},1032,["onClick"])):g("",!0)]),_:2},1032,["class","style"]))),128))]),_:1},8,["style"])):g("",!0)]),_:3})}],["__scopeId","data-v-2be9f9bb"]])},options:{virtualHost:!0},emits:["select","success","fail","progress","delete","update:modelValue","input"],props:{modelValue:{type:[Array,Object],default:()=>[]},value:{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"]},sourceType:{type:Array,default:()=>["album","camera"]},provider:{type:String,default:""},dir:{type:String,default:""}},data:()=>({files:[],localValue:[],dirPath:""}),watch:{value:{handler(e,t){this.setValue(e,t)},immediate:!0},modelValue:{handler(e,t){this.setValue(e,t)},immediate:!0},dir:{handler(e){this.dirPath=e},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>=9?9:this.limit:1}},created(){e.config&&e.config.provider||(this.noSpace=!0,e.chooseAndUploadFile=H),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=[];return this.files.forEach((t,l)=>{"ready"!==t.status&&"error"!==t.status||e.push(Object.assign({},t))}),this.uploadFiles(e)},async setValue(e,t){const l=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 l(e):e={};else{e||(e=[]);for(let t=0;t<e.length;t++){let s=e[t];await l(s)}}this.localValue=e,this.form&&this.formItem&&!this.is_reset&&(this.is_reset=!1,this.formItem.setValue(this.localValue));let s=Object.keys(e).length>0?e:[];this.files=[].concat(s)},choose(){this.disabled||(this.files.length>=Number(this.limitLength)&&"grid"!==this.showType&&"array"===this.returnType?i({title:`您最多选择 ${this.limitLength} 个文件`,icon:"none"}):this.chooseFiles())},chooseFiles(){const t=q(this.fileExtname);e.chooseAndUploadFile({type:this.fileMediatype,compressed:!1,sizeType:this.sizeType,sourceType:this.sourceType,extension:t.length>0?t: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=>{console.log("选择失败",e)})},async chooseFileCallback(e){const t=q(this.fileExtname);(1===Number(this.limitLength)&&this.disablePreview&&!this.disabled||"object"===this.returnType)&&(this.files=[]);let{filePaths:l,files:s}=((e,t)=>{let l=[],s=[];return t&&0!==t.length?(e.tempFiles.forEach(e=>{const i=Z(e.name).ext.toLowerCase();-1!==t.indexOf(i)&&(s.push(e),l.push(e.path))}),s.length!==e.tempFiles.length&&i({title:`当前选择了${e.tempFiles.length}个文件 ,${e.tempFiles.length-s.length} 个文件格式不正确`,icon:"none",duration:5e3}),{filePaths:l,files:s}):{filePaths:l,files:s}})(e,t);t&&t.length>0||(l=e.tempFilePaths,s=e.tempFiles);let a=[];for(let i=0;i<s.length&&!(this.limitLength-this.files.length<=0);i++){s[i].uuid=Date.now();let e=await G(s[i],this.fileMediatype);e.progress=0,e.status="ready";let t={...e,file:s[i]};this.files.push(t),a.push(t)}return this.$emit("select",{tempFiles:a,tempFilePaths:l}),e.tempFiles=s,this.autoUpload&&!this.noSpace||(e.tempFiles=[]),console.log(123123123,"zidong"),e.tempFiles.map((e,t)=>{this.provider&&(e.provider=this.provider);const l=e.name.split("."),s=l.pop(),i=l.join(".").replace(/[\s\/\?<>\\:\*\|":]/g,"_");let a=this.dirPath||"";return a&&"/"!==a[a.length-1]&&(a+="/"),e.cloudPath=a+i+"_"+Date.now()+"_"+t+"."+s,e.cloudPathAsRealPath=!0,e}),e},uploadFiles(e){return e=[].concat(e),N.call(this,e,5,e=>{this.setProgress(e,e.index,!0)}).then(e=>(this.setSuccessAndError(e),e)).catch(e=>{console.log(e)})},async setSuccessAndError(e,t){let l=[],s=[],i=[],a=[];for(let o=0;o<e.length;o++){const t=e[o],r=t.uuid?this.files.findIndex(e=>e.uuid===t.uuid):t.index;if(-1===r||!this.files)break;if("request:fail"===t.errMsg)this.files[r].url=t.path,this.files[r].status="error",this.files[r].errMsg=t.errMsg,s.push(this.files[r]),a.push(this.files[r].url);else{this.files[r].errMsg="",this.files[r].fileID=t.url;/cloud:\/\/([\w.]+\/?)\S*/.test(t.url)?this.files[r].url=await this.getTempFileURL(t.url):this.files[r].url=t.url,this.files[r].status="success",this.files[r].progress+=1,l.push(this.files[r]),i.push(this.files[r].fileID)}}l.length>0&&(this.setEmit(),this.$emit("success",{tempFiles:this.backObject(l),tempFilePaths:i})),s.length>0&&this.$emit("fail",{tempFiles:this.backObject(s),tempFilePaths:a})},setProgress(e,t,l){this.files.length;const s=Math.round(100*e.loaded/e.total);let i=t;l||(i=this.files.findIndex(t=>t.uuid===e.tempFile.uuid)),-1!==i&&this.files[i]&&(this.files[i].progress=s-1,this.$emit("progress",{index:i,progress:parseInt(s),tempFile:this.files[i]}))},delFile(e){this.$emit("delete",{index:e,tempFile:this.files[e],tempFilePath:this.files[e].url}),this.files.splice(e,1),this.$nextTick(()=>{this.setEmit()})},getFileExt(e){const t=e.lastIndexOf("."),l=e.length;return{name:e.substring(0,t),ext:e.substring(t+1,l)}},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,uuid:e.uuid,status:e.status,cloudPath:e.cloudPath})}),t},async getTempFileURL(t){t={fileList:[].concat(t)};return(await e.getTempFileURL(t)).fileList[0].tempFileURL||""},getForm(e="uniForms"){let t=this.$parent,l=t.$options.name;for(;l!==e;){if(t=t.$parent,!t)return!1;l=t.$options.name}return t}}},[["render",function(e,t,l,s,i,a){const o=P,r=x,p=S("upload-image"),c=I,h=S("upload-file");return u(),d(r,{class:"uni-file-picker"},{default:n(()=>[l.title?(u(),d(r,{key:0,class:"uni-file-picker__header"},{default:n(()=>[f(o,{class:"file-title"},{default:n(()=>[b(k(l.title),1)]),_:1}),f(o,{class:"file-count"},{default:n(()=>[b(k(a.filesList.length)+"/"+k(a.limitLength),1)]),_:1})]),_:1})):g("",!0),"image"===l.fileMediatype&&"grid"===a.showType?(u(),d(p,{key:1,readonly:l.readonly,"image-styles":l.imageStyles,"files-list":a.filesList,limit:a.limitLength,disablePreview:l.disablePreview,delIcon:l.delIcon,onUploadFiles:a.uploadFiles,onChoose:a.choose,onDelFile:a.delFile},{default:n(()=>[v(e.$slots,"default",{},()=>[f(r,{class:"icon-add"}),f(r,{class:"icon-add rotate"})],!0)]),_:3},8,["readonly","image-styles","files-list","limit","disablePreview","delIcon","onUploadFiles","onChoose","onDelFile"])):g("",!0),"image"!==l.fileMediatype||"grid"!==a.showType?(u(),d(h,{key:2,readonly:l.readonly,"list-styles":l.listStyles,"files-list":a.filesList,showType:a.showType,delIcon:l.delIcon,onUploadFiles:a.uploadFiles,onChoose:a.choose,onDelFile:a.delFile},{default:n(()=>[v(e.$slots,"default",{},()=>[f(c,{type:"primary",size:"mini"},{default:n(()=>[b("选择文件")]),_:1})],!0)]),_:3},8,["readonly","list-styles","files-list","showType","delIcon","onUploadFiles","onChoose","onDelFile"])):g("",!0)]),_:3})}],["__scopeId","data-v-c2dab129"]]),J=o({__name:"cwg-file-picker",props:{modelValue:{type:[String,Array,Object],default:null},editable:{type:Boolean,default:!1},multiple:{type:Boolean,default:!1},limit:{type:Number,default:1},title:{type:String,default:""},fileMediatype:{type:String,default:"image"},mode:{type:String,default:"grid"},disabled:{type:Boolean,default:!1},disablePreview:{type:Boolean,default:!1},canChoose:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},uploadUrl:{type:String,required:!0,default:"/custom/bank/upload"},uploadHeaders:{type:Object,default:()=>({})},uploadName:{type:String,default:"file"},uploadData:{type:Object,default:()=>({})},baseUrl:{type:String,default:j.Host80},imagePathPrefix:{type:String,default:""},customClass:{type:String,default:""},previewClass:{type:String,default:""},imageWidth:{type:[String,Number],default:160},imageHeight:{type:[String,Number],default:160},imageGap:{type:[String,Number],default:16},imageBorderRadius:{type:[String,Number],default:8},imageMode:{type:String,default:"aspectFill"},showCustomButton:{type:Boolean,default:!0},uploadText:{type:String,default:""},replaceText:{type:String,default:""},noImageText:{type:String,default:""},showPreviewDelete:{type:Boolean,default:!1},canDelete:{type:Boolean,default:!0},showProgress:{type:Boolean,default:!0},autoUpload:{type:Boolean,default:!0},responseHandler:{type:Function,default:e=>{var t;try{const l="string"==typeof e?JSON.parse(e):e;return{success:200===l.code,path:(null==(t=l.data)?void 0:t.path)||l.data,message:l.msg||"上传成功",data:l}}catch(l){return{success:!1,path:null,message:"解析响应失败",data:null}}}},imageStyles:{type:Object,default:()=>({})},listStyles:{type:Object,default:()=>({})},customStyles:{type:Object,default:()=>({})},showError:{type:Object,default:!0}},emits:["update:modelValue","select","delete","progress","success","fail","preview","image-error","preview-delete","upload-start","upload-complete"],setup(e,{expose:t,emit:l}){T(e=>({"25cfc6b6":z.value,b23bcb64:N.value}));const{t:s}=C(),a=e,o=l,F=$(0),S=$(""),I=$(!1),L=V(()=>X(a.modelValue)),D=V(()=>"number"==typeof a.imageWidth?ne(a.imageWidth):a.imageWidth),U=V(()=>"number"==typeof a.imageHeight?ne(a.imageHeight):a.imageHeight),z=V(()=>"number"==typeof a.imageGap?ne(a.imageGap):a.imageGap),N=V(()=>"number"==typeof a.imageBorderRadius?ne(a.imageBorderRadius):a.imageBorderRadius),R=V(()=>({width:D.value,height:U.value,...a.customStyles.customButton})),H=V(()=>({width:D.value,height:U.value,borderRadius:N.value,...a.customStyles.previewImage})),Z=V(()=>({width:D.value,height:U.value,borderRadius:N.value,...a.customStyles.imageItem})),q=V(()=>({gap:z.value,...a.customStyles.listContainer})),G=V(()=>({width:D.value,height:U.value,borderRadius:N.value,...a.customStyles.noImage})),J=V(()=>a.customStyles.noImageText||{}),K=V(()=>a.customStyles.progress||{}),Q=V(()=>a.customStyles.deleteBtn||{}),X=e=>e?a.multiple?Array.isArray(e)?e.map(e=>({url:ee(e.path||e),path:e.path||e,name:e.name||"图片",uuid:e.id||e.path||Date.now()+Math.random()})):[]:(console.log(e,[{url:ee(e),path:e,name:"图片",uuid:e}],121212121),"string"==typeof e?e?[{url:ee(e),path:e,name:"图片",uuid:e}]:[]:e&&e.path?[{url:ee(e.path),path:e.path,name:e.name||"图片",uuid:e.id||e.path}]:[]):(a.multiple,[]),Y=e=>e?a.multiple?Array.isArray(e)?e:[]:"string"==typeof e?e?[{path:e}]:[]:e?[e]:[]:[],ee=e=>e?e.startsWith("http")?e:(a.baseUrl||j.Host80)+(a.imagePathPrefix||"")+e:"",te=e=>e?"string"==typeof e?ee(e):e.url?e.url:e.path?ee(e.path):"":"",le=e=>e?"string"==typeof e?e:e.path||e.url||"":"",se=e=>e?ee("string"==typeof e?e:e.path||e.url||""):"",ie=async e=>{S.value="",o("select",e),a.autoUpload&&await ae(e.tempFiles)},ae=async e=>{if(e&&0!==e.length){I.value=!0,o("upload-start");try{const t=[];for(let l=0;l<e.length;l++){const s=e[l];F.value=Math.round(l/e.length*100);const i=await oe(s);if(!i.success)throw new Error(i.message);t.push(i.path),F.value=Math.round((l+1)/e.length*100)}if(a.multiple){const e=[...Array.isArray(a.modelValue)?[...a.modelValue]:[],...t.map(e=>({path:e}))];o("update:modelValue",e)}else{const e=t[0];console.log(3333,a.modelValue),o("update:modelValue",e)}F.value=100,setTimeout(()=>{F.value=0},500),o("upload-complete",{success:!0,paths:t})}catch(t){S.value=t.message||"上传失败",F.value=0,o("upload-complete",{success:!1,error:t.message}),i({title:t.message||"上传失败",icon:"none"})}finally{I.value=!1}}},oe=e=>new Promise((t,l)=>{E({url:j.Host80+a.uploadUrl,filePath:e.path,name:a.uploadName,header:a.uploadHeaders,name:"file",header:{"Access-Token":O.value},formData:a.uploadData,success:e=>{const s=a.responseHandler(e.data);s.success?t(s):l(new Error(s.message))},fail:e=>{console.error("上传失败:",e),l(new Error("网络错误,请重试"))}}).onProgressUpdate(e=>{console.log("单文件上传进度:",e.progress)})}),re=e=>{if(o("delete",e),a.multiple){const t=(Array.isArray(a.modelValue)?[...a.modelValue]:[]).filter((t,l)=>l!==e.index);o("update:modelValue",t)}else o("update:modelValue","")},ue=e=>{if(!e)return;const t=Y(a.modelValue).map(e=>ee(le(e)));r({current:ee(e),urls:t.length?t:[ee(e)]}),o("preview",e)},de=e=>{console.error("图片加载失败:",e),o("image-error",e)},ne=e=>2*e+"rpx";return t({uploadFiles:ae,clearError:()=>S.value=""}),(t,l)=>{const i=P,r=x,I=A(M("uni-file-picker"),W),T=w;return u(),d(r,{class:_(["common-file-uploader",e.customClass])},{default:n(()=>[e.editable?(u(),d(r,{key:0,class:"upload-wrapper"},{default:n(()=>[f(I,{limit:e.multiple?e.limit:1,title:e.title,"file-mediatype":e.fileMediatype,mode:e.mode,"auto-upload":!1,value:L.value,disabled:e.disabled,readonly:e.readonly,"image-styles":e.imageStyles,"list-styles":e.listStyles,"del-icon":e.showPreviewDelete,disablePreview:e.disablePreview,canChoose:e.canChoose,onSelect:ie,onDelete:re},{default:n(()=>[t.$slots.default||e.showCustomButton?v(t.$slots,"default",{key:0},()=>[f(r,{class:_(["custom-upload-btn",{"replace-btn":!e.multiple&&L.value.length>0}]),style:m(R.value)},{default:n(()=>[!e.multiple&&L.value.length>0?(u(),p(c,{key:0},[f(i,{class:"replace-icon"},{default:n(()=>[b("↻")]),_:1}),f(i,{class:"tip"},{default:n(()=>[b(k(e.replaceText||B(s)("Common.Replace")),1)]),_:1})],64)):(u(),d(i,{key:1,class:"plus"},{default:n(()=>[b("+")]),_:1}))]),_:1},8,["class","style"])],!0):g("",!0)]),_:3},8,["limit","title","file-mediatype","mode","value","disabled","readonly","image-styles","list-styles","del-icon","disablePreview","canChoose"]),e.showProgress&&F.value>0&&F.value<100?(u(),d(r,{key:0,class:"upload-progress",style:m(K.value)},{default:n(()=>[f(r,{class:"progress-bar",style:m({width:F.value+"%"})},null,8,["style"]),f(i,{class:"progress-text"},{default:n(()=>[b(k(F.value)+"%",1)]),_:1})]),_:1},8,["style"])):g("",!0),S.value&&e.showError?(u(),d(r,{key:1,class:"upload-error"},{default:n(()=>[f(i,{class:"error-text"},{default:n(()=>[b(k(S.value),1)]),_:1})]),_:1})):g("",!0)]),_:3})):(u(),d(r,{key:1,class:_(["image-preview",e.previewClass])},{default:n(()=>[e.multiple?(u(),p(c,{key:1},[Y(e.modelValue).length?(u(),d(r,{key:0,class:"image-list",style:m(q.value)},{default:n(()=>[(u(!0),p(c,null,h(Y(e.modelValue),(t,l)=>(u(),d(r,{key:l,class:"image-item",style:m(Z.value)},{default:n(()=>[f(T,{src:se(t),mode:e.imageMode,class:"preview-image",style:m(H.value),onClick:e=>ue(le(t)),onError:de,"lazy-load":!0},null,8,["src","mode","style","onClick"]),e.showPreviewDelete&&e.canDelete?(u(),d(r,{key:0,class:"preview-delete-btn",style:m(Q.value),onClick:y(e=>((e,t)=>{if(o("preview-delete",{file:e,index:t}),a.multiple){const e=Array.isArray(a.modelValue)?[...a.modelValue]:[];e.splice(t,1),o("update:modelValue",e)}})(t,l),["stop"])},{default:n(()=>[f(i,{class:"delete-icon"},{default:n(()=>[b("×")]),_:1})]),_:2},1032,["style","onClick"])):g("",!0)]),_:2},1032,["style"]))),128))]),_:1},8,["style"])):(u(),d(r,{key:1,class:"no-image",style:m(G.value)},{default:n(()=>[f(i,{style:m(J.value)},{default:n(()=>[b(k(e.noImageText||B(s)("Common.NoImage")),1)]),_:1},8,["style"])]),_:1},8,["style"]))],64)):(u(),d(r,{key:0,class:"single-preview"},{default:n(()=>[te(e.modelValue)?(u(),d(T,{key:0,src:te(e.modelValue),mode:e.imageMode,class:"preview-image",style:m(H.value),onClick:l[0]||(l[0]=t=>ue(te(e.modelValue))),onError:de,"lazy-load":!0},null,8,["src","mode","style"])):(u(),d(r,{key:1,class:"no-image",style:m(G.value)},{default:n(()=>[f(i,{style:m(J.value)},{default:n(()=>[b(k(e.noImageText||B(s)("Common.NoImage")),1)]),_:1},8,["style"])]),_:1},8,["style"]))]),_:1}))]),_:1},8,["class"]))]),_:3},8,["class"])}}},[["__scopeId","data-v-53f242a6"]]);export{L as P,D as V,J as _,W as a};
|