useTable-b75776d4.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,X as ge,f as g,W as me,m as V,N as he,V as I,H as ne,cR as fe,b5 as ye,o as P,c as K,aZ as we,P as be,B as k,aN as Q,A as N,G as B,D as M,E as L,aG as xe,F as ve,_ as _e,L as Pe,x as Se,bl as oe,bm as re,n as Ae,__tla as ke}from"./index-631574a1.js";import{g as W,_ as Le,__tla as ze}from"./Form-933b72c2.js";import{E as Oe,__tla as Te}from"./index-f73f70f0.js";import{_ as Ce}from"./_plugin-vue_export-helper-1b428a4d.js";import{u as je,__tla as Fe}from"./useForm-df85d408.js";import{d as Re}from"./download-20922b56.js";let le,se,ie,$e=Promise.all([(()=>{try{return ke}catch{}})(),(()=>{try{return ze}catch{}})(),(()=>{try{return Te}catch{}})(),(()=>{try{return Fe}catch{}})()]).then(async()=>{let Y,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:z}){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};z({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(I,{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(I,{type:"expand",align:t,headerAlign:O},{default:S=>W(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(I,{type:"index",index:i.index?i.index:D=>((A,U,X,Z)=>{const H=U+1;return A?X*(Z-1)+H:H})(T,D,S,C),align:i.align||j,headerAlign:i.headerAlign||ee,label:i.label,width:"65px"},null);{const D={...i};return D.children&&delete D.children,g(I,V({showOverflowTooltip:ce,align:j,headerAlign:ee},D,{prop:i.field}),{default:A=>{var U;return i.children&&i.children.length?(X=>{const{align:Z,headerAlign:H,showOverflowTooltip:de}=a(l);return X.map(f=>{const J={...f};return J.children&&delete J.children,g(I,V({showOverflowTooltip:de,align:Z,headerAlign:H},J,{prop:f.field}),{default:F=>{var te;return f.children&&f.children.length?G(f.children):W(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:W(p,`${f.field}-header`)})})})(i.children):W(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:()=>W(p,`${i.field}-header`)||i.label})}}))};return()=>ue(g("div",null,[g(me,V({ref:u,data:a(l).data,"onSelection-change":E},a(v)),{default:()=>G(),append:()=>W(p,"append")}),a(l).pagination?g(Oe,V({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"]]),Y={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,z=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();z("search",w)}}))},x=async()=>{var d;(d=a(n))==null||d.resetFields();const{getFormData:s}=r,v=await s();z("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=Le;return P(),K(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(),K("div",Y,[e.showSearch?(P(),N(w,{key:0,onClick:l},{default:k(()=>[g(d,{class:"mr-5px",icon:"ep:search"}),B(" "+M(a(p)("common.query")),1)]),_:1})):L("",!0),e.showReset?(P(),N(w,{key:1,onClick:x},{default:k(()=>[g(d,{class:"mr-5px",icon:"ep:refresh"}),B(" "+M(a(p)("common.reset")),1)]),_:1})):L("",!0),e.expand?(P(),N(w,{key:2,text:"",onClick:E},{default:k(()=>[B(M(a(p)(a(u)?"common.shrink":"common.expand"))+" ",1),g(d,{icon:a(u)?"ep:arrow-up":"ep:arrow-down"},null,8,["icon"])]),_:1})):L("",!0),Q(s.$slots,"actionMore")])):L("",!0)]),_:2},[be(Object.keys(s.$slots),t=>({name:t,fn:k(()=>[Q(s.$slots,t)])}))]),1032,["inline","is-col","label-width","schema","onRegister"]),e.layout==="bottom"?(P(),K("div",{key:0,style:xe(a(q))},[e.showSearch?(P(),N(w,{key:0,type:"primary",onClick:l},{default:k(()=>[g(d,{class:"mr-5px",icon:"ep:search"}),B(" "+M(a(p)("common.query")),1)]),_:1})):L("",!0),e.showReset?(P(),N(w,{key:1,onClick:x},{default:k(()=>[g(d,{class:"mr-5px",icon:"ep:refresh-right"}),B(" "+M(a(p)("common.reset")),1)]),_:1})):L("",!0),e.expand?(P(),N(w,{key:2,text:"",onClick:E},{default:k(()=>[B(M(a(p)(a(u)?"common.shrink":"common.expand"))+" ",1),g(d,{icon:a(u)?"ep:arrow-up":"ep:arrow-down"},null,8,["icon"])]),_:1})):L("",!0),Q(s.$slots,"actionMore")],4)):L("",!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=_(),z=_(),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,z.value=r},elTableRef:z,tableObject:o,methods:h,tableMethods:h}}});export{le as _,$e as __tla,se as a,ie as u};