UNPKG

el-plus-powerful-table-ts

Version:

## [DOCS](https://peng-xiao-shuai.github.io/vite-vue-admin-docs/zh-CN/component/powerful-table-doc.html)

2 lines (1 loc) 1.98 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../index.js"),L=require("vue");function _(e,t,i){var y;const r=(y=t.tree)==null?void 0:y.props;let s=[];const f=(l,p,d=a.deepClone(t.list))=>{s.length||(s=a.deepClone(t).list.sort((n,c)=>(n._cdSort=n[r==null?void 0:r.children]?1:0,c._cdSort=c[r==null?void 0:r.children]?1:0,c._cdSort-n._cdSort)));const h=d;if(!l||Array.isArray(l)&&!l.length)return t.list;const o=O(p);if(o.filters&&o.filtersType==="select"||o.type==="switch")u(r,s,n=>{const c=n;return l.some(F=>{var w;switch(o.type){case"tag":{const S=(w=typeof c[o.prop]=="string"?c[o.prop].split(","):c[o.prop])==null?void 0:w.map(b=>String(b));return S==null?void 0:S.includes(String(F))}default:return c[o.prop]==F}})},h);else if(o.filtersType==="date"){const n=l;u(r,s,c=>j(c[o.prop],n[0],n[1]),h)}else u(r,s,n=>String(n[o.prop]||"").includes(String(l)),h);return h},g=L.computed(()=>l=>O(l));return{handleHeaderFilterChange:(l,p)=>{var o;let d=[];const h=(o=i.value)==null?void 0:o.filter(n=>n.state.value.length);if(h!=null&&h.length){if(typeof g.value(p).customFilter=="function"){new Promise(n=>{g.value(p).customFilter(l,p,n)}).then(n=>{e.tableLists=n});return}h.forEach(n=>{d=f(n.state.value,n.header,d),e.tableLists=d})}else e.tableLists=t.list},getPropObj:g}}const u=(e,t,i,r)=>{t&&t.length&&t.forEach(s=>{const f=a.deepClone(s);f[e.children]&&f[e.children].length?(f[e.children]=[],D(i(s),r,f),u(e,s[e.children],i,i(s)?r[r.length-1][e.children]:r)):D(i(s),r,f)})},D=(e,t,i)=>{e&&(t.length&&t.map(s=>JSON.stringify(s)).some(s=>s.replace(/,"_cdSort":\d/,"").includes(JSON.stringify(i).replace(/,"_cdSort":\d/,"")))||t.push(i))},O=e=>{let t={prop:""};if(!Array.isArray(e.props))return t=e.props,t;if(e.props.length===1)t=e.props[0];else if(e.props.length>1){const i=e.props.find(r=>r.filterItem);t=i||e.props[0]}return t},j=(e,t,i)=>{const r=new Date(e),s=new Date(t),f=new Date(i);return r>=s&&r<=f};exports.useFilters=_;