import{r as v,l as t,a4 as g,aj as $,bb as J,ay as F,aw as Q,ci as w,dd as W,d as A,bU as H,j as C,aq as X,aa as Y,h as ee,o as te,i as ae,w as L,p as ne,W as oe}from"./index-9PRMimni.js";import{c as se}from"./componentSetting-DVhNDBTO.js";import{g as ue}from"./list-I2I5D8gr.js";function ce(s){const o=v(t(s.value.columns));return{getColumnsRef:g(()=>$(t(o)))}}const{table:re}=se,{apiSetting:le,defaultPageSize:ie,pageSizes:fe}=re,B=ie,y=le,ge=fe;function de(s,{getPaginationInfo:o,setPagination:n,setLoading:c,tableData:r},i){const a=v([]);J(()=>{r.value=t(a)}),F(()=>t(s).dataSource,()=>{const{dataSource:e,requestData:d}=t(s);!d&&e&&(a.value=e)},{immediate:!0});const S=g(()=>{const{rowKey:e}=t(s);return e||(()=>"key")}),u=g(()=>{const{rowClassName:e}=t(s);return e}),f=g(()=>{const e=t(a);return!e||e.length===0?t(a):t(a)});async function m(e,d){try{c(!0);const{requestData:l,pagination:p}=t(s);if(!l)return;const _=y.pageField,K=y.sizeField,M=y.totalField,N=y.listField,O=y.countField;let D={};const{page:k=1,pageSize:z=B}=t(o);w(p)&&!p||w(o)?D={}:(D[_]=e&&e[_]||k,D[K]=z);const E={...D,...e};d&&(E[_]=1,n({page:1}));const h=await l(E),P=h[M],Z=h[_],T=h[O],I=h[N]?h[N]:[];if(P){const q=Math.ceil(T/z);if(k>q)return n({page:q,itemCount:T}),await m(e)}a.value=I,n({page:Z,pageCount:P,itemCount:T}),e&&e[_]&&n({page:e[_]||1}),i("fetch-success",{items:t(I),resultTotal:P})}catch(l){console.error(l),i("fetch-error",l),a.value=[],n({pageCount:0})}finally{c(!1)}}Q(()=>{setTimeout(()=>{m()},16)});function b(e){a.value=e}function R(){return f.value}async function U(e){await m(e)}async function j(e){await m(e,!0)}async function V(e,d,l){return a.value[e]&&(a.value[e][d]=l),a.value[e]}function G(e,d){if(!a.value||a.value.length===0)return;const l=a.value[e]||[];if(l){for(const p in l)Reflect.has(d,p)&&(l[p]=d[p]);return l}}function x(e){!a.value||a.value.length==0||e>=0&&a.value.splice(e,1)}return{fetch:m,getRowKey:S,getRowClassName:u,getDataSourceRef:f,getDataSource:R,setTableData:b,reload:U,restReload:j,updateTableData:V,updateTableDataRecord:G,deleteTableDataRecord:x}}const me={...W,componentName:{type:String,default:""},form:{type:Object,default:()=>{}},requestData:{type:Function,default:null},dataSource:{type:[Object],default:()=>[]}};function pe(s){const o=v({}),n=v(!0);F(()=>t(s).pagination,u=>{!w(u)&&u&&(o.value={...t(o),...u??{}})});const c=g(()=>{const{pagination:u}=t(s);return!t(n)||w(u)&&!u?!1:{page:1,pageSize:B,pageSizes:ge,showSizePicker:!0,showQuickJumper:!0,prefix:f=>`共 ${f.itemCount} 条`,...w(u)?{}:u,...t(o)}});function r(u){const f=t(c);o.value={...w(f)?{}:f,...u}}function i(){return t(c)}function a(){return t(n)}async function S(u){n.value=u}return{getPagination:i,getPaginationInfo:c,setShowPagination:S,getShowPagination:a,setPagination:r}}function ve(s){const o=v(t(s).loading);F(()=>t(s).loading,r=>{o.value=r});const n=g(()=>t(o));function c(r){o.value=r}return{getLoading:n,setLoading:c}}const Se=A({name:"NCurd",props:me,emits:["change"],setup(s,{emit:o}){const n=g(()=>s),c=v([]),{getLoading:r,setLoading:i}=ve(n),{getColumnsRef:a}=ce(n),{getPaginationInfo:S,setPagination:u}=pe(n),{getDataSourceRef:f}=de(n,{getPaginationInfo:S,setPagination:u,tableData:c,setLoading:i},o),m=g(()=>{const R=t(f);return{...t(n),loading:t(r),columns:t(a.value),data:R,remote:!0}}),b=g(()=>H(t(S)));return()=>C(X,Y(m.value,{pagination:b}),null)}}),_e={class:"n-layout-page-header"},De=A({__name:"ncurd",setup(s){const o=v([{title:"编码",key:"no"},{title:"名称",key:"name"},{title:"地址",key:"address"}]),n=async c=>await ue({...c});return(c,r)=>{const i=oe;return te(),ee("div",null,[ae("div",_e,[C(i,{bordered:!1,title:"NCURD"},{default:L(()=>r[0]||(r[0]=[ne(" NCURD 是面向配置的组件，本页展示的所有功能，均无额外业务代码，仅通过 NCURD 的 API 配置实现。 ")])),_:1})]),C(i,{bordered:!1,class:"mt-3"},{default:L(()=>[C(t(Se),{columns:o.value,requestData:n},null,8,["columns"])]),_:1})])}}});export{De as default};
