useTable-944d6584.js 8.9 KB

1
  1. import{d as ae,ar as c,r as _,b as pe,a,e as R,w as $,k as ue,Z as ge,f as g,Y as me,m as K,O as he,X as W,Q as ne,cM as fe,b5 as ye,o as P,c as H,aZ as we,R as be,B as k,aN as J,A as M,E as B,G as N,D as z,aG as xe,F as ve,_ as _e,K as Pe,x as Se,bl as oe,bm as re,n as Ae,__tla as ke}from"./index-e8bff8cb.js";import{g as D,_ as ze,__tla as Le}from"./Form-50cf5525.js";import{E as Oe,__tla as Te}from"./index-35928fe5.js";import{_ as Ce}from"./_plugin-vue_export-helper-1b428a4d.js";import{u as je,__tla as Fe}from"./useForm-1e4c828f.js";import{d as Re}from"./download-20922b56.js";let le,se,ie,$e=Promise.all([(()=>{try{return ke}catch{}})(),(()=>{try{return Le}catch{}})(),(()=>{try{return Te}catch{}})(),(()=>{try{return Fe}catch{}})()]).then(async()=>{let V,y;se=Ce(ae({name:"Table",props:{pageSize:c.number.def(10),currentPage:c.number.def(1),selection:c.bool.def(!1),showOverflowTooltip:c.bool.def(!0),columns:{type:Array,default:()=>[]},expand:c.bool.def(!1),pagination:{type:Object,default:()=>{}},reserveSelection:c.bool.def(!1),loading:c.bool.def(!1),reserveIndex:c.bool.def(!1),align:c.string.validate(e=>["left","center","right"].includes(e)).def("center"),headerAlign:c.string.validate(e=>["left","center","right"].includes(e)).def("center"),data:{type:Array,default:()=>[]}},emits:["update:pageSize","update:currentPage","register"],setup(e,{attrs:o,slots:p,emit:m,expose:L}){const u=_();pe(()=>{const t=a(u);m("register",t==null?void 0:t.$parent,u)});const b=_(e.pageSize),h=_(e.currentPage),n=_({}),r=_({}),l=R(()=>{const t={...e};return Object.assign(t,a(r)),t}),x=(t,O)=>{var S;const{columns:T}=a(l);for(const C of O||T)for(const j of t)C.field===j.field?he(C,j.path,j.value):(S=C.children)!=null&&S.length&&x(t,C.children)},q=_([]),E=t=>{q.value=t};L({setProps:(t={})=>{r.value=Object.assign(a(r),t),n.value=t},setColumn:x,selections:q});const s=R(()=>Object.assign({small:!1,background:!0,pagerCount:document.body.clientWidth<992?5:7,layout:"total, sizes, prev, pager, next, jumper",pageSizes:[10,20,30,50,100],disabled:!1,hideOnSinglePage:!1,total:10},a(l).pagination));$(()=>a(l).pageSize,t=>{b.value=t}),$(()=>a(l).currentPage,t=>{h.value=t}),$(()=>b.value,t=>{m("update:pageSize",t)}),$(()=>h.value,t=>{m("update:currentPage",t)});const v=R(()=>{const t={...o,...e};return delete t.columns,delete t.data,t}),d=()=>{const{selection:t,reserveSelection:O,align:T,headerAlign:S}=a(l);return t?g(W,{type:"selection",reserveSelection:O,align:T,headerAlign:S,width:"50"},null):void 0},w=()=>{const{align:t,headerAlign:O,expand:T}=a(l);return T?g(W,{type:"expand",align:t,headerAlign:O},{default:S=>D(p,"expand",S)}):void 0},G=t=>{const{columns:O,reserveIndex:T,pageSize:S,currentPage:C,align:j,headerAlign:ee,showOverflowTooltip:ce}=a(l);return[w(),d()].concat((t||O).map(i=>{if(i.type==="index")return g(W,{type:"index",index:i.index?i.index:I=>((A,U,Q,X)=>{const Z=U+1;return A?Q*(X-1)+Z:Z})(T,I,S,C),align:i.align||j,headerAlign:i.headerAlign||ee,label:i.label,width:"65px"},null);{const I={...i};return I.children&&delete I.children,g(W,K({showOverflowTooltip:ce,align:j,headerAlign:ee},I,{prop:i.field}),{default:A=>{var U;return i.children&&i.children.length?(Q=>{const{align:X,headerAlign:Z,showOverflowTooltip:de}=a(l);return Q.map(f=>{const Y={...f};return Y.children&&delete Y.children,g(W,K({showOverflowTooltip:de,align:X,headerAlign:Z},Y,{prop:f.field}),{default:F=>{var te;return f.children&&f.children.length?G(f.children):D(p,f.field,F)||((te=f==null?void 0:f.formatter)==null?void 0:te.call(f,F.row,F.column,F.row[f.field],F.$index))||F.row[f.field]},header:D(p,`${f.field}-header`)})})})(i.children):D(p,i.field,A)||((U=i==null?void 0:i.formatter)==null?void 0:U.call(i,A.row,A.column,A.row[i.field],A.$index))||A.row[i.field]},header:()=>D(p,`${i.field}-header`)||i.label})}}))};return()=>ue(g("div",null,[g(me,K({ref:u,data:a(l).data,"onSelection-change":E},a(v)),{default:()=>G(),append:()=>D(p,"append")}),a(l).pagination?g(Oe,K({pageSize:b.value,"onUpdate:pageSize":t=>b.value=t,currentPage:h.value,"onUpdate:currentPage":t=>h.value=t,class:"float-right mb-15px mt-15px"},a(s)),null):void 0]),[[ge,a(l).loading]])}}),[["__scopeId","data-v-ade6697d"]]),V={key:0},le=ae({name:"Search",__name:"Search",props:{schema:{type:Array,default:()=>[]},isCol:c.bool.def(!1),labelWidth:c.oneOfType([String,Number]).def("auto"),layout:c.string.validate(e=>["inline","bottom"].includes(e)).def("inline"),buttomPosition:c.string.validate(e=>["left","center","right"].includes(e)).def("center"),showSearch:c.bool.def(!0),showReset:c.bool.def(!0),expand:c.bool.def(!1),expandField:c.string.def(""),inline:c.bool.def(!0),model:{type:Object,default:()=>({})}},emits:["search","reset"],setup(e,{emit:o}){const{t:p}=ne(),m=e,L=o,u=_(!0),b=R(()=>{let s=fe(m.schema);if(m.expand&&m.expandField&&!a(u)){const v=ye(s,d=>d.field===m.expandField);if(v>-1){const d=s.length;s.splice(v+1,d)}}return m.layout==="inline"&&(s=s.concat([{field:"action",formItemProps:{labelWidth:"0px"}}])),s}),{register:h,elFormRef:n,methods:r}=je({model:m.model||{}}),l=async()=>{var s;await((s=a(n))==null?void 0:s.validate(async v=>{if(v){const{getFormData:d}=r,w=await d();L("search",w)}}))},x=async()=>{var d;(d=a(n))==null||d.resetFields();const{getFormData:s}=r,v=await s();L("reset",v)},q=R(()=>({textAlign:m.buttomPosition})),E=()=>{var s;(s=a(n))==null||s.resetFields(),u.value=!a(u)};return(s,v)=>{const d=_e,w=Pe,G=ze;return P(),H(ve,null,[g(G,{inline:e.inline,"is-col":e.isCol,"is-custom":!1,"label-width":e.labelWidth,schema:a(b),class:"-mb-15px","hide-required-asterisk":"",onRegister:a(h)},we({action:k(()=>[e.layout==="inline"?(P(),H("div",V,[e.showSearch?(P(),M(w,{key:0,onClick:l},{default:k(()=>[g(d,{class:"mr-5px",icon:"ep:search"}),B(" "+N(a(p)("common.query")),1)]),_:1})):z("",!0),e.showReset?(P(),M(w,{key:1,onClick:x},{default:k(()=>[g(d,{class:"mr-5px",icon:"ep:refresh"}),B(" "+N(a(p)("common.reset")),1)]),_:1})):z("",!0),e.expand?(P(),M(w,{key:2,text:"",onClick:E},{default:k(()=>[B(N(a(p)(a(u)?"common.shrink":"common.expand"))+" ",1),g(d,{icon:a(u)?"ep:arrow-up":"ep:arrow-down"},null,8,["icon"])]),_:1})):z("",!0),J(s.$slots,"actionMore")])):z("",!0)]),_:2},[be(Object.keys(s.$slots),t=>({name:t,fn:k(()=>[J(s.$slots,t)])}))]),1032,["inline","is-col","label-width","schema","onRegister"]),e.layout==="bottom"?(P(),H("div",{key:0,style:xe(a(q))},[e.showSearch?(P(),M(w,{key:0,type:"primary",onClick:l},{default:k(()=>[g(d,{class:"mr-5px",icon:"ep:search"}),B(" "+N(a(p)("common.query")),1)]),_:1})):z("",!0),e.showReset?(P(),M(w,{key:1,onClick:x},{default:k(()=>[g(d,{class:"mr-5px",icon:"ep:refresh-right"}),B(" "+N(a(p)("common.reset")),1)]),_:1})):z("",!0),e.expand?(P(),M(w,{key:2,text:"",onClick:E},{default:k(()=>[B(N(a(p)(a(u)?"common.shrink":"common.expand"))+" ",1),g(d,{icon:a(u)?"ep:arrow-up":"ep:arrow-down"},null,8,["icon"])]),_:1})):z("",!0),J(s.$slots,"actionMore")],4)):z("",!0)],64)}}}),{t:y}=ne(),ie=e=>{const o=Se({pageSize:10,currentPage:1,total:10,tableList:[],params:{...(e==null?void 0:e.defaultParams)||{}},loading:!0,exportLoading:!1,currentRow:null}),p=R(()=>({...o.params,pageSize:o.pageSize,pageNo:o.currentPage}));$(()=>o.currentPage,()=>{h.getList()}),$(()=>o.pageSize,()=>{o.currentPage===1||(o.currentPage=1),h.getList()});const m=_(),L=_(),u=async()=>{await Ae();const n=a(m);return n||console.error("The table is not registered. Please use the register method to register"),n},b=async n=>{let r=1;n instanceof Array?(r=n.length,await Promise.all(n.map(async l=>{await((e==null?void 0:e.delListApi)&&(e==null?void 0:e.delListApi(l)))}))):await((e==null?void 0:e.delListApi)&&(e==null?void 0:e.delListApi(n))),oe.success(y("common.delSuccess")),o.currentPage=(o.total%o.pageSize===r||o.pageSize===1)&&o.currentPage>1?o.currentPage-1:o.currentPage,await h.getList()},h={getList:async()=>{o.loading=!0;const n=await(e==null?void 0:e.getListApi(a(p)).finally(()=>{o.loading=!1}));n&&(o.tableList=n.list,o.total=n.total??0)},setProps:async(n={})=>{const r=await u();r==null||r.setProps(n)},setColumn:async n=>{const r=await u();r==null||r.setColumn(n)},getSelections:async()=>{const n=await u();return(n==null?void 0:n.selections)||[]},setSearchParams:n=>{o.params=Object.assign(o.params,{pageSize:o.pageSize,pageNo:1,...n}),o.currentPage!==1?o.currentPage=1:h.getList()},delList:async(n,r,l=!0)=>{const x=await u();!r||x!=null&&x.selections.length?l?re.confirm(y("common.delMessage"),y("common.confirmTitle"),{confirmButtonText:y("common.ok"),cancelButtonText:y("common.cancel"),type:"warning"}).then(async()=>{await b(n)}):await b(n):oe.warning(y("common.delNoData"))},exportList:async n=>{o.exportLoading=!0,re.confirm(y("common.exportMessage"),y("common.confirmTitle"),{confirmButtonText:y("common.ok"),cancelButtonText:y("common.cancel"),type:"warning"}).then(async()=>{var l;const r=await((l=e==null?void 0:e.exportListApi)==null?void 0:l.call(e,a(p)));r&&Re.excel(r,n)}).finally(()=>{o.exportLoading=!1})}};return e!=null&&e.props&&h.setProps(e.props),{register:(n,r)=>{m.value=n,L.value=r},elTableRef:L,tableObject:o,methods:h,tableMethods:h}}});export{le as _,$e as __tla,se as a,ie as u};