2 lines
8.7 KiB
JavaScript
2 lines
8.7 KiB
JavaScript
var Be=Object.defineProperty,Pe=Object.defineProperties;var Le=Object.getOwnPropertyDescriptors;var le=Object.getOwnPropertySymbols;var $e=Object.prototype.hasOwnProperty,Fe=Object.prototype.propertyIsEnumerable;var Z=(n,t,s)=>t in n?Be(n,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[t]=s,b=(n,t)=>{for(var s in t||(t={}))$e.call(t,s)&&Z(n,s,t[s]);if(le)for(var s of le(t))Fe.call(t,s)&&Z(n,s,t[s]);return n},j=(n,t)=>Pe(n,Le(t));var T=(n,t,s)=>Z(n,typeof t!="symbol"?t+"":t,s);var P=(n,t,s)=>new Promise((v,d)=>{var V=i=>{try{k(s.next(i))}catch(B){d(B)}},L=i=>{try{k(s.throw(i))}catch(B){d(B)}},k=i=>i.done?v(i.value):Promise.resolve(i.value).then(V,L);k((s=s.apply(n,t)).next())});import{cz as x,cy as Re,cn as Ee,R as O,i as Ge,cF as be,m as he,bC as ze,aa as m,bB as Ae,bZ as He,w as _e,v as Me,x as Ne,ad as Q,b2 as z,j as D,ag as ue,bJ as p,bb as ce,bc as f,ac as A,ae as de,ai as me,ab as pe,bp as X,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-Cy8amzIl.js";import{b6 as Ze,b1 as Qe,u as Xe,$ as H,bG as Ke,b3 as Ye,bH as et,aZ as tt,am as ot,b7 as st}from"./bootstrap-CW2RsBQq.js";import{u as at,V as ge,a as rt,b as nt,e as it}from"./vxe-table-D615zg_B.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 s=b({},t),v=lt();this.store=new Ze(x(s,v),{onUpdate:()=>{this.state=this.store.state}}),this.state=this.store.state,this.stateHandler=new Re,Ee(this)}mount(t,s){!this.isMounted&&t&&(this.grid=t,this.formApi=s,this.stateHandler.setConditionTrue(),this.isMounted=!0)}query(){return P(this,arguments,function*(t={}){try{yield this.grid.commitProxy("query",O(t))}catch(s){console.error("Error occurred while querying:",s)}})}reload(){return P(this,arguments,function*(t={}){try{yield this.grid.commitProxy("reload",O(t))}catch(s){console.error("Error occurred while reloading:",s)}})}setGridOptions(t){this.setState({gridOptions:t})}setLoading(t){this.setState({gridOptions:{loading:t}})}setState(t){Ge(t)?this.store.setState(s=>x(t(s),s)):this.store.setState(s=>x(t,s))}toggleSearchForm(t){var s,v;return this.setState({showSearchForm:be(t)?t:!((s=this.state)!=null&&s.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,se;const t=n,s=ze("gridRef"),v=(se=(M=t.api)==null?void 0:M.useStore)==null?void 0:se.call(M),{gridOptions:d,class:V,gridClass:L,gridEvents:k,formOptions:i,tableTitle:B,tableTitleHelp:ee,showSearchForm:$,separator:y}=Qe(t,v),{isMobile:ve}=Xe(),U=m(()=>!i.value||$.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=Ae(),[ye,c]=at({compact:!0,handleSubmit:()=>P(null,null,function*(){const e=yield c.getValues();c.setLatestSubmissionValues(O(e)),t.api.reload(e)}),handleReset:()=>P(null,null,function*(){var a;const e=yield c.getValues();yield c.resetForm();const o=yield c.getValues();c.setLatestSubmissionValues(o),(Ke(e,o)||!((a=i.value)!=null&&a.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))||B.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,R,E,G;const e=(g=l[q])==null?void 0:g.call(l),o=(h=l[I])==null?void 0:h.call(l),a={code:"search",icon:"vxe-icon-search",circle:!0,status:$.value?"primary":void 0,title:$.value?H("common.hideSearchPanel"):H("common.showSearchPanel")},u={tools:(R=(F=(w=d.value)==null?void 0:w.toolbarConfig)==null?void 0:F.tools)!=null?R:[]};return(G=(E=d.value)==null?void 0:E.toolbarConfig)!=null&&G.search&&i.value&&(u.tools=Array.isArray(u.tools)?[...u.tools,a]:[a]),W.value?(u.slots=b(b({},e||J.value?{buttons:q}:{}),o?{tools:I}:{}),{toolbarConfig:u}):{toolbarConfig:u}}),_=m(()=>{var a,u,g;const e=(g=(u=(a=ge)==null?void 0:a.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,a;e.code==="search"&&oe(),(a=(o=k.value)==null?void 0:o.toolbarToolClick)==null||a.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 P(this,null,function*(){var h,w,F,R,E,G,ae,re,ne,N,ie;yield Ue();const e=(F=(w=(h=ge)==null?void 0:h.getConfig())==null?void 0:w.grid)!=null?F:{},o=x({},O(d.value),O(e)),a=(R=o.proxyConfig)==null?void 0:R.autoLoad;((E=_.value.proxyConfig)==null?void 0:E.enabled)&&a&&((re=(ae=t.api.grid).commitProxy)==null||re.call(ae,"query",i.value?(G=yield c.getValues())!=null?G:{}:{}));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,s.value,c),Ve()}),Ne(()=>{var e,o,a;(e=c==null?void 0:c.unmount)==null||e.call(c),(a=(o=t.api)==null?void 0:o.unmount)==null||a.call(o)}),(e,o)=>(z(),Q("div",{class:fe(r(K)("bg-card h-full rounded-md",r(V)))},[D(r(nt),qe({ref_key:"gridRef",ref:s,class:r(K)("p-2",{"pt-0":W.value&&!r(i)},r(L))},_.value,Ie(we.value)),ue({"toolbar-tools":p(a=>{var u,g;return[f(e.$slots,"toolbar-tools",S(C(a))),(g=(u=r(d))==null?void 0:u.toolbarConfig)!=null&&g.search&&r(i)?(z(),pe(r(rt),{key:0,icon:"vxe-icon-search",circle:"",class:"ml-2",status:r($)?"primary":void 0,title:r(H)("common.search"),onClick:oe},null,8,["status","title"])):A("",!0)]}),form:p(()=>[r(i)?je((z(),Q("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(a=>[f(e.$slots,"reset-before",S(C(a)))]),"submit-before":p(a=>[f(e.$slots,"submit-before",S(C(a)))]),"expand-before":p(a=>[f(e.$slots,"expand-before",S(C(a)))]),"expand-after":p(a=>[f(e.$slots,"expand-after",S(C(a)))]),_:2},[ce(Oe.value,a=>({name:a,fn:p(u=>[f(e.$slots,`${Y}${a}`,S(C(u)))])}))]),1024)]),U.value?(z(),Q("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)):A("",!0)],2)),[[ot,r($)!==!1]]):A("",!0)]),loading:p(()=>[f(e.$slots,"loading",{},()=>[D(r(tt),{spinning:!0})])]),_:2},[W.value?{name:"toolbar-actions",fn:p(a=>[J.value?f(e.$slots,"table-title",{key:0},()=>[de("div",ct,[me(X(r(B))+" ",1),r(ee)?(z(),pe(r(Ye),{key:0,"trigger-class":"pb-1"},{default:p(()=>[me(X(r(ee)),1)]),_:1})):A("",!0)])]):A("",!0),f(e.$slots,"toolbar-actions",S(C(a)))]),key:"0"}:void 0,ce(Te.value,a=>({name:a,fn:p(u=>[f(e.$slots,a,S(C(u)))])})),xe.value?{name:"empty",fn:p(()=>[f(e.$slots,"empty",{},()=>[D(r(et),{class:"mx-auto"}),de("div",dt,X(r(H)("common.noData")),1)])]),key:"1"}:void 0]),1040,["class"])],2))}});function vt(n){const t=new ut(n),s=t;return s.useStore=d=>st(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:s}),L)),{name:"VbenVxeGrid",inheritAttrs:!1,slots:Object}),s]}export{vt as u};
|