2 lines
2.1 KiB
JavaScript
2 lines
2.1 KiB
JavaScript
import{r as j}from"./index-DjYVfash.js";import{j as x,m as L,F as U,l as s,D as _}from"./index-DyfK1iyO.js";function N(p){const{apiUrl:l,statsUrl:r=null,defaultFilters:c={},defaultPageSize:h=20,fetchParams:d=null,processData:t=null,onError:o=null}=p,u=s([]),a=s(!1),v=s(1),b=s(h),w=s(0),C=s(null),z=s([]),f=s({prop:"",order:""}),g=x({...c}),E=s(500);function y(){const e={page:v.value,page_size:b.value,...g};return f.value.prop&&(e.sort_by=f.value.prop,e.sort_order=f.value.order==="ascending"?"asc":"desc"),d&&Object.assign(e,d()),Object.keys(e).forEach(n=>{(e[n]===""||e[n]===null||e[n]===void 0)&&delete e[n]}),e}async function i(){a.value=!0;try{const e=await j.get(l,{params:y()});let n=e.data.list||[];t&&(n=n.map(t)),u.value=n,w.value=e.data.total||0}catch(e){console.error(`获取列表失败: ${l}`,e),o&&o(e)}finally{a.value=!1}}async function S(){if(r)try{const e=await j.get(r);C.value=e.data}catch(e){console.error("获取统计数据失败:",e)}}function D(){i(),S()}function F(e){z.value=e}function H({prop:e,order:n}){f.value={prop:e,order:n},i()}function M(e){b.value=e,v.value=1,i()}function O(){v.value=1,i()}function P(){Object.keys(g).forEach(e=>{g[e]=c[e]!==void 0?c[e]:""}),O()}function m(){const e=window.innerHeight;E.value=Math.max(300,e-450)}return L(()=>{m(),window.addEventListener("resize",m),i(),S()}),U(()=>{window.removeEventListener("resize",m)}),{list:u,loading:a,page:v,pageSize:b,total:w,stats:C,selectedRows:z,sortParams:f,filters:g,tableMaxHeight:E,fetchData:i,fetchStats:S,refreshData:D,handleSelectionChange:F,handleSortChange:H,handleSizeChange:M,handleFilterChange:O,resetFilters:P,calculateTableHeight:m}}function q(p,l){const r=s(l.map(t=>({...t,visible:t.visible!==!1})));function c(){localStorage.setItem(p,JSON.stringify(r.value))}function h(){const t=localStorage.getItem(p);if(t)try{const o=JSON.parse(t),u=new Map(o.map(a=>[a.prop,a.visible]));r.value=l.map(a=>({...a,visible:u.has(a.prop)?u.get(a.prop):a.visible!==!1}))}catch(o){console.error("加载列设置失败:",o)}}const d=_(()=>{const t={};return r.value.forEach(o=>{t[o.prop]=o.visible}),t});return h(),{columnOptions:r,visibleColumns:d,saveColumnSettings:c}}export{q as a,N as u};
|