jiuyiUniapp/jiuyi2/unpackage/dist/build/web/assets/uni-file-picker.Dkbqw_5V.js

2 lines
17 KiB
JavaScript
Raw Normal View History

2024-12-27 15:03:48 +08:00
import{Z as e}from"./uni-cloud.es.t_RKYAwE.js";import{o as t,c as i,w as s,a as l,F as o,m as r,A as a,b as n,K as d,s as u,e as h,N as c,f as p,i as f,O as m,p as y,t as g,M as b,v as F,d as x}from"./index-CZsuXyof.js";import{_}from"./_plugin-vue_export-helper.BCo6x5W8.js";const k="chooseAndUploadFile:fail";function w(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 v(t,i=5,s){const l=(t=JSON.parse(JSON.stringify(t))).length;let o=0,r=this;return new Promise((a=>{for(;o<i;)n();function n(){let i=o++;if(i>=l)return void(!t.find((e=>!e.url&&!e.errMsg))&&a(t));const d=t[i],u=r.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=u,s&&s(e)}}).then((e=>{d.url=e.fileID,d.index=u,i<l&&n()})).catch((e=>{d.errMsg=e.errMsg||e.message,d.index=u,i<l&&n()}))}}))}function I(e,{onChooseFile:t,onUploadProgress:i}){return e.then((e=>{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 P(e={type:"all"}){return"image"===e.type?I(function(e){const{count:t,sizeType:i=["original","compressed"],sourceType:s,extension:l}=e;return new Promise(((e,o)=>{uni.chooseImage({count:t,sizeType:i,sourceType:s,extension:l,success(t){e(w(t,"image"))},fail(e){o({errMsg:e.errMsg.replace("chooseImage:fail",k)})}})}))}(e),e):"video"===e.type?I(function(e){const{count:t,camera:i,compressed:s,maxDuration:l,sourceType:o,extension:r}=e;return new Promise(((e,t)=>{uni.chooseVideo({camera:i,compressed:s,maxDuration:l,sourceType:o,extension:r,success(t){const{tempFilePath:i,duration:s,size:l,height:o,width:r}=t;e(w({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){t({errMsg:e.errMsg.replace("chooseVideo:fail",k)})}})}))}(e),e):I(function(e){const{count:t,extension:i}=e;return new Promise(((e,s)=>{let l=uni.chooseFile;if("undefined"!=typeof wx&&"function"==typeof wx.chooseMessageFile&&(l=wx.chooseMessageFile),"function"!=typeof l)return s({errMsg:k+" 请指定 type 类型,该平台仅支持选择 image 或 video。"});l({type:"all",count:t,extension:i,success(t){e(w(t))},fail(e){s({errMsg:e.errMsg.replace("chooseFile:fail",k)})}})}))}(e),e)}const T=e=>{const t=e.lastIndexOf("."),i=e.length;return{name:e.substring(0,t),ext:e.substring(t+1,i)}},S=e=>{if(Array.isArray(e))return e;return e.replace(/(\[|\])/g,"").split(",")},$=async(e,t="image")=>{const i=T(e.name).ext.toLowerCase();let s={name:e.name,uuid:e.uuid,extname:i||"",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(l=e.path,new Promise(((e,t)=>{uni.getImageInfo({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};const M=_({name:"uniFilePicker",components:{uploadImage:_({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"!==