2 lines
7.1 KiB
JavaScript
2 lines
7.1 KiB
JavaScript
import{_ as q}from"./index-BeJT5uVo.js";import{o as re,bQ as se,bR as ue,az as de,R as pe,bL as O,M as s,p as T,n as fe,x as F,q as ge,r as me,v as g,bM as ve,D as S,s as d,aw as h,ae as I,L as ce,ac as he,ah as ye,t as we,ad as De,a2 as Ce}from"./.pnpm-BGZW0UGg.js";import{_ as be,a as Q,F as Te}from"./index-DjAC1tO-.js";import{e as Se,i as j,_ as Pe,c as ze}from"./index-CeIwrh_6.js";import{_ as $e}from"./index-B1H9vJ5g.js";import{a as ke}from"./file-tQw_m7Aj.js";const Ve=re({components:{Popup:q,Draggable:se,FileItem:Te,Material:Q,Preview:be},props:{modelValue:{type:[String,Array],default:()=>[]},type:{type:String,default:"image"},size:{type:String,default:"100px"},width:{type:String,default:""},height:{type:String,default:""},fileSize:{type:String,default:"100px"},limit:{type:Number,default:1},disabled:{type:Boolean,default:!1},hiddenUpload:{type:Boolean,default:!1},uploadClass:{type:String,default:""},excludeDomain:{type:Boolean,default:!1},uploadCid:{type:[Number,String],default:0}},emits:["change","update:modelValue"],setup(e,{emit:a}){const k=s(),V=s(),A=s(""),E=s(!1),o=s([]),P=s([]),c=s(!0),z=s(-1),m=s(0),y=s(!1),{disabled:v,limit:p,modelValue:i}=ue(e),w=Se(),D=t=>w.getImageUrl(t),C=T(()=>!e.hiddenUpload&&(e.type==="image"||e.type==="video"||e.type==="file")),_=T(()=>m.value>0);function R(t){if(!t)return!1;const n=Array.from(t.types);return n.includes("Files")||n.includes("application/x-moz-file")}function B(t,n){var r;if(n==="file")return!0;const l=t.includes(".")&&((r=t.split(".").pop())==null?void 0:r.toLowerCase())||"";return n==="image"?l?["jpg","jpeg","png","gif","ico"].includes(l):!0:n==="video"&&l?["wmv","avi","mpg","mpeg","3gp","mov","mp4","flv","rmvb","mkv"].includes(l):!0}function G(t){var r;if(!t||!t.startsWith("http"))return t;const n=String(((r=w.config)==null?void 0:r.oss_domain)||"").trim().replace(/\/$/,"");if(n&&t.startsWith(n))return t.slice(n.length).replace(/^\//,"");const l=typeof window<"u"?window.location.origin.replace(/\/$/,""):"";if(l&&t.startsWith(l))return t.slice(l.length).replace(/^\//,"");try{return new URL(t).pathname.replace(/^\//,"")}catch{return t}}function H(t){var b,$;const n=e.type,l=Array.from(((b=t.clipboardData)==null?void 0:b.files)||[]).filter(f=>B(f.name,n));if(l.length)return l;if(n!=="image")return[];const r=($=t.clipboardData)==null?void 0:$.items;if(!r)return[];const u=[];for(let f=0;f<r.length;f++){const U=r[f];if(U.kind==="file"&&U.type.startsWith("image/")){const N=U.getAsFile();N&&u.push(N)}}return u}async function M(t){if(y.value)return;const n=p.value===-1?1/0:Math.max(0,p.value-o.value.length);if(!n){j.msgWarning("已达到上传数量上限");return}const l=t.slice(0,n);if(!l.length)return;const r=e.type==="video"?"video":e.type==="file"?"file":"image";y.value=!0;try{const u=[];for(const $ of l){const f=await ke($,r,e.uploadCid);u.push(e.excludeDomain?G(f.url):f.url)}o.value=[...o.value,...u];const b=p.value!=1?o.value:o.value[0]||"";a("update:modelValue",b),a("change",b),L()}catch(u){j.msgError((u==null?void 0:u.message)||"上传失败")}finally{y.value=!1}}const J=t=>{!C.value||v.value||R(t.dataTransfer)&&m.value++},K=()=>{C.value&&(m.value=Math.max(0,m.value-1))},X=t=>{!C.value||v.value||R(t.dataTransfer)&&t.preventDefault()},Y=async t=>{var l;if(m.value=0,!C.value||v.value)return;const n=Array.from(((l=t.dataTransfer)==null?void 0:l.files)||[]).filter(r=>B(r.name,e.type));n.length&&await M(n)},Z=async t=>{if(!C.value||v.value)return;const n=H(t);n.length&&(t.preventDefault(),await M(n))},x=T(()=>{switch(e.type){case"image":return"图片";case"video":return"视频";default:return""}}),ee=T(()=>e.limit-o.value.length>0),te=T(()=>c.value?p.value==-1?null:p.value-o.value.length:1),ae=de(()=>{const t=P.value.map(n=>e.excludeDomain?n.uri:n.url);c.value?o.value=[...o.value,...t]:o.value.splice(z.value,1,t.shift()),W()},1e3,!1),ne=t=>{var n;v.value||(t>=0?(c.value=!1,z.value=t):c.value=!0,(n=k.value)==null||n.open())},ie=t=>{P.value=t},W=()=>{const t=p.value!=1?o.value:o.value[0]||"";a("update:modelValue",t),a("change",t),L()},oe=t=>{o.value.splice(t,1),W()},le=t=>{A.value=e.excludeDomain?D(t):t,E.value=!0},L=()=>{fe(()=>{var t;e.hiddenUpload&&(o.value=[]),(t=V.value)==null||t.clearSelect()})};return pe(i,t=>{o.value=Array.isArray(t)?t:t==""?[]:[t]},{immediate:!0}),O("limit",e.limit),O("hiddenUpload",e.hiddenUpload),{popupRef:k,materialRef:V,fileList:o,tipsText:x,handleConfirm:ae,meterialLimit:te,showUpload:ee,showPopup:ne,selectChange:ie,deleteImg:oe,previewUrl:A,showPreview:E,handlePreview:le,handleClose:L,getImageUrl:D,dropActive:_,onTriggerDragEnter:J,onTriggerDragLeave:K,onTriggerDragOver:X,onTriggerDrop:Y,onTriggerPaste:Z}}}),Ae={class:"material-select"},Ee=["onClick"],Le={class:"operation-btns text-xs text-center"},Ue=["onClick"],Fe={class:"material-wrap"};function Ie(e,a,k,V,A,E){const o=F("file-item"),P=$e,c=F("draggable"),z=ze,m=Q,y=Ce,v=q,p=F("preview");return ge(),me("div",Ae,[g(v,{ref:"popupRef",width:"1050px","custom-class":"body-padding",title:`选择${e.tipsText}`,onConfirm:e.handleConfirm,onClose:e.handleClose},ve({default:S(()=>[g(y,null,{default:S(()=>[d("div",Fe,[g(m,{ref:"materialRef",type:e.type,"file-size":e.fileSize,limit:e.meterialLimit,onChange:e.selectChange},null,8,["type","file-size","limit","onChange"])])]),_:1})]),_:2},[e.hiddenUpload?void 0:{name:"trigger",fn:S(()=>[d("div",{class:I(["material-select__trigger clearfix",{"is-drop-hover":e.dropActive}]),tabindex:"0",onClick:a[2]||(a[2]=h(()=>{},["stop"])),onDragenter:a[3]||(a[3]=h((...i)=>e.onTriggerDragEnter&&e.onTriggerDragEnter(...i),["prevent","stop"])),onDragleave:a[4]||(a[4]=h((...i)=>e.onTriggerDragLeave&&e.onTriggerDragLeave(...i),["prevent","stop"])),onDragover:a[5]||(a[5]=h((...i)=>e.onTriggerDragOver&&e.onTriggerDragOver(...i),["prevent","stop"])),onDrop:a[6]||(a[6]=h((...i)=>e.onTriggerDrop&&e.onTriggerDrop(...i),["prevent","stop"])),onPaste:a[7]||(a[7]=(...i)=>e.onTriggerPaste&&e.onTriggerPaste(...i))},[g(c,{class:"draggable",modelValue:e.fileList,"onUpdate:modelValue":a[0]||(a[0]=i=>e.fileList=i),animation:"300","item-key":"id"},{item:S(({element:i,index:w})=>[d("div",{class:I(["material-preview",{"is-disabled":e.disabled,"is-one":e.limit==1}]),onClick:D=>e.showPopup(w)},[g(P,{onClose:D=>e.deleteImg(w)},{default:S(()=>[g(o,{uri:e.excludeDomain?e.getImageUrl(i):i,"file-size":e.size,width:e.width,height:e.height,type:e.type},null,8,["uri","file-size","width","height","type"])]),_:2},1032,["onClose"]),d("div",Le,[a[9]||(a[9]=d("span",null,"修改",-1)),a[10]||(a[10]=ce(" | ",-1)),d("span",{onClick:h(D=>e.handlePreview(i),["stop"])},"查看",8,Ue)])],10,Ee)]),_:1},8,["modelValue"]),he(d("div",{class:I(["material-upload",{"is-disabled":e.disabled,"is-one":e.limit==1,[e.uploadClass]:!0}]),onClick:a[1]||(a[1]=i=>e.showPopup(-1))},[ye(e.$slots,"upload",{},()=>[d("div",{class:"upload-btn",style:we({width:e.width||e.size,height:e.height||e.size})},[g(z,{size:25,name:"el-icon-Plus"}),a[11]||(a[11]=d("span",null,"添加",-1))],4)],!0)],2),[[De,e.showUpload]])],34)]),key:"0"}]),1032,["title","onConfirm","onClose"]),g(p,{modelValue:e.showPreview,"onUpdate:modelValue":a[8]||(a[8]=i=>e.showPreview=i),url:e.previewUrl,type:e.type},null,8,["modelValue","url","type"])])}const je=Pe(Ve,[["render",Ie],["__scopeId","data-v-8eb71802"]]);export{je as _};
|