engineering/public/admin/assets/usePaging.5a1a0ff2.js
2024-04-15 09:25:11 +08:00

2 lines
1.1 KiB
JavaScript

import{t as u,a0 as f}from"./@vue.ab566ce7.js";function y(s){var a=document.createElement("span");a.textContent=s,a.style.visibility="hidden",a.style.position="absolute",a.style.whiteSpace="nowrap",document.body.appendChild(a);var o=a.offsetWidth;return document.body.removeChild(a),o}function w(s){const{page:a=1,size:o=15,fetchFun:d,params:r={},firstLoading:c=!1}=s,l=Object.assign({},u(r)),e=f({page:a,size:o,loading:c,count:0,lists:[],extend:{},calcWidth:({column:t})=>{let g=t.label.length*14+30;const h=e.lists.map(n=>{var i;return(i=t.property)!=null&&i.includes(".")?n[t.property.split(".")[0]][t.property.split(".")[1]]:n[t.property]}).reduce((n,i)=>Math.max(n,y(i)),0)+27;return t.width=Math.max(h,g),t.label}}),p=()=>(e.loading=!0,d({page_no:e.page,page_size:e.size,...r}).then(t=>(e.count=t==null?void 0:t.count,e.lists=t==null?void 0:t.lists,e.extend=t==null?void 0:t.extend,Promise.resolve(t))).catch(t=>Promise.reject(t)).finally(()=>{e.loading=!1}));return{pager:e,getLists:p,resetParams:()=>{Object.keys(l).forEach(t=>{r[t]=l[t]}),p()},resetPage:()=>{e.page=1,p()}}}export{w as u};