import{useAntdTable as e}from"ahooks";import a from"../useUrlQueryCriteria/index.js";function t(t,r){if(!t)return void console.error("【useTable】 缺少 service 参数");const{params:n,transform:o,...i}=r||{},{useStorageQueryCriteria:s=!0,usePagination:c=!0,usePermission:u=!0,defaultType:l="advance",defaultCurrent:p=1,defaultPageSize:g=20,defaultPagination:f={current:p,pageSize:g},...d}=i,{setUrlCriteriaQuery:b,getUrlCriteriaQuery:m}=a(),y=s?m("searchFormKeys","searchFormValues"):{},S=s&&c?m("paginationKeys","paginationValues"):{},h=Object.keys(y).length>0?y:{},P=c?Object.keys(S).length>0?S:f:{},k=e(function(e,a={},t,r){const n=("function"==typeof a?a():a)||{};return async({current:a,pageSize:o},i={})=>{let s=i;if("function"==typeof t){const e=t(i);e&&"object"==typeof e&&(s={...i,...e})}const c={pageIndex:a,pageSize:o,...s,...n};r&&(c.menuPath=window.location.pathname);const u=await e(c);return{list:u.data||[],total:u.totalCount||0,...u}}}(t,n,o,u),{...d,defaultParams:[P,h],defaultType:l,onSuccess:(e,a)=>{i.onSuccess&&i.onSuccess(e,a),s&&b(a[1]??{},c?{current:k.tableProps.pagination.current,pageSize:k.tableProps.pagination.pageSize}:{})}});return void 0!==i.callback&&console.warn("【useTable】 callback 参数已弃用，请使用 onSuccess 参数"),i.callback&&i.callback(k?.data?.list||[],k?.data||{}),{...k,tableProps:{...k.tableProps,pagination:!!c&&{...k.tableProps.pagination,showQuickJumper:!0,showSizeChanger:!0}},getData:k.search.submit}}export{t as default};
