bj-web-components 0.2.14 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/web/Table/BTable.js +1 -1
- package/dist/web/Table/BTable.mjs +30 -30
- package/package.json +1 -1
package/dist/web/Table/BTable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),b=require("react"),Kt=require("react-dom"),qt=require("../Pagination/Pagination.js"),me=require("../Icon/Icon.js");;/* empty css */const Bt=require("../Tooltip/ContentTooltip.js"),Tt=require("../Tooltip/TooltipWrapper.js"),zt=require("../CheckBox/index.js"),It=require("../Dropdown/BDropdown.js"),Vt=require("../OverlayScrollbar/BOverlayScrollbar.js"),wt=require("../SkuInputCard/spin_loading_red.gif.js"),Lt=require("../ProductField/no_data_light.png.js"),At=require("./Column.js"),Ht=require("./ColumnGroup.js"),_=require("./utils/sortFilter.js"),ve=require("./utils/columns.js");;/* empty css */const Wt=300;function E(...p){return p.filter(Boolean).join(" ")}function Ut(p,u){return u===void 0?void 0:(Array.isArray(u)?u:[u]).reduce((r,k)=>{if(!(r==null||typeof r!="object"))return r[k]},p)}function H(p,u,j){if(typeof j=="function")return j(p,u);if(j){const r=p[String(j)];if(typeof r=="string"||typeof r=="number")return r}return u}function Ze(p,u){return Math.max(1,Math.ceil(p/u))}function $t(p){return!!(p&&typeof p=="object"&&!b.isValidElement(p)&&"props"in p)}function Gt(p,u){return(typeof u.text=="string"||typeof u.text=="number"?String(u.text):String(u.value)).toLocaleLowerCase().includes(p.toLocaleLowerCase())}function Xe({checked:p,disabled:u,label:j,name:r,onChange:k,type:W="checkbox"}){return W==="checkbox"?i.jsx(zt.BCheckBox,{"aria-label":j,checked:p,className:"bj-table__selection-checkbox",disabled:u,name:r,onChange:k,skipGroup:!0}):i.jsxs("label",{className:E("bj-table__selection-control",p&&"bj-table__selection-control--checked",u&&"bj-table__selection-control--disabled"),children:[i.jsx("input",{"aria-label":j,checked:p,className:"bj-table__selection-input",disabled:u,name:r,onChange:k,type:W}),i.jsx("span",{"aria-hidden":"true",className:"bj-table__selection-box",children:p&&i.jsx(me,{className:"bj-table__selection-check-icon",type:"icon-a-dagouxi"})})]})}function Jt({columns:p,dataSource:u=[],rowKey:j,rowSelection:r,pagination:k=!1,loading:W=!1,bordered:Ye=!0,size:et="middle",showHeader:tt=!0,emptyText:ae,emptyImage:le=Lt,emptyHeight:st,t:$=Y=>Y,className:rt,style:at,rowClassName:ie,sortDirections:lt=["ascend","descend",null],onChange:ne,children:Ce,title:Fe,footer:De,summary:Re,tableLayout:Pe,components:v,onRow:de,onHeaderRow:ce,id:it,scroll:o,locale:U}){var Ue,$e,Ge;const Y=b.useRef(null),ke=b.useRef(null),ee=b.useMemo(()=>p??ve.convertChildrenToColumns(Ce),[Ce,p]),G=b.useMemo(()=>ve.flattenColumns(ee),[ee]),Oe=b.useMemo(()=>ve.buildHeaderRows(ee),[ee]),[nt,Ee]=b.useState((r==null?void 0:r.defaultSelectedRowKeys)??[]),[oe,te]=b.useState(k?k.defaultCurrent??1:1),[dt,ct]=b.useState(k?k.defaultPageSize??10:10),[ot,bt]=b.useState(()=>new Map(G.flatMap((e,t)=>e.defaultSortOrder?[[_.getColumnKey(e,t),e.defaultSortOrder]]:[]))),[ft,ut]=b.useState(()=>new Map(G.flatMap((e,t)=>e.defaultFilteredValue===void 0?[]:[[_.getColumnKey(e,t),e.defaultFilteredValue]]))),[M,L]=b.useState(null),[Me,J]=b.useState(new Map),[ht,se]=b.useState(null),pt=b.useRef(`btable-${Math.random().toString(36).slice(2,10)}`).current,[A,be]=b.useState(null),[fe,Se]=b.useState(null),[ue,Ke]=b.useState(""),[Q,qe]=b.useState(""),[_t,he]=b.useState(),pe=b.useRef(0),a=k||void 0,B=(a==null?void 0:a.pageSize)??dt,D=(r==null?void 0:r.selectedRowKeys)??nt,m=G,R=new Map(ot),O=new Map(ft);m.forEach((e,t)=>{if("children"in e)return;const s=_.getColumnKey(e,t);e.sortOrder!==void 0&&R.set(s,e.sortOrder),e.filteredValue!==void 0&&O.set(s,e.filteredValue)});const Be=b.useMemo(()=>_.filterRecords(u,m,O),[m,O,u]),T=b.useMemo(()=>_.sortRecords(Be,m,R),[m,Be,R]),_e=(a==null?void 0:a.total)??T.length,Te=Ze(_e,B),S=Math.min((a==null?void 0:a.current)??oe,Te);b.useEffect(()=>{S!==oe&&(a==null?void 0:a.current)===void 0&&te(S)},[S,a==null?void 0:a.current,oe]),b.useEffect(()=>{if(!A||M===null){Se(null);return}const e=()=>{const t=A.getBoundingClientRect();Se({left:t.left,top:t.bottom+8})};return e(),document.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{document.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[A,M]),b.useEffect(()=>{if(M===null)return;const e=t=>{const s=t.target;A!=null&&A.contains(s)||s.closest(".bj-table__filter-dropdown")||(L(null),be(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[A,M]),b.useEffect(()=>{const e=window.setTimeout(()=>qe(ue.trim()),Wt);return()=>window.clearTimeout(e)},[ue]),b.useEffect(()=>{if(M===null)return;const e=G.find((s,d)=>_.getColumnKey(s,d)===M);if(!e||"children"in e||!e.filterRequest)return;const t=++pe.current;Promise.resolve().then(()=>e.filterRequest(Q)).then(s=>{pe.current===t&&he(s)},()=>{pe.current===t&&he([])})},[Q,G,M]);const z=b.useMemo(()=>{if(!a)return T.map((t,s)=>({record:t,index:s}));const e=(S-1)*B;return T.slice(e,e+B).map((t,s)=>({record:t,index:e+s}))},[S,B,a,T]),ze=b.useMemo(()=>z.map(({record:e,index:t})=>H(e,t,j)),[j,z]),jt=D.map(String).join("|"),gt=ze.map(String).join("|");b.useEffect(()=>{var c;if(!r||D.length===0)return;const e=new Set(ze),t=D.filter(f=>e.has(f));if(t.length===D.length)return;r.selectedRowKeys===void 0&&Ee(t);const s=new Set(t),d=z.filter(({record:f,index:l})=>s.has(H(f,l,j))).map(({record:f})=>f);(c=r.onChange)==null||c.call(r,t,d,{type:"multiple"})},[r,j,jt,gt,z]);const je=(e,t=R,s=O,d=S)=>{const c=Object.fromEntries(s),f=_.filterRecords(u,m,s),l=_.sortRecords(f,m,t);ne==null||ne({...a,current:d,pageSize:B,total:(a==null?void 0:a.total)??l.length},c,_.getSorterResult(m,t),{action:e,currentDataSource:l})},yt=(e,t)=>{if(!e.sorter)return;const s=_.getColumnKey(e,t),d=_.getNextSortOrder(R.get(s)??null,e.sortDirections??lt),c=new Map;c.set(s,d),e.sortOrder===void 0&&bt(c),je("sort",c)},ge=(e,t,s)=>{const d=_.getColumnKey(e,t),c=new Map(O);c.set(d,s),e.filteredValue===void 0&&ut(c),L(null),(a==null?void 0:a.current)===void 0&&te(1),je("filter",R,c,1)},xt=(e,t)=>{const s=_.getColumnKey(e,t),d=e.filterResetToDefaultFilteredValue?e.defaultFilteredValue??[]:[];J(c=>new Map(c).set(s,d))},re=(e,t,s)=>{var c,f,l,C;const d=_.getColumnKey(e,t);if(M===d){L(null),be(null),(c=e.onFilterDropdownOpenChange)==null||c.call(e,!1),(f=e.onFilterDropdownVisibleChange)==null||f.call(e,!1);return}Ke(""),qe(""),he(void 0),J(g=>new Map(g).set(d,O.get(d)??[])),L(d),s&&be(s),(l=e.onFilterDropdownOpenChange)==null||l.call(e,!0),(C=e.onFilterDropdownVisibleChange)==null||C.call(e,!0)},vt=(e,t)=>{var w,Je;const s=_.getColumnKey(e,t),d=`bj-table-badge-${pt}-${String(s).replace(/[^a-zA-Z0-9_-]/g,"-")}`,c=R.get(s)??null,f=O.get(s)??[],l=Me.get(s)??f,C=e.filterDropdownOpen??e.filterDropdownVisible??M===s,g=e.filtered||f.length>0,h=c==="ascend"?"icon-a-zhengxumian":c==="descend"?"icon-a-daoxumian":"icon-a-weipaixumian",I=_.renderColumnTitle(e.title,{sortOrder:c,sortColumn:c?e:void 0,sortColumns:c?[{column:e,order:c}]:[],filters:Object.fromEntries(O)}),V=typeof e.filterDropdown=="function"?e.filterDropdown({prefixCls:"bj-table",selectedKeys:l.filter(n=>typeof n!="boolean"),setSelectedKeys:n=>J(y=>new Map(y).set(s,n)),confirm:n=>{ge(e,t,Me.get(s)??l),(n==null?void 0:n.closeDropdown)===!1&&L(s)},clearFilters:n=>{const y=e.filterResetToDefaultFilteredValue?e.defaultFilteredValue??[]:[];J(F=>new Map(F).set(s,y)),(n==null?void 0:n.confirm)===!0&&ge(e,t,y),((n==null?void 0:n.closeDropdown)===!1||(n==null?void 0:n.confirm)!==!0)&&L(s)},filters:e.filters,close:()=>L(null),visible:C}):e.filterDropdown,P=e.filterRequest?_t??[]:e.filters??[],x=Q&&!e.filterRequest?P.filter(n=>typeof e.filterSearch=="function"?e.filterSearch(Q,n):Gt(Q,n)):P,q=!!(e.filterSearch||e.filterRequest),N=i.jsxs("div",{className:E("bj-table__column-header",e.sorter&&"bj-table__column-header--sortable"),children:[e.badge!==void 0&&i.jsx("span",{"aria-label":"表头提示",className:"bj-table__column-badge-trigger",id:d,onBlur:()=>se(null),onClick:n=>n.stopPropagation(),onFocus:()=>se(s),onKeyDown:n=>n.stopPropagation(),onMouseEnter:()=>se(s),onMouseLeave:()=>se(null),role:"button",tabIndex:0,children:i.jsx("span",{"aria-hidden":"true",className:"bj-table__column-badge-shape"})}),i.jsxs("div",{className:"bj-table__column-title",children:[i.jsx("span",{className:"bj-table__column-title-content",children:I}),e.sorter&&i.jsx("span",{"aria-hidden":"true",className:"bj-table__column-sorter",children:i.jsx(me,{className:"bj-table__column-sorter-icon",type:h})})]}),(e.filters||e.filterDropdown)&&i.jsxs("div",{className:"bj-table__filter",children:[i.jsx("button",{"aria-expanded":C,"aria-label":"筛选",className:E("bj-table__filter-trigger",g&&"bj-table__filter-trigger--active"),onClick:n=>{n.stopPropagation(),re(e,t)},type:"button",children:typeof e.filterIcon=="function"?e.filterIcon(g):e.filterIcon??i.jsx(me,{className:"bj-table__filter-icon",type:"icon-a-shaixuanxi"})}),C&&fe&&typeof document<"u"&&Kt.createPortal(i.jsx("div",{className:"bj-table__filter-dropdown",onClick:n=>n.stopPropagation(),role:"dialog",style:{left:fe.left,top:fe.top},children:V??i.jsx(It.BDropdown,{...e.filterDropdownProps,emptyText:(U==null?void 0:U.filterEmptyText)??$("暂无筛选项"),multiple:e.filterMultiple!==!1,onChange:(n,y)=>{var F,Qe;J(St=>new Map(St).set(s,n)),(Qe=(F=e.filterDropdownProps)==null?void 0:F.onChange)==null||Qe.call(F,n,y)},onConfirm:n=>{var y,F;ge(e,t,n),(F=(y=e.filterDropdownProps)==null?void 0:y.onConfirm)==null||F.call(y,n)},onReset:()=>{var n,y;xt(e,t),(y=(n=e.filterDropdownProps)==null?void 0:n.onReset)==null||y.call(n)},onSearch:n=>{var y,F;Ke(n),(F=(y=e.filterDropdownProps)==null?void 0:y.onSearch)==null||F.call(y,n)},options:x.map(n=>({label:n.text,description:n.description,value:n.value})),searchable:((w=e.filterDropdownProps)==null?void 0:w.searchable)??q,searchPlaceholder:((Je=e.filterDropdownProps)==null?void 0:Je.searchPlaceholder)??(e.filterRequest?$("请输入搜索内容"):(U==null?void 0:U.filterSearchPlaceholder)??$("搜索")),searchValue:ue,value:l})}),document.body)]})]});return e.badge!==void 0?i.jsxs(Tt,{className:"bj-table__column-tooltip-wrapper",children:[i.jsx("div",{className:"bj-table__column-tooltip-trigger",children:N}),ht===s&&i.jsx(Bt,{className:"bj-table__column-tooltip",content:e.badge,getAnchorElement:()=>document.getElementById(d),getPopupContainer:()=>document.body,placement:"top"})]}):N},Ie=(e,t,s)=>{var f,l;t.selectedRowKeys===void 0&&Ee(e);const d=new Set(e),c=u.filter((C,g)=>d.has(H(C,g,j)));(f=t.onChange)==null||f.call(t,e,c),s&&((l=t.onSelect)==null||l.call(t,s,d.has(H(s,u.indexOf(s),j)),c))},mt=(e,t)=>{if(!r)return;const s=H(e,t,j),d=D.includes(s),c=r.type==="radio"?d?[]:[s]:d?D.filter(f=>f!==s):[...D,s];Ie(c,r,e)},Ve=z.filter(({record:e})=>{var t;return!((t=r==null?void 0:r.getCheckboxProps)!=null&&t.call(r,e).disabled)}),Z=Ve.map(({record:e,index:t})=>H(e,t,j)),ye=Z.length>0&&Z.every(e=>D.includes(e)),Nt=()=>{var s;if(!r||r.type==="radio")return;const e=new Set(Z),t=ye?D.filter(d=>!e.has(d)):Array.from(new Set([...D,...Z]));Ie(t,r),new Set(t),(s=r.onSelectAll)==null||s.call(r,!ye,Ve.map(({record:d})=>d))},Ct=e=>{var t;!a||e<1||e>Te||e===S||(a.current===void 0&&te(e),(t=a.onChange)==null||t.call(a,e,B),je("paginate",R,O,e))},Ft=e=>{var s,d;if(!a||e===B)return;const t=Math.min(S,Ze(_e,e));a.pageSize===void 0&&ct(e),a.current===void 0&&te(t),(s=a.onShowSizeChange)==null||s.call(a,t,e),(d=a.onChange)==null||d.call(a,t,e)},Dt=m.length+(r?1:0),X=(r==null?void 0:r.columnWidth)??48,we=e=>typeof e.width=="number"?e.width:0,Le=(e,t)=>{const s=e.fixed===!0?"left":e.fixed;return s==="left"?{position:"sticky",left:m.slice(0,t).reduce((c,f)=>c+we(f),r&&typeof X=="number"?X:0),zIndex:2}:s==="right"?{position:"sticky",right:m.slice(t+1).reduce((c,f)=>c+we(f),0),zIndex:2}:{}},Rt=o!=null&&o.x?{width:o.x===!0?"max-content":o.x,minWidth:"100%",tableLayout:Pe??"fixed"}:{tableLayout:Pe},Pt=(v==null?void 0:v.table)??"table",kt=((Ue=v==null?void 0:v.header)==null?void 0:Ue.wrapper)??"thead",Ot=(($e=v==null?void 0:v.header)==null?void 0:$e.row)??"tr",Ae=((Ge=v==null?void 0:v.header)==null?void 0:Ge.cell)??"th",K=typeof(v==null?void 0:v.body)=="object"?v.body:void 0,Et=(K==null?void 0:K.wrapper)??"tbody",He=(K==null?void 0:K.row)??"tr",xe=(K==null?void 0:K.cell)??"td",Mt=typeof ae=="function"?ae():ae??$("暂无数据"),We=typeof le=="string"?i.jsx("img",{alt:"",className:"bj-table__empty-image",src:le}):le;return i.jsxs("div",{id:it,ref:Y,className:E("bj-table",Ye&&"bj-table--bordered",`bj-table--${et}`,W&&"bj-table--loading",T.length===0&&"bj-table--empty",rt),style:at,children:[Fe&&i.jsx("div",{className:"bj-table__title",children:Fe(T)}),i.jsxs("div",{className:"bj-table__viewport",children:[i.jsx("div",{className:E("bj-table__scroll",!!(o!=null&&o.x||o!=null&&o.y)&&"bj-overlay-scrollbar-hidden"),ref:ke,style:{maxHeight:o==null?void 0:o.y},children:i.jsxs(Pt,{className:"bj-table__native-table",style:Rt,children:[m.some(e=>e.width)&&i.jsxs("colgroup",{children:[r&&i.jsx("col",{className:"bj-table__selection-col",style:{width:X}}),m.map((e,t)=>i.jsx("col",{style:{width:e.width}},e.key??t))]}),tt&&i.jsx(kt,{className:"bj-table__header",children:Oe.map((e,t)=>i.jsxs(Ot,{className:"bj-table__header-row",...ce==null?void 0:ce(m,t),children:[r&&t===0&&i.jsxs(Ae,{className:E("bj-table__header-cell","bj-table__selection-cell",!!(o!=null&&o.x)&&"bj-table__selection-cell--fixed"),rowSpan:Oe.length,scope:"col",style:{width:X},children:[r.type!=="radio"&&i.jsx(Xe,{checked:ye,disabled:Z.length===0,onChange:Nt,label:"选择当前页所有行"}),r.columnTitle]}),e.map(({column:s,colSpan:d,rowSpan:c},f)=>{var P;const l=s,C=m.indexOf(l),g=C>=0?C:f,h=!("children"in s)&&!!(l.filters||l.filterDropdown),I=!("children"in s)&&!!l.sorter,V=()=>{h?re(l,g):I&&yt(l,g)};return b.createElement(Ae,{...(P=l.onHeaderCell)==null?void 0:P.call(l,s,f),"aria-label":typeof l.title=="string"?l.title:void 0,"aria-sort":I?R.get(_.getColumnKey(l,g))==="ascend"?"ascending":R.get(_.getColumnKey(l,g))==="descend"?"descending":"none":void 0,className:E("bj-table__header-cell",l.fixed&&"bj-table__cell--fixed",(l.fixed==="left"||l.fixed===!0)&&"bj-table__cell--fixed-left",l.fixed==="right"&&"bj-table__cell--fixed-right",l.sorter&&"bj-table__header-cell--sortable",h&&"bj-table__header-cell--filterable",R.get(_.getColumnKey(l,g))&&"bj-table__header-cell--sorted",l.className),colSpan:d,key:l.key??String(l.dataIndex??f),onClick:x=>{var q,N,w;(w=(N=(q=l.onHeaderCell)==null?void 0:q.call(l,s,f))==null?void 0:N.onClick)==null||w.call(N,x),!x.target.closest(".bj-table__filter-dropdown")&&(h?re(l,g,x.currentTarget):V())},onKeyDown:x=>{var q,N,w;(w=(N=(q=l.onHeaderCell)==null?void 0:q.call(l,s,f))==null?void 0:N.onKeyDown)==null||w.call(N,x),!x.target.closest(".bj-table__filter-dropdown")&&(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),h?re(l,g,x.currentTarget):V())},rowSpan:c,scope:"col",style:{textAlign:l.align,...Le(l,g)},tabIndex:h||I?0:void 0},"children"in s?_.renderColumnTitle(s.title,{filters:Object.fromEntries(O)}):vt(l,g))})]},t))}),i.jsx(Et,{className:"bj-table__body",children:z.length>0?z.map(({record:e,index:t})=>{var l;const s=H(e,t,j),d=((l=r==null?void 0:r.getCheckboxProps)==null?void 0:l.call(r,e).disabled)??!1,c=D.includes(s),f=typeof ie=="function"?ie(e,t,0):ie;return b.createElement(He,{...de==null?void 0:de(e,t),className:E("bj-table__row",c&&"bj-table__row--selected",f),key:s},r&&i.jsx(xe,{className:E("bj-table__cell","bj-table__selection-cell",!!(o!=null&&o.x)&&"bj-table__selection-cell--fixed"),style:{width:X},children:i.jsx(Xe,{checked:c,disabled:d,label:`选择第 ${t+1} 行`,name:r.type==="radio"?"bj-table-row-selection":void 0,onChange:()=>mt(e,t),type:r.type??"checkbox"})}),m.map((C,g)=>{var N;const h=C,I=Ut(e,h.dataIndex),V=h.render?h.render(I,e,t):I,P=$t(V)?V:void 0,x={...(N=h.onCell)==null?void 0:N.call(h,e,t),...P==null?void 0:P.props},q=P?P.children:V;return x.colSpan===0||x.rowSpan===0?null:b.createElement(xe,{...x,className:E("bj-table__cell",h.fixed&&"bj-table__cell--fixed",(h.fixed==="left"||h.fixed===!0)&&"bj-table__cell--fixed-left",h.fixed==="right"&&"bj-table__cell--fixed-right",h.ellipsis&&"bj-table__cell--ellipsis",h.className,x.className),key:h.key??String(h.dataIndex??g),style:{textAlign:h.align,...Le(h,g),...x.style}},i.jsx("div",{className:"bj-table__cell-content",children:q??""}))}))}):i.jsx(He,{className:"bj-table__empty-row",children:i.jsx(xe,{className:"bj-table__empty-cell",colSpan:Math.max(Dt,1),style:{height:st}})})}),Re&&i.jsx("tfoot",{className:"bj-table__summary",children:Re(T)})]})}),z.length===0&&i.jsx("div",{className:"bj-table__empty-overlay",children:i.jsxs("div",{className:"bj-table__empty-content",children:[We&&i.jsx("div",{className:"bj-table__empty-image-wrap",children:We}),i.jsx("div",{className:"bj-table__empty-text",children:Mt})]})})]}),((o==null?void 0:o.x)||(o==null?void 0:o.y))&&i.jsx(Vt,{containerRef:Y,direction:o!=null&&o.x&&(o!=null&&o.y)?"both":o!=null&&o.x?"horizontal":"vertical",gap:2,horizontalInsetEnd:0,horizontalInsetStart:0,size:4,targetRef:ke}),De&&i.jsx("div",{className:"bj-table__footer",children:De(T)}),W&&i.jsxs("div",{"aria-live":"polite","aria-busy":"true",className:"bj-table__loading",role:"status",children:[i.jsx("img",{alt:"",className:"bj-table__loading-indicator",src:wt}),i.jsx("span",{className:"bj-table__loading-text",children:"加载中..."})]}),a&&i.jsx("div",{className:"bj-table__pagination",children:i.jsx(qt,{align:"end",disabled:W||a.disabled,current:S,defaultCurrent:a.defaultCurrent,defaultPageSize:a.defaultPageSize,dropdownClassName:a.dropdownClassName,hideOnSinglePage:a.hideOnSinglePage,onChange:Ct,onShowSizeChange:(e,t)=>Ft(t),pageSize:B,pageSizeOptions:a.pageSizeOptions,popupPlacement:a.popupPlacement,resolvePopupPlacement:a.resolvePopupPlacement,showQuickJumper:a.showQuickJumper,showSizeChanger:a.showSizeChanger,showTotal:a.showTotal,simple:a.simple,size:a.size,t:a.t??$,total:_e})})]})}const Ne=Jt;Ne.Column=At;Ne.ColumnGroup=Ht;exports.BTable=Ne;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),b=require("react"),Kt=require("react-dom"),qt=require("../Pagination/Pagination.js"),me=require("../Icon/Icon.js");;/* empty css */const Bt=require("../Tooltip/ContentTooltip.js"),Tt=require("../Tooltip/TooltipWrapper.js"),zt=require("../CheckBox/index.js"),It=require("../Dropdown/BDropdown.js"),Vt=require("../OverlayScrollbar/BOverlayScrollbar.js"),wt=require("../SkuInputCard/spin_loading_red.gif.js"),Lt=require("../ProductField/no_data_light.png.js"),At=require("./Column.js"),Ht=require("./ColumnGroup.js"),_=require("./utils/sortFilter.js"),ve=require("./utils/columns.js");;/* empty css */const Wt=300;function E(...p){return p.filter(Boolean).join(" ")}function Ut(p,u){return u===void 0?void 0:(Array.isArray(u)?u:[u]).reduce((r,k)=>{if(!(r==null||typeof r!="object"))return r[k]},p)}function H(p,u,j){if(typeof j=="function")return j(p,u);if(j){const r=p[String(j)];if(typeof r=="string"||typeof r=="number")return r}return u}function Ze(p,u){return Math.max(1,Math.ceil(p/u))}function $t(p){return!!(p&&typeof p=="object"&&!b.isValidElement(p)&&"props"in p)}function Gt(p,u){return(typeof u.text=="string"||typeof u.text=="number"?String(u.text):String(u.value)).toLocaleLowerCase().includes(p.toLocaleLowerCase())}function Xe({checked:p,disabled:u,label:j,name:r,onChange:k,type:W="checkbox"}){return W==="checkbox"?i.jsx(zt.BCheckBox,{"aria-label":j,checked:p,className:"bj-table__selection-checkbox",disabled:u,name:r,onChange:k,skipGroup:!0}):i.jsxs("label",{className:E("bj-table__selection-control",p&&"bj-table__selection-control--checked",u&&"bj-table__selection-control--disabled"),children:[i.jsx("input",{"aria-label":j,checked:p,className:"bj-table__selection-input",disabled:u,name:r,onChange:k,type:W}),i.jsx("span",{"aria-hidden":"true",className:"bj-table__selection-box",children:p&&i.jsx(me,{className:"bj-table__selection-check-icon",type:"icon-a-dagouxi"})})]})}function Jt({columns:p,dataSource:u=[],rowKey:j,rowSelection:r,pagination:k=!1,loading:W=!1,bordered:Ye=!0,size:et="middle",showHeader:tt=!0,emptyText:ae,emptyImage:le=Lt,emptyHeight:st,t:$=Y=>Y,className:rt,style:at,rowClassName:ie,sortDirections:lt=["ascend","descend",null],onChange:ne,children:Ce,title:Fe,footer:De,summary:Re,tableLayout:Pe,components:v,onRow:de,onHeaderRow:ce,id:it,scroll:o,locale:U}){var Ue,$e,Ge;const Y=b.useRef(null),ke=b.useRef(null),ee=b.useMemo(()=>p??ve.convertChildrenToColumns(Ce),[Ce,p]),G=b.useMemo(()=>ve.flattenColumns(ee),[ee]),Oe=b.useMemo(()=>ve.buildHeaderRows(ee),[ee]),[nt,Ee]=b.useState((r==null?void 0:r.defaultSelectedRowKeys)??[]),[oe,te]=b.useState(k?k.defaultCurrent??1:1),[dt,ct]=b.useState(k?k.defaultPageSize??10:10),[ot,bt]=b.useState(()=>new Map(G.flatMap((e,t)=>e.defaultSortOrder?[[_.getColumnKey(e,t),e.defaultSortOrder]]:[]))),[ft,ut]=b.useState(()=>new Map(G.flatMap((e,t)=>e.defaultFilteredValue===void 0?[]:[[_.getColumnKey(e,t),e.defaultFilteredValue]]))),[M,L]=b.useState(null),[Me,J]=b.useState(new Map),[ht,se]=b.useState(null),pt=b.useRef(`btable-${Math.random().toString(36).slice(2,10)}`).current,[A,be]=b.useState(null),[fe,Se]=b.useState(null),[ue,Ke]=b.useState(""),[Q,qe]=b.useState(""),[_t,he]=b.useState(),pe=b.useRef(0),a=k||void 0,T=(a==null?void 0:a.pageSize)??dt,D=(r==null?void 0:r.selectedRowKeys)??nt,m=G,R=new Map(ot),O=new Map(ft);m.forEach((e,t)=>{if("children"in e)return;const s=_.getColumnKey(e,t);e.sortOrder!==void 0&&R.set(s,e.sortOrder),e.filteredValue!==void 0&&O.set(s,e.filteredValue)});const Be=b.useMemo(()=>_.filterRecords(u,m,O),[m,O,u]),S=b.useMemo(()=>_.sortRecords(Be,m,R),[m,Be,R]),_e=(a==null?void 0:a.total)??S.length,Te=Ze(_e,T),K=Math.min((a==null?void 0:a.current)??oe,Te);b.useEffect(()=>{K!==oe&&(a==null?void 0:a.current)===void 0&&te(K)},[K,a==null?void 0:a.current,oe]),b.useEffect(()=>{if(!A||M===null){Se(null);return}const e=()=>{const t=A.getBoundingClientRect();Se({left:t.left,top:t.bottom+8})};return e(),document.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{document.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[A,M]),b.useEffect(()=>{if(M===null)return;const e=t=>{const s=t.target;A!=null&&A.contains(s)||s.closest(".bj-table__filter-dropdown")||(L(null),be(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[A,M]),b.useEffect(()=>{const e=window.setTimeout(()=>qe(ue.trim()),Wt);return()=>window.clearTimeout(e)},[ue]),b.useEffect(()=>{if(M===null)return;const e=G.find((s,d)=>_.getColumnKey(s,d)===M);if(!e||"children"in e||!e.filterRequest)return;const t=++pe.current;Promise.resolve().then(()=>e.filterRequest(Q)).then(s=>{pe.current===t&&he(s)},()=>{pe.current===t&&he([])})},[Q,G,M]);const z=b.useMemo(()=>{if(!a)return S.map((t,s)=>({record:t,index:s}));const e=(K-1)*T;return S.slice(e,e+T).map((t,s)=>({record:t,index:e+s}))},[K,T,a,S]),ze=b.useMemo(()=>z.map(({record:e,index:t})=>H(e,t,j)),[j,z]),jt=D.map(String).join("|"),gt=ze.map(String).join("|");b.useEffect(()=>{var c;if(!r||D.length===0)return;const e=new Set(ze),t=D.filter(f=>e.has(f));if(t.length===D.length)return;r.selectedRowKeys===void 0&&Ee(t);const s=new Set(t),d=z.filter(({record:f,index:l})=>s.has(H(f,l,j))).map(({record:f})=>f);(c=r.onChange)==null||c.call(r,t,d,{type:"multiple"})},[r,j,jt,gt,z]);const je=(e,t=R,s=O,d=K)=>{const c=Object.fromEntries(s),f=_.filterRecords(u,m,s),l=_.sortRecords(f,m,t);ne==null||ne({...a,current:d,pageSize:T,total:(a==null?void 0:a.total)??l.length},c,_.getSorterResult(m,t),{action:e,currentDataSource:l})},yt=(e,t)=>{if(!e.sorter)return;const s=_.getColumnKey(e,t),d=_.getNextSortOrder(R.get(s)??null,e.sortDirections??lt),c=new Map;c.set(s,d),e.sortOrder===void 0&&bt(c),je("sort",c)},ge=(e,t,s)=>{const d=_.getColumnKey(e,t),c=new Map(O);c.set(d,s),e.filteredValue===void 0&&ut(c),L(null),(a==null?void 0:a.current)===void 0&&te(1),je("filter",R,c,1)},xt=(e,t)=>{const s=_.getColumnKey(e,t),d=e.filterResetToDefaultFilteredValue?e.defaultFilteredValue??[]:[];J(c=>new Map(c).set(s,d))},re=(e,t,s)=>{var c,f,l,C;const d=_.getColumnKey(e,t);if(M===d){L(null),be(null),(c=e.onFilterDropdownOpenChange)==null||c.call(e,!1),(f=e.onFilterDropdownVisibleChange)==null||f.call(e,!1);return}Ke(""),qe(""),he(void 0),J(g=>new Map(g).set(d,O.get(d)??[])),L(d),s&&be(s),(l=e.onFilterDropdownOpenChange)==null||l.call(e,!0),(C=e.onFilterDropdownVisibleChange)==null||C.call(e,!0)},vt=(e,t)=>{var w,Je;const s=_.getColumnKey(e,t),d=`bj-table-badge-${pt}-${String(s).replace(/[^a-zA-Z0-9_-]/g,"-")}`,c=R.get(s)??null,f=O.get(s)??[],l=Me.get(s)??f,C=e.filterDropdownOpen??e.filterDropdownVisible??M===s,g=e.filtered||f.length>0,h=c==="ascend"?"icon-a-zhengxumian":c==="descend"?"icon-a-daoxumian":"icon-a-weipaixumian",I=_.renderColumnTitle(e.title,{sortOrder:c,sortColumn:c?e:void 0,sortColumns:c?[{column:e,order:c}]:[],filters:Object.fromEntries(O)}),V=typeof e.filterDropdown=="function"?e.filterDropdown({prefixCls:"bj-table",selectedKeys:l.filter(n=>typeof n!="boolean"),setSelectedKeys:n=>J(y=>new Map(y).set(s,n)),confirm:n=>{ge(e,t,Me.get(s)??l),(n==null?void 0:n.closeDropdown)===!1&&L(s)},clearFilters:n=>{const y=e.filterResetToDefaultFilteredValue?e.defaultFilteredValue??[]:[];J(F=>new Map(F).set(s,y)),(n==null?void 0:n.confirm)===!0&&ge(e,t,y),((n==null?void 0:n.closeDropdown)===!1||(n==null?void 0:n.confirm)!==!0)&&L(s)},filters:e.filters,close:()=>L(null),visible:C}):e.filterDropdown,P=e.filterRequest?_t??[]:e.filters??[],x=Q&&!e.filterRequest?P.filter(n=>typeof e.filterSearch=="function"?e.filterSearch(Q,n):Gt(Q,n)):P,B=!!(e.filterSearch||e.filterRequest),N=i.jsxs("div",{className:E("bj-table__column-header",e.sorter&&"bj-table__column-header--sortable"),children:[e.badge!==void 0&&i.jsx("span",{"aria-label":"表头提示",className:"bj-table__column-badge-trigger",id:d,onBlur:()=>se(null),onClick:n=>n.stopPropagation(),onFocus:()=>se(s),onKeyDown:n=>n.stopPropagation(),onMouseEnter:()=>se(s),onMouseLeave:()=>se(null),role:"button",tabIndex:0,children:i.jsx("span",{"aria-hidden":"true",className:"bj-table__column-badge-shape"})}),i.jsxs("div",{className:"bj-table__column-title",children:[i.jsx("span",{className:"bj-table__column-title-content",children:I}),e.sorter&&i.jsx("span",{"aria-hidden":"true",className:"bj-table__column-sorter",children:i.jsx(me,{className:"bj-table__column-sorter-icon",type:h})})]}),(e.filters||e.filterDropdown)&&i.jsxs("div",{className:"bj-table__filter",children:[i.jsx("button",{"aria-expanded":C,"aria-label":"筛选",className:E("bj-table__filter-trigger",g&&"bj-table__filter-trigger--active"),onClick:n=>{n.stopPropagation(),re(e,t)},type:"button",children:typeof e.filterIcon=="function"?e.filterIcon(g):e.filterIcon??i.jsx(me,{className:"bj-table__filter-icon",type:"icon-a-shaixuanxi"})}),C&&fe&&typeof document<"u"&&Kt.createPortal(i.jsx("div",{className:"bj-table__filter-dropdown",onClick:n=>n.stopPropagation(),role:"dialog",style:{left:fe.left,top:fe.top},children:V??i.jsx(It.BDropdown,{...e.filterDropdownProps,emptyText:(U==null?void 0:U.filterEmptyText)??$("暂无筛选项"),multiple:e.filterMultiple!==!1,onChange:(n,y)=>{var F,Qe;J(St=>new Map(St).set(s,n)),(Qe=(F=e.filterDropdownProps)==null?void 0:F.onChange)==null||Qe.call(F,n,y)},onConfirm:n=>{var y,F;ge(e,t,n),(F=(y=e.filterDropdownProps)==null?void 0:y.onConfirm)==null||F.call(y,n)},onReset:()=>{var n,y;xt(e,t),(y=(n=e.filterDropdownProps)==null?void 0:n.onReset)==null||y.call(n)},onSearch:n=>{var y,F;Ke(n),(F=(y=e.filterDropdownProps)==null?void 0:y.onSearch)==null||F.call(y,n)},options:x.map(n=>({label:n.text,description:n.description,value:n.value})),searchable:((w=e.filterDropdownProps)==null?void 0:w.searchable)??B,searchPlaceholder:((Je=e.filterDropdownProps)==null?void 0:Je.searchPlaceholder)??(e.filterRequest?$("请输入搜索内容"):(U==null?void 0:U.filterSearchPlaceholder)??$("搜索")),searchValue:ue,value:l})}),document.body)]})]});return e.badge!==void 0?i.jsxs(Tt,{className:"bj-table__column-tooltip-wrapper",children:[i.jsx("div",{className:"bj-table__column-tooltip-trigger",children:N}),ht===s&&i.jsx(Bt,{className:"bj-table__column-tooltip",content:e.badge,getAnchorElement:()=>document.getElementById(d),getPopupContainer:()=>document.body,placement:"top"})]}):N},Ie=(e,t,s)=>{var f,l;t.selectedRowKeys===void 0&&Ee(e);const d=new Set(e),c=u.filter((C,g)=>d.has(H(C,g,j)));(f=t.onChange)==null||f.call(t,e,c),s&&((l=t.onSelect)==null||l.call(t,s,d.has(H(s,u.indexOf(s),j)),c))},mt=(e,t)=>{if(!r)return;const s=H(e,t,j),d=D.includes(s),c=r.type==="radio"?d?[]:[s]:d?D.filter(f=>f!==s):[...D,s];Ie(c,r,e)},Ve=z.filter(({record:e})=>{var t;return!((t=r==null?void 0:r.getCheckboxProps)!=null&&t.call(r,e).disabled)}),Z=Ve.map(({record:e,index:t})=>H(e,t,j)),ye=Z.length>0&&Z.every(e=>D.includes(e)),Nt=()=>{var s;if(!r||r.type==="radio")return;const e=new Set(Z),t=ye?D.filter(d=>!e.has(d)):Array.from(new Set([...D,...Z]));Ie(t,r),new Set(t),(s=r.onSelectAll)==null||s.call(r,!ye,Ve.map(({record:d})=>d))},Ct=e=>{var t;!a||e<1||e>Te||e===K||(a.current===void 0&&te(e),(t=a.onChange)==null||t.call(a,e,T),je("paginate",R,O,e))},Ft=e=>{var s,d;if(!a||e===T)return;const t=Math.min(K,Ze(_e,e));a.pageSize===void 0&&ct(e),a.current===void 0&&te(t),(s=a.onShowSizeChange)==null||s.call(a,t,e),(d=a.onChange)==null||d.call(a,t,e)},Dt=m.length+(r?1:0),X=(r==null?void 0:r.columnWidth)??48,we=e=>typeof e.width=="number"?e.width:0,Le=(e,t)=>{const s=e.fixed===!0?"left":e.fixed;return s==="left"?{position:"sticky",left:m.slice(0,t).reduce((c,f)=>c+we(f),r&&typeof X=="number"?X:0),zIndex:2}:s==="right"?{position:"sticky",right:m.slice(t+1).reduce((c,f)=>c+we(f),0),zIndex:2}:{}},Rt=o!=null&&o.x?{width:o.x===!0?"max-content":o.x,minWidth:"100%",tableLayout:Pe??"fixed"}:{tableLayout:Pe},Pt=(v==null?void 0:v.table)??"table",kt=((Ue=v==null?void 0:v.header)==null?void 0:Ue.wrapper)??"thead",Ot=(($e=v==null?void 0:v.header)==null?void 0:$e.row)??"tr",Ae=((Ge=v==null?void 0:v.header)==null?void 0:Ge.cell)??"th",q=typeof(v==null?void 0:v.body)=="object"?v.body:void 0,Et=(q==null?void 0:q.wrapper)??"tbody",He=(q==null?void 0:q.row)??"tr",xe=(q==null?void 0:q.cell)??"td",Mt=typeof ae=="function"?ae():ae??$("暂无数据"),We=typeof le=="string"?i.jsx("img",{alt:"",className:"bj-table__empty-image",src:le}):le;return i.jsxs("div",{id:it,ref:Y,className:E("bj-table",Ye&&"bj-table--bordered",`bj-table--${et}`,W&&"bj-table--loading",S.length===0&&"bj-table--empty",rt),style:at,children:[Fe&&i.jsx("div",{className:"bj-table__title",children:Fe(S)}),i.jsxs("div",{className:"bj-table__viewport",children:[i.jsx("div",{className:E("bj-table__scroll",!!(o!=null&&o.x||o!=null&&o.y)&&"bj-overlay-scrollbar-hidden"),ref:ke,style:{maxHeight:o==null?void 0:o.y},children:i.jsxs(Pt,{className:"bj-table__native-table",style:Rt,children:[m.some(e=>e.width)&&i.jsxs("colgroup",{children:[r&&i.jsx("col",{className:"bj-table__selection-col",style:{width:X}}),m.map((e,t)=>i.jsx("col",{style:{width:e.width}},e.key??t))]}),tt&&i.jsx(kt,{className:"bj-table__header",children:Oe.map((e,t)=>i.jsxs(Ot,{className:"bj-table__header-row",...ce==null?void 0:ce(m,t),children:[r&&t===0&&i.jsxs(Ae,{className:E("bj-table__header-cell","bj-table__selection-cell",!!(o!=null&&o.x)&&"bj-table__selection-cell--fixed"),rowSpan:Oe.length,scope:"col",style:{width:X},children:[r.type!=="radio"&&i.jsx(Xe,{checked:ye,disabled:Z.length===0,onChange:Nt,label:"选择当前页所有行"}),r.columnTitle]}),e.map(({column:s,colSpan:d,rowSpan:c},f)=>{var P;const l=s,C=m.indexOf(l),g=C>=0?C:f,h=!("children"in s)&&!!(l.filters||l.filterDropdown),I=!("children"in s)&&!!l.sorter,V=()=>{h?re(l,g):I&&yt(l,g)};return b.createElement(Ae,{...(P=l.onHeaderCell)==null?void 0:P.call(l,s,f),"aria-label":typeof l.title=="string"?l.title:void 0,"aria-sort":I?R.get(_.getColumnKey(l,g))==="ascend"?"ascending":R.get(_.getColumnKey(l,g))==="descend"?"descending":"none":void 0,className:E("bj-table__header-cell",l.fixed&&"bj-table__cell--fixed",(l.fixed==="left"||l.fixed===!0)&&"bj-table__cell--fixed-left",l.fixed==="right"&&"bj-table__cell--fixed-right",l.sorter&&"bj-table__header-cell--sortable",h&&"bj-table__header-cell--filterable",R.get(_.getColumnKey(l,g))&&"bj-table__header-cell--sorted",l.className),colSpan:d,key:l.key??String(l.dataIndex??f),onClick:x=>{var B,N,w;(w=(N=(B=l.onHeaderCell)==null?void 0:B.call(l,s,f))==null?void 0:N.onClick)==null||w.call(N,x),!x.target.closest(".bj-table__filter-dropdown")&&(h?re(l,g,x.currentTarget):V())},onKeyDown:x=>{var B,N,w;(w=(N=(B=l.onHeaderCell)==null?void 0:B.call(l,s,f))==null?void 0:N.onKeyDown)==null||w.call(N,x),!x.target.closest(".bj-table__filter-dropdown")&&(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),h?re(l,g,x.currentTarget):V())},rowSpan:c,scope:"col",style:{textAlign:l.align,...Le(l,g)},tabIndex:h||I?0:void 0},"children"in s?_.renderColumnTitle(s.title,{filters:Object.fromEntries(O)}):vt(l,g))})]},t))}),i.jsx(Et,{className:"bj-table__body",children:z.length>0?z.map(({record:e,index:t})=>{var l;const s=H(e,t,j),d=((l=r==null?void 0:r.getCheckboxProps)==null?void 0:l.call(r,e).disabled)??!1,c=D.includes(s),f=typeof ie=="function"?ie(e,t,0):ie;return b.createElement(He,{...de==null?void 0:de(e,t),className:E("bj-table__row",c&&"bj-table__row--selected",f),key:s},r&&i.jsx(xe,{className:E("bj-table__cell","bj-table__selection-cell",!!(o!=null&&o.x)&&"bj-table__selection-cell--fixed"),style:{width:X},children:i.jsx(Xe,{checked:c,disabled:d,label:`选择第 ${t+1} 行`,name:r.type==="radio"?"bj-table-row-selection":void 0,onChange:()=>mt(e,t),type:r.type??"checkbox"})}),m.map((C,g)=>{var N;const h=C,I=Ut(e,h.dataIndex),V=h.render?h.render(I,e,t):I,P=$t(V)?V:void 0,x={...(N=h.onCell)==null?void 0:N.call(h,e,t),...P==null?void 0:P.props},B=P?P.children:V;return x.colSpan===0||x.rowSpan===0?null:b.createElement(xe,{...x,className:E("bj-table__cell",h.fixed&&"bj-table__cell--fixed",(h.fixed==="left"||h.fixed===!0)&&"bj-table__cell--fixed-left",h.fixed==="right"&&"bj-table__cell--fixed-right",h.ellipsis&&"bj-table__cell--ellipsis",h.className,x.className),key:h.key??String(h.dataIndex??g),style:{textAlign:h.align,...Le(h,g),...x.style}},i.jsx("div",{className:"bj-table__cell-content",children:B??""}))}))}):i.jsx(He,{className:"bj-table__empty-row",children:i.jsx(xe,{className:"bj-table__empty-cell",colSpan:Math.max(Dt,1),style:{height:st}})})}),Re&&i.jsx("tfoot",{className:"bj-table__summary",children:Re(S)})]})}),z.length===0&&i.jsx("div",{className:"bj-table__empty-overlay",children:i.jsxs("div",{className:"bj-table__empty-content",children:[We&&i.jsx("div",{className:"bj-table__empty-image-wrap",children:We}),i.jsx("div",{className:"bj-table__empty-text",children:Mt})]})})]}),((o==null?void 0:o.x)||(o==null?void 0:o.y))&&i.jsx(Vt,{containerRef:Y,direction:o!=null&&o.x&&(o!=null&&o.y)?"both":o!=null&&o.x?"horizontal":"vertical",gap:2,horizontalInsetEnd:0,horizontalInsetStart:0,size:4,targetRef:ke}),De&&i.jsx("div",{className:"bj-table__footer",children:De(S)}),W&&i.jsxs("div",{"aria-live":"polite","aria-busy":"true",className:"bj-table__loading",role:"status",children:[i.jsx("img",{alt:"",className:"bj-table__loading-indicator",src:wt}),i.jsx("span",{className:"bj-table__loading-text",children:"加载中..."})]}),a&&S.length>0&&i.jsx("div",{className:"bj-table__pagination",children:i.jsx(qt,{align:"end",disabled:W||a.disabled,current:K,defaultCurrent:a.defaultCurrent,defaultPageSize:a.defaultPageSize,dropdownClassName:a.dropdownClassName,hideOnSinglePage:a.hideOnSinglePage,onChange:Ct,onShowSizeChange:(e,t)=>Ft(t),pageSize:T,pageSizeOptions:a.pageSizeOptions,popupPlacement:a.popupPlacement,resolvePopupPlacement:a.resolvePopupPlacement,showQuickJumper:a.showQuickJumper,showSizeChanger:a.showSizeChanger,showTotal:a.showTotal,simple:a.simple,size:a.size,t:a.t??$,total:_e})})]})}const Ne=Jt;Ne.Column=At;Ne.ColumnGroup=Ht;exports.BTable=Ne;
|
|
@@ -125,7 +125,7 @@ function dr({
|
|
|
125
125
|
() => new Map(Z.flatMap((e, t) => e.defaultSortOrder ? [[C(e, t), e.defaultSortOrder]] : []))
|
|
126
126
|
), [jt, mt] = x(
|
|
127
127
|
() => new Map(Z.flatMap((e, t) => e.defaultFilteredValue === void 0 ? [] : [[C(e, t), e.defaultFilteredValue]]))
|
|
128
|
-
), [M, q] = x(null), [ze, X] = x(/* @__PURE__ */ new Map()), [vt, se] = x(null), Nt = ne(`btable-${Math.random().toString(36).slice(2, 10)}`).current, [H, pe] = x(null), [_e, Te] = x(null), [ge, Ke] = x(""), [Y, Se] = x(""), [xt, ye] = x(), je = ne(0), l = R || void 0,
|
|
128
|
+
), [M, q] = x(null), [ze, X] = x(/* @__PURE__ */ new Map()), [vt, se] = x(null), Nt = ne(`btable-${Math.random().toString(36).slice(2, 10)}`).current, [H, pe] = x(null), [_e, Te] = x(null), [ge, Ke] = x(""), [Y, Se] = x(""), [xt, ye] = x(), je = ne(0), l = R || void 0, S = (l == null ? void 0 : l.pageSize) ?? pt, k = (a == null ? void 0 : a.selectedRowKeys) ?? ut, m = Z, P = new Map(gt), B = new Map(jt);
|
|
129
129
|
m.forEach((e, t) => {
|
|
130
130
|
if ("children" in e) return;
|
|
131
131
|
const r = C(e, t);
|
|
@@ -134,13 +134,13 @@ function dr({
|
|
|
134
134
|
const Ve = W(
|
|
135
135
|
() => et(f, m, B),
|
|
136
136
|
[m, B, f]
|
|
137
|
-
),
|
|
137
|
+
), I = W(
|
|
138
138
|
() => tt(Ve, m, P),
|
|
139
139
|
[m, Ve, P]
|
|
140
|
-
), me = (l == null ? void 0 : l.total) ??
|
|
140
|
+
), me = (l == null ? void 0 : l.total) ?? I.length, Le = at(me, S), z = Math.min((l == null ? void 0 : l.current) ?? ue, Le);
|
|
141
141
|
J(() => {
|
|
142
|
-
|
|
143
|
-
}, [
|
|
142
|
+
z !== ue && (l == null ? void 0 : l.current) === void 0 && le(z);
|
|
143
|
+
}, [z, l == null ? void 0 : l.current, ue]), J(() => {
|
|
144
144
|
if (!H || M === null) {
|
|
145
145
|
Te(null);
|
|
146
146
|
return;
|
|
@@ -181,13 +181,13 @@ function dr({
|
|
|
181
181
|
}, [Y, Z, M]);
|
|
182
182
|
const V = W(() => {
|
|
183
183
|
if (!l)
|
|
184
|
-
return
|
|
185
|
-
const e = (
|
|
186
|
-
return
|
|
184
|
+
return I.map((t, r) => ({ record: t, index: r }));
|
|
185
|
+
const e = (z - 1) * S;
|
|
186
|
+
return I.slice(e, e + S).map((t, r) => ({
|
|
187
187
|
record: t,
|
|
188
188
|
index: e + r
|
|
189
189
|
}));
|
|
190
|
-
}, [
|
|
190
|
+
}, [z, S, l, I]), we = W(
|
|
191
191
|
() => V.map(({ record: e, index: t }) => U(e, t, p)),
|
|
192
192
|
[p, V]
|
|
193
193
|
), Ft = k.map(String).join("|"), Dt = we.map(String).join("|");
|
|
@@ -200,10 +200,10 @@ function dr({
|
|
|
200
200
|
const r = new Set(t), n = V.filter(({ record: b, index: s }) => r.has(U(b, s, p))).map(({ record: b }) => b);
|
|
201
201
|
(d = a.onChange) == null || d.call(a, t, n, { type: "multiple" });
|
|
202
202
|
}, [a, p, Ft, Dt, V]);
|
|
203
|
-
const ve = (e, t = P, r = B, n =
|
|
203
|
+
const ve = (e, t = P, r = B, n = z) => {
|
|
204
204
|
const d = Object.fromEntries(r), b = et(f, m, r), s = tt(b, m, t);
|
|
205
205
|
be == null || be(
|
|
206
|
-
{ ...l, current: n, pageSize:
|
|
206
|
+
{ ...l, current: n, pageSize: S, total: (l == null ? void 0 : l.total) ?? s.length },
|
|
207
207
|
d,
|
|
208
208
|
er(m, t),
|
|
209
209
|
{ action: e, currentDataSource: s }
|
|
@@ -247,7 +247,7 @@ function dr({
|
|
|
247
247
|
filters: e.filters,
|
|
248
248
|
close: () => q(null),
|
|
249
249
|
visible: N
|
|
250
|
-
}) : e.filterDropdown, O = e.filterRequest ? xt ?? [] : e.filters ?? [], y = Y && !e.filterRequest ? O.filter((i) => typeof e.filterSearch == "function" ? e.filterSearch(Y, i) : nr(Y, i)) : O,
|
|
250
|
+
}) : e.filterDropdown, O = e.filterRequest ? xt ?? [] : e.filters ?? [], y = Y && !e.filterRequest ? O.filter((i) => typeof e.filterSearch == "function" ? e.filterSearch(Y, i) : nr(Y, i)) : O, K = !!(e.filterSearch || e.filterRequest), v = /* @__PURE__ */ F("div", { className: E("bj-table__column-header", e.sorter && "bj-table__column-header--sortable"), children: [
|
|
251
251
|
e.badge !== void 0 && /* @__PURE__ */ o(
|
|
252
252
|
"span",
|
|
253
253
|
{
|
|
@@ -318,7 +318,7 @@ function dr({
|
|
|
318
318
|
description: i.description,
|
|
319
319
|
value: i.value
|
|
320
320
|
})),
|
|
321
|
-
searchable: ((A = e.filterDropdownProps) == null ? void 0 : A.searchable) ??
|
|
321
|
+
searchable: ((A = e.filterDropdownProps) == null ? void 0 : A.searchable) ?? K,
|
|
322
322
|
searchPlaceholder: ((Xe = e.filterDropdownProps) == null ? void 0 : Xe.searchPlaceholder) ?? (e.filterRequest ? Q("请输入搜索内容") : (G == null ? void 0 : G.filterSearchPlaceholder) ?? Q("搜索")),
|
|
323
323
|
searchValue: ge,
|
|
324
324
|
value: s
|
|
@@ -385,12 +385,12 @@ function dr({
|
|
|
385
385
|
);
|
|
386
386
|
}, Bt = (e) => {
|
|
387
387
|
var t;
|
|
388
|
-
!l || e < 1 || e > Le || e ===
|
|
388
|
+
!l || e < 1 || e > Le || e === z || (l.current === void 0 && le(e), (t = l.onChange) == null || t.call(l, e, S), ve("paginate", P, B, e));
|
|
389
389
|
}, Et = (e) => {
|
|
390
390
|
var r, n;
|
|
391
|
-
if (!l || e ===
|
|
391
|
+
if (!l || e === S)
|
|
392
392
|
return;
|
|
393
|
-
const t = Math.min(
|
|
393
|
+
const t = Math.min(z, at(me, e));
|
|
394
394
|
l.pageSize === void 0 && _t(e), l.current === void 0 && le(t), (r = l.onShowSizeChange) == null || r.call(l, t, e), (n = l.onChange) == null || n.call(l, t, e);
|
|
395
395
|
}, Mt = m.length + (a ? 1 : 0), te = (a == null ? void 0 : a.columnWidth) ?? 48, He = (e) => typeof e.width == "number" ? e.width : 0, We = (e, t) => {
|
|
396
396
|
const r = e.fixed === !0 ? "left" : e.fixed;
|
|
@@ -399,7 +399,7 @@ function dr({
|
|
|
399
399
|
width: c.x === !0 ? "max-content" : c.x,
|
|
400
400
|
minWidth: "100%",
|
|
401
401
|
tableLayout: Be ?? "fixed"
|
|
402
|
-
} : { tableLayout: Be }, zt = (j == null ? void 0 : j.table) ?? "table", Tt = ((Je = j == null ? void 0 : j.header) == null ? void 0 : Je.wrapper) ?? "thead", Kt = ((Qe = j == null ? void 0 : j.header) == null ? void 0 : Qe.row) ?? "tr", Ue = ((Ze = j == null ? void 0 : j.header) == null ? void 0 : Ze.cell) ?? "th",
|
|
402
|
+
} : { tableLayout: Be }, zt = (j == null ? void 0 : j.table) ?? "table", Tt = ((Je = j == null ? void 0 : j.header) == null ? void 0 : Je.wrapper) ?? "thead", Kt = ((Qe = j == null ? void 0 : j.header) == null ? void 0 : Qe.row) ?? "tr", Ue = ((Ze = j == null ? void 0 : j.header) == null ? void 0 : Ze.cell) ?? "th", T = typeof (j == null ? void 0 : j.body) == "object" ? j.body : void 0, St = (T == null ? void 0 : T.wrapper) ?? "tbody", $e = (T == null ? void 0 : T.row) ?? "tr", Fe = (T == null ? void 0 : T.cell) ?? "td", Vt = typeof de == "function" ? de() : de ?? Q("暂无数据"), Ge = typeof oe == "string" ? /* @__PURE__ */ o("img", { alt: "", className: "bj-table__empty-image", src: oe }) : oe;
|
|
403
403
|
return /* @__PURE__ */ F(
|
|
404
404
|
"div",
|
|
405
405
|
{
|
|
@@ -410,12 +410,12 @@ function dr({
|
|
|
410
410
|
it && "bj-table--bordered",
|
|
411
411
|
`bj-table--${nt}`,
|
|
412
412
|
$ && "bj-table--loading",
|
|
413
|
-
|
|
413
|
+
I.length === 0 && "bj-table--empty",
|
|
414
414
|
ct
|
|
415
415
|
),
|
|
416
416
|
style: bt,
|
|
417
417
|
children: [
|
|
418
|
-
Pe && /* @__PURE__ */ o("div", { className: "bj-table__title", children: Pe(
|
|
418
|
+
Pe && /* @__PURE__ */ o("div", { className: "bj-table__title", children: Pe(I) }),
|
|
419
419
|
/* @__PURE__ */ F("div", { className: "bj-table__viewport", children: [
|
|
420
420
|
/* @__PURE__ */ o(
|
|
421
421
|
"div",
|
|
@@ -474,12 +474,12 @@ function dr({
|
|
|
474
474
|
colSpan: n,
|
|
475
475
|
key: s.key ?? String(s.dataIndex ?? b),
|
|
476
476
|
onClick: (y) => {
|
|
477
|
-
var
|
|
478
|
-
(A = (v = (
|
|
477
|
+
var K, v, A;
|
|
478
|
+
(A = (v = (K = s.onHeaderCell) == null ? void 0 : K.call(s, r, b)) == null ? void 0 : v.onClick) == null || A.call(v, y), !y.target.closest(".bj-table__filter-dropdown") && (h ? ie(s, _, y.currentTarget) : w());
|
|
479
479
|
},
|
|
480
480
|
onKeyDown: (y) => {
|
|
481
|
-
var
|
|
482
|
-
(A = (v = (
|
|
481
|
+
var K, v, A;
|
|
482
|
+
(A = (v = (K = s.onHeaderCell) == null ? void 0 : K.call(s, r, b)) == null ? void 0 : v.onKeyDown) == null || A.call(v, y), !y.target.closest(".bj-table__filter-dropdown") && (y.key === "Enter" || y.key === " ") && (y.preventDefault(), h ? ie(s, _, y.currentTarget) : w());
|
|
483
483
|
},
|
|
484
484
|
rowSpan: d,
|
|
485
485
|
scope: "col",
|
|
@@ -520,7 +520,7 @@ function dr({
|
|
|
520
520
|
),
|
|
521
521
|
m.map((N, _) => {
|
|
522
522
|
var v;
|
|
523
|
-
const h = N, L = sr(e, h.dataIndex), w = h.render ? h.render(L, e, t) : L, O = ir(w) ? w : void 0, y = { ...(v = h.onCell) == null ? void 0 : v.call(h, e, t), ...O == null ? void 0 : O.props },
|
|
523
|
+
const h = N, L = sr(e, h.dataIndex), w = h.render ? h.render(L, e, t) : L, O = ir(w) ? w : void 0, y = { ...(v = h.onCell) == null ? void 0 : v.call(h, e, t), ...O == null ? void 0 : O.props }, K = O ? O.children : w;
|
|
524
524
|
return y.colSpan === 0 || y.rowSpan === 0 ? null : /* @__PURE__ */ De(
|
|
525
525
|
Fe,
|
|
526
526
|
{
|
|
@@ -537,7 +537,7 @@ function dr({
|
|
|
537
537
|
key: h.key ?? String(h.dataIndex ?? _),
|
|
538
538
|
style: { textAlign: h.align, ...We(h, _), ...y.style }
|
|
539
539
|
},
|
|
540
|
-
/* @__PURE__ */ o("div", { className: "bj-table__cell-content", children:
|
|
540
|
+
/* @__PURE__ */ o("div", { className: "bj-table__cell-content", children: K ?? "" })
|
|
541
541
|
);
|
|
542
542
|
})
|
|
543
543
|
);
|
|
@@ -549,7 +549,7 @@ function dr({
|
|
|
549
549
|
style: { height: ot }
|
|
550
550
|
}
|
|
551
551
|
) }) }),
|
|
552
|
-
Re && /* @__PURE__ */ o("tfoot", { className: "bj-table__summary", children: Re(
|
|
552
|
+
Re && /* @__PURE__ */ o("tfoot", { className: "bj-table__summary", children: Re(I) })
|
|
553
553
|
] })
|
|
554
554
|
}
|
|
555
555
|
),
|
|
@@ -570,24 +570,24 @@ function dr({
|
|
|
570
570
|
targetRef: Ee
|
|
571
571
|
}
|
|
572
572
|
),
|
|
573
|
-
Oe && /* @__PURE__ */ o("div", { className: "bj-table__footer", children: Oe(
|
|
573
|
+
Oe && /* @__PURE__ */ o("div", { className: "bj-table__footer", children: Oe(I) }),
|
|
574
574
|
$ && /* @__PURE__ */ F("div", { "aria-live": "polite", "aria-busy": "true", className: "bj-table__loading", role: "status", children: [
|
|
575
575
|
/* @__PURE__ */ o("img", { alt: "", className: "bj-table__loading-indicator", src: Jt }),
|
|
576
576
|
/* @__PURE__ */ o("span", { className: "bj-table__loading-text", children: "加载中..." })
|
|
577
577
|
] }),
|
|
578
|
-
l && /* @__PURE__ */ o("div", { className: "bj-table__pagination", children: /* @__PURE__ */ o(
|
|
578
|
+
l && I.length > 0 && /* @__PURE__ */ o("div", { className: "bj-table__pagination", children: /* @__PURE__ */ o(
|
|
579
579
|
qt,
|
|
580
580
|
{
|
|
581
581
|
align: "end",
|
|
582
582
|
disabled: $ || l.disabled,
|
|
583
|
-
current:
|
|
583
|
+
current: z,
|
|
584
584
|
defaultCurrent: l.defaultCurrent,
|
|
585
585
|
defaultPageSize: l.defaultPageSize,
|
|
586
586
|
dropdownClassName: l.dropdownClassName,
|
|
587
587
|
hideOnSinglePage: l.hideOnSinglePage,
|
|
588
588
|
onChange: Bt,
|
|
589
589
|
onShowSizeChange: (e, t) => Et(t),
|
|
590
|
-
pageSize:
|
|
590
|
+
pageSize: S,
|
|
591
591
|
pageSizeOptions: l.pageSizeOptions,
|
|
592
592
|
popupPlacement: l.popupPlacement,
|
|
593
593
|
resolvePopupPlacement: l.resolvePopupPlacement,
|