import{E as x}from"./eleVendor-48a7d3b8-1782572373740v=1.0.0.js";import{y as S,V as A,r as p,al as n,z as D,A as M,R as r,J as d,u as i,C as z,O as N,F as U,M as O,B as P,P as R,k as $,Q as j}from"./vendor-866bb149-1782572373740v=1.0.0.js";const L={style:{color:"red"}},J=S({__name:"index",props:{uploadFn:{type:Function,required:!0},maxSizeMB:{type:Number,default:999},allowedExt:{type:Array,default:()=>[".xls",".xlsx"]},validateFn:{type:Function,default:void 0},disabled:{type:Boolean,default:!1},extraParams:{type:Object,default:()=>({})},beforeUpload:{type:Function,default:()=>!0}},emits:["beforeValidate","validateSuccess","validateFail","uploadSuccess","uploadError","change"],setup(m,{emit:_}){const l=m,u=_,y=A(),g=p(),c=p(!1);function E(e=""){const t=e.lastIndexOf(".");return t===-1?"":e.slice(t).toLowerCase()}function B(e){return e*1024*1024}function C(e){const t=E(e.name);return l.allowedExt.map(o=>o.toLowerCase()).includes(t)?e.size>B(l.maxSizeMB)?{ok:!1,err:`\u6587\u4EF6\u8D85\u8FC7\u6700\u5927\u9650\u5236 ${l.maxSizeMB}MB`}:{ok:!0}:{ok:!1,err:`\u6587\u4EF6\u540E\u7F00\u4E0D\u652F\u6301\uFF08\u5141\u8BB8\uFF1A${l.allowedExt.join(", ")})`}}async function w(e){}async function v(e,t){c.value=!0;try{const o=new FormData;o.append("file",e);const a=await l.uploadFn(o,l.extraParams);a.code==0?u("uploadSuccess",a.data):a.code===998?(F.value=a.data,F.value,f.value=!0,u("uploadError",a.msg)):(x.error(a.msg),u("uploadError",a.msg))}catch(o){console.error({err:o}),u("uploadError",o)}finally{c.value=!1}}const f=p(!1),F=p([]);async function h(e,t){if(!l.beforeUpload(e.raw))return!1;e.raw&&u("change",e.raw);const a=e.raw;u("beforeValidate",a);const s=C(a);return s.ok?(await v(a),!1):(u("validateFail",[s.err]),x.error(s.err),!1)}return(e,t)=>{const o=n("el-button"),a=n("el-upload"),s=n("el-table-column"),V=n("el-table"),k=n("el-dialog");return D(),M(j,null,[r(a,U(i(y),{ref_key:"uploadRef",ref:g,"before-upload":w,"show-file-list":!1,"auto-upload":!1,disabled:m.disabled||i(c),accept:".xls,.xlsx","on-change":h,multiple:!1}),{default:d(()=>[r(o,{loading:i(c),disabled:m.disabled,type:"primary"},{default:d(()=>[z(e.$slots,"default",{},()=>[t[1]||(t[1]=N("\u5BFC\u5165",-1))])]),_:3},8,["loading","disabled"])]),_:3},16,["disabled"]),O(" \u5BFC\u51FA\u9519\u8BEF\u7684\u5F39\u7A97\uFF0C\u9519\u8BEF\u4F7F\u7528\u8868\u683C\u5C55\u793A "),r(k,{modelValue:i(f),"onUpdate:modelValue":t[0]||(t[0]=b=>$(f)?f.value=b:null),top:"25vh",title:"\u5BFC\u5165\u5931\u8D25\u539F\u56E0",width:"50%"},{default:d(()=>[r(V,{data:i(F)},{default:d(()=>[r(s,{label:"\u5E8F\u53F7",type:"index",width:"60"}),r(s,{label:"\u9519\u8BEF\u4FE1\u606F",prop:"message"},{default:d(({row:b})=>[P("div",L,R(b),1)]),_:1})]),_:1},8,["data"])]),_:1},8,["modelValue"])],64)}}});export{J as _};
