2 lines
8.7 KiB
JavaScript
2 lines
8.7 KiB
JavaScript
var Pe=Object.defineProperty,Be=Object.defineProperties;var Le=Object.getOwnPropertyDescriptors;var le=Object.getOwnPropertySymbols;var Re=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable;var Q=(n,t,a)=>t in n?Pe(n,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):n[t]=a,b=(n,t)=>{for(var a in t||(t={}))Re.call(t,a)&&Q(n,a,t[a]);if(le)for(var a of le(t))$e.call(t,a)&&Q(n,a,t[a]);return n},j=(n,t)=>Be(n,Le(t));var T=(n,t,a)=>Q(n,typeof t!="symbol"?t+"":t,a);var B=(n,t,a)=>new Promise((v,d)=>{var V=i=>{try{k(a.next(i))}catch(P){d(P)}},L=i=>{try{k(a.throw(i))}catch(P){d(P)}},k=i=>i.done?v(i.value):Promise.resolve(i.value).then(V,L);k((a=a.apply(n,t)).next())});import{cz as x,cy as Fe,cn as Ee,R as O,i as ze,cF as be,m as he,bC as Ae,aa as m,bB as Ge,bZ as He,w as _e,v as Me,x as Ne,ad as X,b2 as A,j as D,ag as ue,bJ as p,bb as ce,bc as f,ac as G,ae as de,ai as me,ab as pe,bp as Z,u as r,aS as S,aw as C,bL as je,aR as fe,cd as K,aT as De,aQ as qe,br as Ie,n as Ue,aW as Je,L as We}from"../jse/index-index-CMeVxoEG.js";import{aP as Qe,aQ as Xe,u as Ze,$ as H,aR as Ke,aS as Ye,aT as et,aU as tt,am as ot,aV as at}from"./bootstrap-CRjSNGHY.js";import{u as st,V as ge,a as rt,b as nt,e as it}from"./vxe-table-uq8U2E1u.js";function lt(){return{class:"",gridClass:"",gridOptions:{},gridEvents:{},formOptions:void 0,showSearchForm:!0}}class ut{constructor(t={}){T(this,"formApi",{});T(this,"grid",{});T(this,"state",null);T(this,"store");T(this,"isMounted",!1);T(this,"stateHandler");const a=b({},t),v=lt();this.store=new Qe(x(a,v),{onUpdate:()=>{this.state=this.store.state}}),this.state=this.store.state,this.stateHandler=new Fe,Ee(this)}mount(t,a){!this.isMounted&&t&&(this.grid=t,this.formApi=a,this.stateHandler.setConditionTrue(),this.isMounted=!0)}query(){return B(this,arguments,function*(t={}){try{yield this.grid.commitProxy("query",O(t))}catch(a){console.error("Error occurred while querying:",a)}})}reload(){return B(this,arguments,function*(t={}){try{yield this.grid.commitProxy("reload",O(t))}catch(a){console.error("Error occurred while reloading:",a)}})}setGridOptions(t){this.setState({gridOptions:t})}setLoading(t){this.setState({gridOptions:{loading:t}})}setState(t){ze(t)?this.store.setState(a=>x(t(a),a)):this.store.setState(a=>x(t,a))}toggleSearchForm(t){var a,v;return this.setState({showSearchForm:be(t)?t:!((a=this.state)!=null&&a.showSearchForm)}),(v=this.state)==null?void 0:v.showSearchForm}unmount(){this.isMounted=!1,this.stateHandler.reset()}}const ct={class:"mr-1 pl-1 text-[1rem]"},dt={class:"mt-2"},Y="form-",q="toolbar-actions",I="toolbar-tools",mt="table-title",pt=he({__name:"use-vxe-grid",props:{api:{},tableTitle:{},tableTitleHelp:{},class:{},gridClass:{},gridOptions:{},gridEvents:{},formOptions:{},showSearchForm:{type:Boolean},separator:{type:[Boolean,Object]}},setup(n){var M,ae;const t=n,a=Ae("gridRef"),v=(ae=(M=t.api)==null?void 0:M.useStore)==null?void 0:ae.call(M),{gridOptions:d,class:V,gridClass:L,gridEvents:k,formOptions:i,tableTitle:P,tableTitleHelp:ee,showSearchForm:R,separator:y}=Xe(t,v),{isMobile:ve}=Ze(),U=m(()=>!i.value||R.value===!1||y.value===!1?!1:y.value===!0||y.value===void 0?!0:y.value.show!==!1),te=m(()=>!y.value||be(y.value)||!y.value.backgroundColor?void 0:y.value.backgroundColor),l=Ge(),[ye,c]=st({compact:!0,handleSubmit:()=>B(null,null,function*(){const e=yield c.getValues();c.setLatestSubmissionValues(O(e)),t.api.reload(e)}),handleReset:()=>B(null,null,function*(){var s;const e=yield c.getValues();yield c.resetForm();const o=yield c.getValues();c.setLatestSubmissionValues(o),(Ke(e,o)||!((s=i.value)!=null&&s.submitOnChange))&&t.api.reload(o)}),commonConfig:{componentProps:{class:"w-full"}},showCollapseButton:!0,submitButtonOptions:{content:m(()=>H("common.search"))},wrapperClass:"grid-cols-1 md:grid-cols-2 lg:grid-cols-3"}),J=m(()=>{var e;return!!((e=l[mt])!=null&&e.call(l))||P.value}),W=m(()=>{var e,o;return!!((e=l[q])!=null&&e.call(l))||!!((o=l[I])!=null&&o.call(l))||J.value}),Se=m(()=>{var g,h,w,$,F,E,z;const e=(g=l[q])==null?void 0:g.call(l),o=(h=l[I])==null?void 0:h.call(l),s={code:"search",icon:"vxe-icon-search",circle:!0,status:R.value?"primary":void 0,title:R.value?H("common.hideSearchPanel"):H("common.showSearchPanel")},u={tools:(F=($=(w=d.value)==null?void 0:w.toolbarConfig)==null?void 0:$.tools)!=null?F:[]};return(z=(E=d.value)==null?void 0:E.toolbarConfig)!=null&&z.search&&i.value&&(u.tools=Array.isArray(u.tools)?[...u.tools,s]:[s]),W.value?(u.slots=b(b({},e||J.value?{buttons:q}:{}),o?{tools:I}:{}),{toolbarConfig:u}):{toolbarConfig:u}}),_=m(()=>{var s,u,g;const e=(g=(u=(s=ge)==null?void 0:s.getConfig())==null?void 0:u.grid)!=null?g:{},o=He(x({},O(Se.value),O(d.value),e));if(o.proxyConfig){const{ajax:h}=o.proxyConfig;o.proxyConfig.enabled=!!h,o.proxyConfig.autoLoad=!1}if(o.pagerConfig){const h=["PrevJump","PrevPage","Number","NextPage","NextJump"],w=["Total","Sizes","Home",...h,"End"];o.pagerConfig=x({},o.pagerConfig,{pageSize:20,background:!0,pageSizes:[10,20,30,50,100,200],className:"mt-2 w-full",layouts:ve.value?h:w,size:"mini"})}return o.formConfig&&(o.formConfig.enabled=!1),o});function Ce(e){var o,s;e.code==="search"&&oe(),(s=(o=k.value)==null?void 0:o.toolbarToolClick)==null||s.call(o,e)}function oe(){var e,o;(o=(e=t.api)==null?void 0:e.toggleSearchForm)==null||o.call(e)}const we=m(()=>j(b({},k.value),{toolbarToolClick:Ce})),Te=m(()=>{const e=[];for(const o of Object.keys(l))["empty","form","loading",q,I].includes(o)||e.push(o);return e}),Oe=m(()=>{const e=[];for(const o of Object.keys(l))o.startsWith(Y)&&e.push(o);return e.map(o=>o.replace(Y,""))}),xe=m(()=>{const e=_.value.emptyText!==void 0,o=_.value.emptyRender!==void 0;return!e&&!o});function Ve(){return B(this,null,function*(){var h,w,$,F,E,z,se,re,ne,N,ie;yield Ue();const e=($=(w=(h=ge)==null?void 0:h.getConfig())==null?void 0:w.grid)!=null?$:{},o=x({},O(d.value),O(e)),s=(F=o.proxyConfig)==null?void 0:F.autoLoad;((E=_.value.proxyConfig)==null?void 0:E.enabled)&&s&&((re=(se=t.api.grid).commitProxy)==null||re.call(se,"query",i.value?(z=yield c.getValues())!=null?z:{}:{}));const g=(ne=d.value)==null?void 0:ne.formConfig;g&&g.enabled&&console.warn("[Vben Vxe Table]: The formConfig in the grid is not supported, please use the `formOptions` props"),(ie=(N=t.api)==null?void 0:N.setState)==null||ie.call(N,{gridOptions:o}),it(t.api,o,()=>c.getLatestSubmissionValues())})}_e(i,()=>{c.setState(e=>{const o=x({},i.value,e);return j(b({},o),{collapseTriggerResize:!!o.showCollapseButton})})},{immediate:!0});const ke=m(()=>{var e;return(e=c.getState())==null?void 0:e.compact});return Me(()=>{var e,o;(o=(e=t.api)==null?void 0:e.mount)==null||o.call(e,a.value,c),Ve()}),Ne(()=>{var e,o,s;(e=c==null?void 0:c.unmount)==null||e.call(c),(s=(o=t.api)==null?void 0:o.unmount)==null||s.call(o)}),(e,o)=>(A(),X("div",{class:fe(r(K)("bg-card h-full rounded-md",r(V)))},[D(r(nt),qe({ref_key:"gridRef",ref:a,class:r(K)("p-2",{"pt-0":W.value&&!r(i)},r(L))},_.value,Ie(we.value)),ue({"toolbar-tools":p(s=>{var u,g;return[f(e.$slots,"toolbar-tools",S(C(s))),(g=(u=r(d))==null?void 0:u.toolbarConfig)!=null&&g.search&&r(i)?(A(),pe(r(rt),{key:0,icon:"vxe-icon-search",circle:"",class:"ml-2",status:r(R)?"primary":void 0,title:r(H)("common.search"),onClick:oe},null,8,["status","title"])):G("",!0)]}),form:p(()=>[r(i)?je((A(),X("div",{key:0,class:fe(r(K)("relative rounded py-3",ke.value?U.value?"pb-8":"pb-4":U.value?"pb-4":"pb-0"))},[f(e.$slots,"form",{},()=>[D(r(ye),null,ue({"reset-before":p(s=>[f(e.$slots,"reset-before",S(C(s)))]),"submit-before":p(s=>[f(e.$slots,"submit-before",S(C(s)))]),"expand-before":p(s=>[f(e.$slots,"expand-before",S(C(s)))]),"expand-after":p(s=>[f(e.$slots,"expand-after",S(C(s)))]),_:2},[ce(Oe.value,s=>({name:s,fn:p(u=>[f(e.$slots,`${Y}${s}`,S(C(u)))])}))]),1024)]),U.value?(A(),X("div",{key:0,style:De(b({},te.value?{backgroundColor:te.value}:void 0)),class:"bg-background-deep z-100 absolute -left-2 bottom-1 h-2 w-[calc(100%+1rem)] overflow-hidden md:bottom-2 md:h-3"},null,4)):G("",!0)],2)),[[ot,r(R)!==!1]]):G("",!0)]),loading:p(()=>[f(e.$slots,"loading",{},()=>[D(r(tt),{spinning:!0})])]),_:2},[W.value?{name:"toolbar-actions",fn:p(s=>[J.value?f(e.$slots,"table-title",{key:0},()=>[de("div",ct,[me(Z(r(P))+" ",1),r(ee)?(A(),pe(r(Ye),{key:0,"trigger-class":"pb-1"},{default:p(()=>[me(Z(r(ee)),1)]),_:1})):G("",!0)])]):G("",!0),f(e.$slots,"toolbar-actions",S(C(s)))]),key:"0"}:void 0,ce(Te.value,s=>({name:s,fn:p(u=>[f(e.$slots,s,S(C(u)))])})),xe.value?{name:"empty",fn:p(()=>[f(e.$slots,"empty",{},()=>[D(r(et),{class:"mx-auto"}),de("div",dt,Z(r(H)("common.noData")),1)])]),key:"1"}:void 0]),1040,["class"])],2))}});function vt(n){const t=new ut(n),a=t;return a.useStore=d=>at(t.store,d),[he((d,{attrs:V,slots:L})=>(Je(()=>{t.unmount()}),t.setState(b(b({},d),V)),()=>We(pt,j(b(b({},d),V),{api:a}),L)),{name:"VbenVxeGrid",inheritAttrs:!1,slots:Object}),a]}export{vt as u};
|