jiuyiUniapp/jiuyi/unpackage/dist/build/web/assets/uni-file-picker.DTxWzIcG.js

2 lines
17 KiB
JavaScript
Raw Normal View History

2024-12-18 15:46:27 +08:00
import{af as e,aM as t,aN as s,v as i,aO as l,T as o,o as a,c as r,w as n,a as d,F as u,q as h,N as c,b as p,_ as f,z as m,e as y,G as g,f as b,i as F,aP as x,E as _,y as k,a0 as w,x as v,d as P}from"./index-CH9-aFWw.js";import{Y as T}from"./uni-cloud.es.DXthrROh.js";import{_ as I}from"./_plugin-vue_export-helper.BCo6x5W8.js";const S="chooseAndUploadFile:fail";function $(e,t){return e.tempFiles.forEach(((e,s)=>{e.name||(e.name=e.path.substring(e.path.lastIndexOf("/")+1)),t&&(e.fileType=t),e.cloudPath=Date.now()+"_"+s+e.name.substring(e.name.lastIndexOf("."))})),e.tempFilePaths||(e.tempFilePaths=e.tempFiles.map((e=>e.path))),e}function M(e,t=5,s){const i=(e=JSON.parse(JSON.stringify(e))).length;let l=0,o=this;return new Promise((a=>{for(;l<t;)r();function r(){let t=l++;if(t>=i)return void(!e.find((e=>!e.url&&!e.errMsg))&&a(e));const n=e[t],d=o.files.findIndex((e=>e.uuid===n.uuid));n.url="",delete n.errMsg,T.uploadFile({filePath:n.path,cloudPath:n.cloudPath,fileType:n.fileType,onUploadProgress:e=>{e.index=d,s&&s(e)}}).then((e=>{n.url=e.fileID,n.index=d,t<i&&r()})).catch((e=>{n.errMsg=e.errMsg||e.message,n.index=d,t<i&&r()}))}}))}function C(e,{onChooseFile:t,onUploadProgress:s}){return e.then((e=>{if(t){const s=t(e);if(void 0!==s)return Promise.resolve(s).then((t=>void 0===t?e:t))}return e})).then((e=>!1===e?{errMsg:"chooseAndUploadFile:ok",tempFilePaths:[],tempFiles:[]}:e))}function L(i={type:"all"}){return"image"===i.type?C(function(t){const{count:s,sizeType:i=["original","compressed"],sourceType:l,extension:o}=t;return new Promise(((t,a)=>{e({count:s,sizeType:i,sourceType:l,extension:o,success(e){t($(e,"image"))},fail(e){a({errMsg:e.errMsg.replace("chooseImage:fail",S)})}})}))}(i),i):"video"===i.type?C(function(e){const{count:s,camera:i,compressed:l,maxDuration:o,sourceType:a,extension:r}=e;return new Promise(((e,s)=>{t({camera:i,compressed:l,maxDuration:o,sourceType:a,extension:r,success(t){const{tempFilePath:s,duration:i,size:l,height:o,width:a}=t;e($({errMsg:"chooseVideo:ok",tempFilePaths:[s],tempFiles:[{name:t.tempFile&&t.tempFile.name||"",path:s,size:l,type:t.tempFile&&t.tempFile.type||"",width:a,height:o,duration:i,fileType:"video",cloudPath:""}]},"video"))},fail(e){s({errMsg:e.errMsg.replace("chooseVideo:fail",S)})}})}))}(i),i):C(function(e){const{count:t,extension:i}=e;return new Promise(((e,l)=>{let o=s;if("undefined"!=typeof wx&&"function"==typeof wx.chooseMessageFile&&(o=wx.chooseMessageFile),"function"!=typeof o)return l({errMsg:S+" 请指定 type 类型,该平台仅支持选择 image 或 video。"});o({type:"all",count:t,extension:i,success(t){e($(t))},fail(e){l({errMsg:e.errMsg.replace("chooseFile:fail",S)})}})}))}(i),i)}const O=e=>{const t=e.lastIndexOf("."),s=e.length;return{name:e.substring(0,t),ext:e.substring(t+1,s)}},E=e=>{if(Array.isArray(e))return e;return e.replace(/(\[|\])/g,"").split(",")},j=async(e,t="image")=>{const s=O(e.name).ext.toLowerCase();let i={name:e.name,uuid:e.uuid,extname:s||"",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(o=e.path,new Promise(((e,t)=>{l({src:o,success(t){e(t)},fail(e){t(e)}})})));delete i.video,i.image.width=t.width,i.image.height=t.height,i.image.location=t.path}else delete i.image;var o;return i};const U=I({name:"uniFilePicker",components:{uploadImage:I({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 s={};"auto"===t?"auto"!==e?(s.height=this.value2px(e),s["padding-top"]=0):s.height=0:(s.height=this.value2px(t),s["padding-top"]=0),s.width="auto"===e?"auto"!==t?t