2 lines
23 KiB
JavaScript
2 lines
23 KiB
JavaScript
|
|
import{ad as e,ae as t,af as s,A as l,ag as i,ah as a,b as o,e as r,w as n,v as d,Q as c,a0 as u,N as h,g as p,ai as f,q as m,y,O as g,F as b,l as _,aj as x,_ as v,z as F,ak as k,G as w,H as P,d as I,r as T,o as S,al as $,am as C,j as M,k as L,an as O,a6 as j,ao as E,ap as D}from"./index-f6e54d8f.js";import{_ as V}from"./uni-card.fea6370f.js";import{L as U}from"./uni-cloud.es.9367344b.js";import{_ as A}from"./_plugin-vue_export-helper.1b428a4d.js";const B="chooseAndUploadFile:fail";function z(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 N(e,t=5,s){const l=(e=JSON.parse(JSON.stringify(e))).length;let i=0,a=this;return new Promise((o=>{for(;i<t;)r();function r(){let t=i++;if(t>=l)return void(!e.find((e=>!e.url&&!e.errMsg))&&o(e));const n=e[t],d=a.files.findIndex((e=>e.uuid===n.uuid));n.url="",delete n.errMsg,U.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<l&&r()})).catch((e=>{n.errMsg=e.errMsg||e.message,n.index=d,t<l&&r()}))}}))}function R(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 q(l={type:"all"}){return"image"===l.type?R(function(t){const{count:s,sizeType:l=["original","compressed"],sourceType:i,extension:a}=t;return new Promise(((t,o)=>{e({count:s,sizeType:l,sourceType:i,extension:a,success(e){t(z(e,"image"))},fail(e){o({errMsg:e.errMsg.replace("chooseImage:fail",B)})}})}))}(l),l):"video"===l.type?R(function(e){const{count:s,camera:l,compressed:i,maxDuration:a,sourceType:o,extension:r}=e;return new Promise(((e,s)=>{t({camera:l,compressed:i,maxDuration:a,sourceType:o,extension:r,success(t){const{tempFilePath:s,duration:l,size:i,height:a,width:o}=t;e(z({errMsg:"chooseVideo:ok",tempFilePaths:[s],tempFiles:[{name:t.tempFile&&t.tempFile.name||"",path:s,size:i,type:t.tempFile&&t.tempFile.type||"",width:o,height:a,duration:l,fileType:"video",cloudPath:""}]},"video"))},fail(e){s({errMsg:e.errMsg.replace("chooseVideo:fail",B)})}})}))}(l),l):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:B+" 请指定 type 类型,该平台仅支持选择 image 或 video。"});a({type:"all",count:t,extension:l,success(t){e(z(t))},fail(e){i({errMsg:e.errMsg.replace("chooseFile:fail",B)})}})}))}(l),l)}const H=e=>{const t=e.lastIndexOf("."),s=e.length;return{name:e.substring(0,t),ext:e.substring(t+1,s)}},J=e=>{if(Array.isArray(e))return e;return e.replace(/(\[|\])/g,"").split(",")},X=async(e,t="image")=>{const s=H(e.name).ext.toLowerCase();let l={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(a=e.path,new Promise(((e,t)=>{i({src:a,success(t){e(t)},fail(e){t(e)}})})));delete l.video,l.image.width=t.width,l.image.height=t.height,l.image.location=t.path}else delete l.image;var a;return l};const G=A({name:"uniFilePicker",components:{uploadImage:A({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=th
|