index.95f4c07f.js 17 KB

123456
  1. import{ar as Fe,$ as z,as as b,ad as j,ae as q,a3 as S,at as Le,au as ce,av as Re,aw as pe,ax as fe,U as ve,a4 as ee,d as g,e as E,t as m,h as e,g as N,D as A,aj as R,v as W,k,x as D,w as _,ay as _e,n as M,ak as H,ao as me,V as x,az as ye,aA as ge,aB as Q,aC as P,aD as Te,aE as V,r as he,F as Ue,j as De,aF as be,af as K,f as B,aG as Oe,aH as Be,aI as Ne,aJ as je,al as Ae,a6 as Y,aK as te,aL as Me,aM as Ie,aN as qe,a5 as se,aO as Ke,a8 as ze,a9 as He,aP as We,aQ as ae,aR as ne}from"./index.bec96d93.js";var Ve=1,Ge=4;function oe(a){return Fe(a,Ve|Ge)}const Xe=z({type:{type:String,default:"line",values:["line","circle","dashboard"]},percentage:{type:Number,default:0,validator:a=>a>=0&&a<=100},status:{type:String,default:"",values:["","success","exception","warning"]},indeterminate:{type:Boolean,default:!1},duration:{type:Number,default:3},strokeWidth:{type:Number,default:6},strokeLinecap:{type:b(String),default:"round"},textInside:{type:Boolean,default:!1},width:{type:Number,default:126},showText:{type:Boolean,default:!0},color:{type:b([String,Array,Function]),default:""},striped:Boolean,stripedFlow:Boolean,format:{type:b(Function),default:a=>`${a}%`}}),Je=["aria-valuenow"],Qe={viewBox:"0 0 100 100"},Ye=["d","stroke","stroke-linecap","stroke-width"],Ze=["d","stroke","opacity","stroke-linecap","stroke-width"],xe={key:0},et=j({name:"ElProgress"}),tt=j({...et,props:Xe,setup(a){const t=a,s={success:"#13ce66",exception:"#ff4949",warning:"#e6a23c",default:"#20a0ff"},u=q("progress"),f=S(()=>({width:`${t.percentage}%`,animationDuration:`${t.duration}s`,backgroundColor:F(t.percentage)})),c=S(()=>(t.strokeWidth/t.width*100).toFixed(1)),y=S(()=>["circle","dashboard"].includes(t.type)?Number.parseInt(`${50-Number.parseFloat(c.value)/2}`,10):0),C=S(()=>{const r=y.value,L=t.type==="dashboard";return`
  2. M 50 50
  3. m 0 ${L?"":"-"}${r}
  4. a ${r} ${r} 0 1 1 0 ${L?"-":""}${r*2}
  5. a ${r} ${r} 0 1 1 0 ${L?"":"-"}${r*2}
  6. `}),h=S(()=>2*Math.PI*y.value),$=S(()=>t.type==="dashboard"?.75:1),w=S(()=>`${-1*h.value*(1-$.value)/2}px`),v=S(()=>({strokeDasharray:`${h.value*$.value}px, ${h.value}px`,strokeDashoffset:w.value})),l=S(()=>({strokeDasharray:`${h.value*$.value*(t.percentage/100)}px, ${h.value}px`,strokeDashoffset:w.value,transition:"stroke-dasharray 0.6s ease 0s, stroke 0.6s ease, opacity ease 0.6s"})),n=S(()=>{let r;return t.color?r=F(t.percentage):r=s[t.status]||s.default,r}),d=S(()=>t.status==="warning"?Le:t.type==="line"?t.status==="success"?ce:Re:t.status==="success"?pe:fe),o=S(()=>t.type==="line"?12+t.strokeWidth*.4:t.width*.111111+2),p=S(()=>t.format(t.percentage));function i(r){const L=100/r.length;return r.map((T,U)=>ee(T)?{color:T,percentage:(U+1)*L}:T).sort((T,U)=>T.percentage-U.percentage)}const F=r=>{var L;const{color:O}=t;if(ve(O))return O(r);if(ee(O))return O;{const T=i(O);for(const U of T)if(U.percentage>r)return U.color;return(L=T[T.length-1])==null?void 0:L.color}};return(r,L)=>(g(),E("div",{class:m([e(u).b(),e(u).m(r.type),e(u).is(r.status),{[e(u).m("without-text")]:!r.showText,[e(u).m("text-inside")]:r.textInside}]),role:"progressbar","aria-valuenow":r.percentage,"aria-valuemin":"0","aria-valuemax":"100"},[r.type==="line"?(g(),E("div",{key:0,class:m(e(u).b("bar"))},[N("div",{class:m(e(u).be("bar","outer")),style:A({height:`${r.strokeWidth}px`})},[N("div",{class:m([e(u).be("bar","inner"),{[e(u).bem("bar","inner","indeterminate")]:r.indeterminate},{[e(u).bem("bar","inner","striped")]:r.striped},{[e(u).bem("bar","inner","striped-flow")]:r.stripedFlow}]),style:A(e(f))},[(r.showText||r.$slots.default)&&r.textInside?(g(),E("div",{key:0,class:m(e(u).be("bar","innerText"))},[R(r.$slots,"default",{percentage:r.percentage},()=>[N("span",null,W(e(p)),1)])],2)):k("v-if",!0)],6)],6)],2)):(g(),E("div",{key:1,class:m(e(u).b("circle")),style:A({height:`${r.width}px`,width:`${r.width}px`})},[(g(),E("svg",Qe,[N("path",{class:m(e(u).be("circle","track")),d:e(C),stroke:`var(${e(u).cssVarName("fill-color-light")}, #e5e9f2)`,"stroke-linecap":r.strokeLinecap,"stroke-width":e(c),fill:"none",style:A(e(v))},null,14,Ye),N("path",{class:m(e(u).be("circle","path")),d:e(C),stroke:e(n),fill:"none",opacity:r.percentage?1:0,"stroke-linecap":r.strokeLinecap,"stroke-width":e(c),style:A(e(l))},null,14,Ze)]))],6)),(r.showText||r.$slots.default)&&!r.textInside?(g(),E("div",{key:2,class:m(e(u).e("text")),style:A({fontSize:`${e(o)}px`})},[R(r.$slots,"default",{percentage:r.percentage},()=>[r.status?(g(),D(e(M),{key:1},{default:_(()=>[(g(),D(_e(e(d))))]),_:1})):(g(),E("span",xe,W(e(p)),1))])],6)):k("v-if",!0)],10,Je))}});var st=H(tt,[["__file","/home/runner/work/element-plus/element-plus/packages/components/progress/src/progress.vue"]]);const at=me(st),ke=Symbol("uploadContextKey"),nt="ElUpload";class ot extends Error{constructor(t,s,u,f){super(t),this.name="UploadAjaxError",this.status=s,this.method=u,this.url=f}}function re(a,t,s){let u;return s.response?u=`${s.response.error||s.response}`:s.responseText?u=`${s.responseText}`:u=`fail to ${t.method} ${a} ${s.status}`,new ot(u,s.status,t.method,a)}function rt(a){const t=a.responseText||a.response;if(!t)return t;try{return JSON.parse(t)}catch{return t}}const lt=a=>{typeof XMLHttpRequest>"u"&&x(nt,"XMLHttpRequest is undefined");const t=new XMLHttpRequest,s=a.action;t.upload&&t.upload.addEventListener("progress",c=>{const y=c;y.percent=c.total>0?c.loaded/c.total*100:0,a.onProgress(y)});const u=new FormData;if(a.data)for(const[c,y]of Object.entries(a.data))ye(y)&&y.length?u.append(c,...y):u.append(c,y);u.append(a.filename,a.file,a.file.name),t.addEventListener("error",()=>{a.onError(re(s,a,t))}),t.addEventListener("load",()=>{if(t.status<200||t.status>=300)return a.onError(re(s,a,t));a.onSuccess(rt(t))}),t.open(a.method,s,!0),a.withCredentials&&"withCredentials"in t&&(t.withCredentials=!0);const f=a.headers||{};if(f instanceof Headers)f.forEach((c,y)=>t.setRequestHeader(y,c));else for(const[c,y]of Object.entries(f))ge(y)||t.setRequestHeader(c,String(y));return t.send(u),t},$e=["text","picture","picture-card"];let it=1;const Z=()=>Date.now()+it++,we=z({action:{type:String,default:"#"},headers:{type:b(Object)},method:{type:String,default:"post"},data:{type:b([Object,Function,Promise]),default:()=>Q({})},multiple:{type:Boolean,default:!1},name:{type:String,default:"file"},drag:{type:Boolean,default:!1},withCredentials:Boolean,showFileList:{type:Boolean,default:!0},accept:{type:String,default:""},fileList:{type:b(Array),default:()=>Q([])},autoUpload:{type:Boolean,default:!0},listType:{type:String,values:$e,default:"text"},httpRequest:{type:b(Function),default:lt},disabled:Boolean,limit:Number}),ut=z({...we,beforeUpload:{type:b(Function),default:P},beforeRemove:{type:b(Function)},onRemove:{type:b(Function),default:P},onChange:{type:b(Function),default:P},onPreview:{type:b(Function),default:P},onSuccess:{type:b(Function),default:P},onProgress:{type:b(Function),default:P},onError:{type:b(Function),default:P},onExceed:{type:b(Function),default:P}}),dt=z({files:{type:b(Array),default:()=>Q([])},disabled:{type:Boolean,default:!1},handlePreview:{type:b(Function),default:P},listType:{type:String,values:$e,default:"text"}}),ct={remove:a=>!!a},pt=["onKeydown"],ft=["src"],vt=["onClick"],mt=["title"],yt=["onClick"],gt=["onClick"],ht=j({name:"ElUploadList"}),bt=j({...ht,props:dt,emits:ct,setup(a,{emit:t}){const s=a,{t:u}=Te(),f=q("upload"),c=q("icon"),y=q("list"),C=V(),h=he(!1),$=S(()=>[f.b("list"),f.bm("list",s.listType),f.is("disabled",s.disabled)]),w=v=>{t("remove",v)};return(v,l)=>(g(),D(je,{tag:"ul",class:m(e($)),name:e(y).b()},{default:_(()=>[(g(!0),E(Ue,null,De(v.files,n=>(g(),E("li",{key:n.uid||n.name,class:m([e(f).be("list","item"),e(f).is(n.status),{focusing:h.value}]),tabindex:"0",onKeydown:be(d=>!e(C)&&w(n),["delete"]),onFocus:l[0]||(l[0]=d=>h.value=!0),onBlur:l[1]||(l[1]=d=>h.value=!1),onClick:l[2]||(l[2]=d=>h.value=!1)},[R(v.$slots,"default",{file:n},()=>[v.listType==="picture"||n.status!=="uploading"&&v.listType==="picture-card"?(g(),E("img",{key:0,class:m(e(f).be("list","item-thumbnail")),src:n.url,alt:""},null,10,ft)):k("v-if",!0),n.status==="uploading"||v.listType!=="picture-card"?(g(),E("div",{key:1,class:m(e(f).be("list","item-info"))},[N("a",{class:m(e(f).be("list","item-name")),onClick:K(d=>v.handlePreview(n),["prevent"])},[B(e(M),{class:m(e(c).m("document"))},{default:_(()=>[B(e(Oe))]),_:1},8,["class"]),N("span",{class:m(e(f).be("list","item-file-name")),title:n.name},W(n.name),11,mt)],10,vt),n.status==="uploading"?(g(),D(e(at),{key:0,type:v.listType==="picture-card"?"circle":"line","stroke-width":v.listType==="picture-card"?6:2,percentage:Number(n.percentage),style:A(v.listType==="picture-card"?"":"margin-top: 0.5rem")},null,8,["type","stroke-width","percentage","style"])):k("v-if",!0)],2)):k("v-if",!0),N("label",{class:m(e(f).be("list","item-status-label"))},[v.listType==="text"?(g(),D(e(M),{key:0,class:m([e(c).m("upload-success"),e(c).m("circle-check")])},{default:_(()=>[B(e(ce))]),_:1},8,["class"])):["picture-card","picture"].includes(v.listType)?(g(),D(e(M),{key:1,class:m([e(c).m("upload-success"),e(c).m("check")])},{default:_(()=>[B(e(pe))]),_:1},8,["class"])):k("v-if",!0)],2),e(C)?k("v-if",!0):(g(),D(e(M),{key:2,class:m(e(c).m("close")),onClick:d=>w(n)},{default:_(()=>[B(e(fe))]),_:2},1032,["class","onClick"])),k(" Due to close btn only appears when li gets focused disappears after li gets blurred, thus keyboard navigation can never reach close btn"),k(" This is a bug which needs to be fixed "),k(" TODO: Fix the incorrect navigation interaction "),e(C)?k("v-if",!0):(g(),E("i",{key:3,class:m(e(c).m("close-tip"))},W(e(u)("el.upload.deleteTip")),3)),v.listType==="picture-card"?(g(),E("span",{key:4,class:m(e(f).be("list","item-actions"))},[N("span",{class:m(e(f).be("list","item-preview")),onClick:d=>v.handlePreview(n)},[B(e(M),{class:m(e(c).m("zoom-in"))},{default:_(()=>[B(e(Be))]),_:1},8,["class"])],10,yt),e(C)?k("v-if",!0):(g(),E("span",{key:0,class:m(e(f).be("list","item-delete")),onClick:d=>w(n)},[B(e(M),{class:m(e(c).m("delete"))},{default:_(()=>[B(e(Ne))]),_:1},8,["class"])],10,gt))],2)):k("v-if",!0)])],42,pt))),128)),R(v.$slots,"append")]),_:3},8,["class","name"]))}});var le=H(bt,[["__file","/home/runner/work/element-plus/element-plus/packages/components/upload/src/upload-list.vue"]]);const kt=z({disabled:{type:Boolean,default:!1}}),$t={file:a=>ye(a)},wt=["onDrop","onDragover"],Ee="ElUploadDrag",Et=j({name:Ee}),Ct=j({...Et,props:kt,emits:$t,setup(a,{emit:t}){const s=Ae(ke);s||x(Ee,"usage: <el-upload><el-upload-dragger /></el-upload>");const u=q("upload"),f=he(!1),c=V(),y=h=>{if(c.value)return;f.value=!1,h.stopPropagation();const $=Array.from(h.dataTransfer.files),w=s.accept.value;if(!w){t("file",$);return}const v=$.filter(l=>{const{type:n,name:d}=l,o=d.includes(".")?`.${d.split(".").pop()}`:"",p=n.replace(/\/.*$/,"");return w.split(",").map(i=>i.trim()).filter(i=>i).some(i=>i.startsWith(".")?o===i:/\/\*$/.test(i)?p===i.replace(/\/\*$/,""):/^[^/]+\/[^/]+$/.test(i)?n===i:!1)});t("file",v)},C=()=>{c.value||(f.value=!0)};return(h,$)=>(g(),E("div",{class:m([e(u).b("dragger"),e(u).is("dragover",f.value)]),onDrop:K(y,["prevent"]),onDragover:K(C,["prevent"]),onDragleave:$[0]||($[0]=K(w=>f.value=!1,["prevent"]))},[R(h.$slots,"default")],42,wt))}});var St=H(Ct,[["__file","/home/runner/work/element-plus/element-plus/packages/components/upload/src/upload-dragger.vue"]]);const Pt=z({...we,beforeUpload:{type:b(Function),default:P},onRemove:{type:b(Function),default:P},onStart:{type:b(Function),default:P},onSuccess:{type:b(Function),default:P},onProgress:{type:b(Function),default:P},onError:{type:b(Function),default:P},onExceed:{type:b(Function),default:P}}),Ft=["onKeydown"],Lt=["name","multiple","accept"],Rt=j({name:"ElUploadContent",inheritAttrs:!1}),_t=j({...Rt,props:Pt,setup(a,{expose:t}){const s=a,u=q("upload"),f=V(),c=Y({}),y=Y(),C=o=>{if(o.length===0)return;const{autoUpload:p,limit:i,fileList:F,multiple:r,onStart:L,onExceed:O}=s;if(i&&F.length+o.length>i){O(o,F);return}r||(o=o.slice(0,1));for(const T of o){const U=T;U.uid=Z(),L(U),p&&h(U)}},h=async o=>{if(y.value.value="",!s.beforeUpload)return w(o);let p,i={};try{const r=s.data,L=s.beforeUpload(o);i=te(s.data)?oe(s.data):s.data,p=await L,te(s.data)&&Me(r,i)&&(i=oe(s.data))}catch{p=!1}if(p===!1){s.onRemove(o);return}let F=o;p instanceof Blob&&(p instanceof File?F=p:F=new File([p],o.name,{type:o.type})),w(Object.assign(F,{uid:o.uid}),i)},$=async(o,p)=>ve(o)?o(p):o,w=async(o,p)=>{const{headers:i,data:F,method:r,withCredentials:L,name:O,action:T,onProgress:U,onSuccess:Ce,onError:Se,httpRequest:Pe}=s;try{p=await $(p??F,o)}catch{s.onRemove(o);return}const{uid:G}=o,X={headers:i||{},withCredentials:L,file:o,data:p,method:r,filename:O,action:T,onProgress:I=>{U(I,o)},onSuccess:I=>{Ce(I,o),delete c.value[G]},onError:I=>{Se(I,o),delete c.value[G]}},J=Pe(X);c.value[G]=J,J instanceof Promise&&J.then(X.onSuccess,X.onError)},v=o=>{const p=o.target.files;!p||C(Array.from(p))},l=()=>{f.value||(y.value.value="",y.value.click())},n=()=>{l()};return t({abort:o=>{Ie(c.value).filter(o?([i])=>String(o.uid)===i:()=>!0).forEach(([i,F])=>{F instanceof XMLHttpRequest&&F.abort(),delete c.value[i]})},upload:h}),(o,p)=>(g(),E("div",{class:m([e(u).b(),e(u).m(o.listType),e(u).is("drag",o.drag)]),tabindex:"0",onClick:l,onKeydown:be(K(n,["self"]),["enter","space"])},[o.drag?(g(),D(St,{key:0,disabled:e(f),onFile:C},{default:_(()=>[R(o.$slots,"default")]),_:3},8,["disabled"])):R(o.$slots,"default",{key:1}),N("input",{ref_key:"inputRef",ref:y,class:m(e(u).e("input")),name:o.name,multiple:o.multiple,accept:o.accept,type:"file",onChange:v,onClick:p[0]||(p[0]=K(()=>{},["stop"]))},null,42,Lt)],42,Ft))}});var ie=H(_t,[["__file","/home/runner/work/element-plus/element-plus/packages/components/upload/src/upload-content.vue"]]);const ue="ElUpload",de=a=>{var t;(t=a.url)!=null&&t.startsWith("blob:")&&URL.revokeObjectURL(a.url)},Tt=(a,t)=>{const s=qe(a,"fileList",void 0,{passive:!0}),u=l=>s.value.find(n=>n.uid===l.uid);function f(l){var n;(n=t.value)==null||n.abort(l)}function c(l=["ready","uploading","success","fail"]){s.value=s.value.filter(n=>!l.includes(n.status))}const y=(l,n)=>{const d=u(n);!d||(console.error(l),d.status="fail",s.value.splice(s.value.indexOf(d),1),a.onError(l,d,s.value),a.onChange(d,s.value))},C=(l,n)=>{const d=u(n);!d||(a.onProgress(l,d,s.value),d.status="uploading",d.percentage=Math.round(l.percent))},h=(l,n)=>{const d=u(n);!d||(d.status="success",d.response=l,a.onSuccess(l,d,s.value),a.onChange(d,s.value))},$=l=>{ge(l.uid)&&(l.uid=Z());const n={name:l.name,percentage:0,status:"ready",size:l.size,raw:l,uid:l.uid};if(a.listType==="picture-card"||a.listType==="picture")try{n.url=URL.createObjectURL(l)}catch(d){Ke(ue,d.message),a.onError(d,n,s.value)}s.value=[...s.value,n],a.onChange(n,s.value)},w=async l=>{const n=l instanceof File?u(l):l;n||x(ue,"file to be removed not found");const d=o=>{f(o);const p=s.value;p.splice(p.indexOf(o),1),a.onRemove(o,p),de(o)};a.beforeRemove?await a.beforeRemove(n,s.value)!==!1&&d(n):d(n)};function v(){s.value.filter(({status:l})=>l==="ready").forEach(({raw:l})=>{var n;return l&&((n=t.value)==null?void 0:n.upload(l))})}return se(()=>a.listType,l=>{l!=="picture-card"&&l!=="picture"||(s.value=s.value.map(n=>{const{raw:d,url:o}=n;if(!o&&d)try{n.url=URL.createObjectURL(d)}catch(p){a.onError(p,n,s.value)}return n}))}),se(s,l=>{for(const n of l)n.uid||(n.uid=Z()),n.status||(n.status="success")},{immediate:!0,deep:!0}),{uploadFiles:s,abort:f,clearFiles:c,handleError:y,handleProgress:C,handleStart:$,handleSuccess:h,handleRemove:w,submit:v,revokeFileObjectURL:de}},Ut=j({name:"ElUpload"}),Dt=j({...Ut,props:ut,setup(a,{expose:t}){const s=a,u=V(),f=Y(),{abort:c,submit:y,clearFiles:C,uploadFiles:h,handleStart:$,handleError:w,handleRemove:v,handleSuccess:l,handleProgress:n,revokeFileObjectURL:d}=Tt(s,f),o=S(()=>s.listType==="picture-card"),p=S(()=>({...s,fileList:h.value,onStart:$,onProgress:n,onSuccess:l,onError:w,onRemove:v}));return ze(()=>{h.value.forEach(d)}),He(ke,{accept:We(s,"accept")}),t({abort:c,submit:y,clearFiles:C,handleStart:$,handleRemove:v}),(i,F)=>(g(),E("div",null,[e(o)&&i.showFileList?(g(),D(le,{key:0,disabled:e(u),"list-type":i.listType,files:e(h),"handle-preview":i.onPreview,onRemove:e(v)},ae({append:_(()=>[B(ie,ne({ref_key:"uploadRef",ref:f},e(p)),{default:_(()=>[i.$slots.trigger?R(i.$slots,"trigger",{key:0}):k("v-if",!0),!i.$slots.trigger&&i.$slots.default?R(i.$slots,"default",{key:1}):k("v-if",!0)]),_:3},16)]),_:2},[i.$slots.file?{name:"default",fn:_(({file:r})=>[R(i.$slots,"file",{file:r})])}:void 0]),1032,["disabled","list-type","files","handle-preview","onRemove"])):k("v-if",!0),!e(o)||e(o)&&!i.showFileList?(g(),D(ie,ne({key:1,ref_key:"uploadRef",ref:f},e(p)),{default:_(()=>[i.$slots.trigger?R(i.$slots,"trigger",{key:0}):k("v-if",!0),!i.$slots.trigger&&i.$slots.default?R(i.$slots,"default",{key:1}):k("v-if",!0)]),_:3},16)):k("v-if",!0),i.$slots.trigger?R(i.$slots,"default",{key:2}):k("v-if",!0),R(i.$slots,"tip"),!e(o)&&i.showFileList?(g(),D(le,{key:3,disabled:e(u),"list-type":i.listType,files:e(h),"handle-preview":i.onPreview,onRemove:e(v)},ae({_:2},[i.$slots.file?{name:"default",fn:_(({file:r})=>[R(i.$slots,"file",{file:r})])}:void 0]),1032,["disabled","list-type","files","handle-preview","onRemove"])):k("v-if",!0)]))}});var Ot=H(Dt,[["__file","/home/runner/work/element-plus/element-plus/packages/components/upload/src/upload.vue"]]);const Nt=me(Ot);export{Nt as E};