Files
workspace/code/fms/fms-vue/.tmp-build/assets/FmsTable-CCmDuvFF.js
T
2026-09-05 17:25:35 +08:00

1 line
16 KiB
JavaScript

import{$ as e,A as t,B as n,K as r,L as i,Lt as a,M as o,O as s,Q as c,R as l,Rt as u,S as d,T as ee,U as te,V as ne,Z as re,_ as f,ft as ie,gt as p,it as m,k as ae,pt as h,t as g,ut as _,v as oe,wt as se,x as ce}from"./_plugin-vue_export-helper-Ktpf6lZe.js";import{t as le}from"./stk-table-vue-DM4qMzbH.js";import{n as ue}from"./app-BeHz6434.js";import{D as v,b as y,g as b,h as x,m as de}from"./ui-BhP3ZSBa.js";o();var S=e=>e.stopPropagation();function fe({getDataSource:e,getRowKey:n,getSelectedRowKeys:r,isRowDisabled:i=()=>!1,onChange:a}){let o=f(()=>new Set(r())),s=f(()=>{let t=new Map;for(let r of e())t.set(n(r),r);return t});function c(e){a(e,e.map(e=>s.value.get(e)).filter(Boolean))}function l(e,t){if(i(e))return;let r=new Set(o.value),a=n(e);t?r.add(a):r.delete(a),c(Array.from(r))}function u(t){let r=new Set(o.value);e().forEach(e=>{if(i(e))return;let a=n(e);t?r.add(a):r.delete(a)}),c(Array.from(r))}return{dataIndex:`__fmsSelection`,key:`__fmsSelection`,title:``,width:44,fixed:`left`,align:`center`,headerAlign:`center`,customCell:({row:e})=>{let r=n(e),a=i(e),s=o.value.has(r);return t(`label`,{class:[`fms-checkbox`,{checked:s,disabled:a}],onClick:S,onMousedown:S},[t(`input`,{type:`checkbox`,checked:s,disabled:a,onChange:t=>{t.stopPropagation(),l(e,t.target.checked)},onClick:S,onMousedown:S}),t(`span`,{class:`fms-checkbox-box`})])},customHeaderCell:()=>{let n=e().filter(e=>!i(e)),r=0;for(let e of o.value)s.value.has(e)&&r++;let a=n.length>0&&r===n.length,c=r>0&&r<n.length;return t(`label`,{class:a?`fms-checkbox checked`:c?`fms-checkbox indeterminate`:`fms-checkbox`,onClick:S},[t(`input`,{type:`checkbox`,checked:a,onChange:e=>{e.stopPropagation(),u(e.target.checked)},onClick:S}),t(`span`,{class:`fms-checkbox-box`})])},__fmsSelection:!0}}function C(e){return e?.__fmsSelection===!0}o(),m();var w=e=>e.stopPropagation(),T=new WeakMap,E={text:`default`,default:`default`,password:`password`,number:`number`,textarea:`textarea`};function pe(e,t){let n=T.get(e);return n?.has(t)?n.get(t):e[t]}function D(e,t,n){let r=T.get(e);r||(r=new Map,T.set(e,r)),r.set(t,n)}function O(e,t){let n=T.get(e);n&&(n.delete(t),n.size||T.delete(e))}function k(e,t,n){O(e,t),e[t]=n}function A(e,t){let n=T.get(e);n?.has(t)&&(h(e)[t]=n.get(t),O(e,t))}function j(e){return typeof e.options==`function`?e.options():e.options??[]}function M(e,n,r){let i=e[n.dataIndex],a=(r.type===`select`?j(r).find(e=>String(e.value)===String(i))?.label??i:i)??``;return t(`span`,{class:`fms-cell-display`,title:String(a)},a)}function N(e,t,n,r,i){e.shouldNotify(n,r,i)&&(t.onChange?.(i,n,r),e.onChange(n,r,i))}function P(e,t){return typeof e.disabled==`function`?!!e.disabled(t):!!e.disabled}function F(e,t,n,r=!1){return({component:i,el:a})=>{if(!e.shouldFocus(t,n))return;let o=e.consumePendingFocus?.(t),s=!!e.wasFocused?.(t);if(!o&&!s)return;let c=a?.matches?.(`input`)?a:a?.querySelector?.(`input`);if(document.activeElement===c)return;let l=i?.exposed||i?.proxy,u=r&&(o||s),d=u?{cursor:`all`,preventScroll:!0}:{preventScroll:!0};if(l?.focus){l.focus(d);return}c?.focus(d),u&&c?.select()}}function I(e,n,r,i){let a=F(i,e,n,!0);return t(b,{type:E[r.inputType||`text`]??`default`,modelValue:pe(e,n.dataIndex)??``,class:`fms-cell-editor fms-cell-editor-root`,"aria-label":n.title||n.dataIndex,"onUpdate:modelValue":t=>{D(e,n.dataIndex,t)},onFocus:()=>i.onEditorFocus?.(e),onBlur:t=>{i.onEditorBlur?.(e);let a=t.target.value;k(e,n.dataIndex,a),N(i,r,e,n,a)},onKeydown:e=>{e.key===`Enter`?(e.preventDefault(),e.stopPropagation(),e.target.select()):e.key===`Escape`&&e.target.blur()},onClick:w,onVnodeMounted:a,onVnodeUpdated:a,onVnodeBeforeUnmount:()=>A(e,n.dataIndex)})}function L(e,n,r,i){let a=j(r),o=F(i,e,n);return t(de,{modelValue:e[n.dataIndex]??void 0,options:a,clearable:r.allowClear??!0,filterable:!1,class:`fms-cell-editor fms-cell-editor-root`,"aria-label":n.title||n.dataIndex,"onUpdate:modelValue":t=>{let a=t??r.emptyValue??null;e[n.dataIndex]=a,N(i,r,e,n,a)},onClick:w,onVnodeMounted:o,onVnodeUpdated:o})}function R(e,n,r,i){let a=e[n.dataIndex]===1,o=i.isEditing(e)?F(i,e,n):void 0,s=t=>{e[n.dataIndex]=t,N(i,r,e,n,t)};return t(`label`,{class:a?`fms-checkbox fms-cell-editor-root checked`:`fms-checkbox fms-cell-editor-root`,onClick:w,onMousedown:w},[t(`input`,{type:`checkbox`,checked:a,"aria-label":n.title||n.dataIndex,onChange:e=>{s(+!!e.target.checked)},onKeydown:t=>{if(t.key!==`Enter`)return;t.preventDefault(),t.stopPropagation();let r=e[n.dataIndex]===1?0:1;t.currentTarget.checked=r===1,s(r)},onClick:w,onMousedown:w,onVnodeMounted:o,onVnodeUpdated:o}),t(`span`,{class:`fms-checkbox-box`})])}function z(e,t){let n=e.editor;return({row:r})=>P(n,r)?M(r,e,n):n?.type===`checkbox`?R(r,e,n,t):t.isEditing(r)?n.type===`select`?L(r,e,n,t):I(r,e,n,t):M(r,e,n)}o(),m();var B=e=>e.stopPropagation();function V(e,t){return typeof e==`function`?!!e(t):!!e}function H(e,t){return e.visible===void 0||V(e.visible,t)}function me(e,n,r,i=`fms-action-btn`){let a=V(e.disabled,n),o=[];return e.icon&&o.push(t(e.icon,{size:14})),(e.label||e.type)&&o.push(e.label||e.type),t(`button`,{type:`button`,class:[i,{"fms-action-btn--danger":e.danger||e.type===`danger`||e.type===`delete`}],title:e.title||e.label,disabled:a,onMousedown:B,onClick:t=>{t.stopPropagation(),r(e,n)}},o)}function U(e,n){let{action:r,row:i}=e.value,a=typeof r.confirm==`string`?{title:r.confirm}:r.confirm||{},o=a.title||`确认操作`,s=a.description??a.content??`确定要执行此操作吗?`,c=a.okText||`确定`,l=a.cancelText||`取消`,u=(a.okType??`danger`)===`danger`?()=>[t(v,{type:`outline`,onClick:n},()=>l),t(v,{type:`danger`,onClick:()=>{n(),r.onClick?.(i)}},()=>c)]:void 0;return t(x,{open:!0,title:o,width:a.width??416,centered:!0,closable:!1,fullscreen:!1,resizable:!1,maskClosable:!!(a.maskClosable??!1),okText:c,cancelText:l,"onUpdate:open":e=>{e||n()},onCancel:n,onOk:()=>{n(),r.onClick?.(i)}},{default:()=>t(`div`,{class:`fms-confirm-content`},s),footer:u})}function he(e){if(!e?.length)return;let n=e.filter(e=>e.type!==`more`),r=e.find(e=>e.type===`more`),i=_(null),a=_(null),o=new Map(r?.items?.map((e,t)=>[String(e.key??e.type??t),e])??[]);function s(){i.value=null}function c(){a.value=null}function l(e,t){if(!V(e.disabled,t)){if(!e.confirm){e.onClick?.(t);return}a.value={action:e,row:t}}}return({row:e})=>{let u=n.filter(t=>H(t,e)).map(t=>me(t,e,l)),d=(r?.items||[]).filter(t=>H(t,e));if(a.value&&u.push(U(a,c)),!d.length)return t(`span`,{class:`fms-actions-cell`},u);let ee=d.map((n,r)=>({key:String(n.key??n.type??r),label:n.label,icon:n.icon?t(n.icon,{size:14}):void 0,disabled:V(n.disabled,e),danger:n.danger||n.type===`danger`||n.type===`delete`})),te=new Map(d.map((e,t)=>[String(e.key??e.type??t),e]));return i.value===e?u.push(t(y,{open:!0,placement:`bottom-end`,offset:4,items:ee,"onUpdate:open":e=>{e||s()},onClick:({key:t})=>{let n=te.get(String(t))||o.get(String(t));s(),n&&l(n,e)}},{default:()=>t(`button`,{type:`button`,class:`fms-action-btn fms-action-more fms-action-more-open`,title:r.title||`更多操作`,"aria-label":r.title||`更多操作`,onMousedown:B,onClick:B},r.label||`⋯`)})):u.push(t(`button`,{type:`button`,class:`fms-action-btn fms-action-more`,title:r.title||`更多操作`,"aria-label":r.title||`更多操作`,onMousedown:B,onClick:t=>{t.stopPropagation(),i.value=e}},r.label||`⋯`)),t(`span`,{class:`fms-actions-cell`},u)}}function ge(e,t,n=!0){if(e.customCell)return e;if(e.editor&&(n||e.editor.type===`checkbox`||e.editor.type===`select`))return{...e,customCell:z(e,t)};if(e.actions?.length){let t=he(e.actions);if(t)return{...e,customCell:t}}return e}m(),se(),o();var _e=100,ve=20,ye=150,W=g(Object.assign({inheritAttrs:!1},{__name:`FmsTable`,props:{virtual:{type:Boolean,default:!0},virtualX:{type:Boolean,default:!0},autoFitWidth:{type:Boolean,default:!1},colResizable:{type:[Boolean,Object],default:!0},bordered:{type:[Boolean,String],default:!0},noDataFull:{type:Boolean,default:!0},showOverflow:{type:Boolean,default:!0},columns:{type:Array,default:()=>[]},seq:{type:[Boolean,Object],default:!0},columnDraggable:{type:[Boolean,Object],default:!0},rowSelection:{type:Object,default:null},dataSource:{type:Array,default:()=>[]},rowKey:{type:[String,Function],default:`id`},activeRowKey:{type:[String,Number],default:null},rowDraggable:{type:Boolean,default:!1},editable:{type:Boolean,default:!0},theme:{type:String,default:void 0,validator:e=>e===`light`||e===`dark`},rowHeight:{type:Number,default:30},headerRowHeight:{type:Number,default:34}},emits:[`update:columns`,`change`,`row-order-change`],setup(t,{expose:o,emit:m}){let h=t,g=m,se=f(()=>h.virtual&&h.dataSource.length>_e),v=f(()=>h.virtualX&&J.value.length>ve),y=_(null),b=_(null),x=re(),de=ue(),S=f(()=>h.theme??(de.darkMode?`dark`:`light`)),w=`onUpdate:columns`in(s()?.vnode.props??{}),T=w&&!h.autoFitWidth?h.colResizable:!1,E=0;function pe(e=!1){E&&cancelAnimationFrame(E),E=requestAnimationFrame(async()=>{E=0,await l(),e?b.value?.initVirtualScrollX?.():b.value?.initVirtualScroll?.(),await l()})}let D=0,O=null,k=null;ne(()=>{typeof ResizeObserver<`u`&&y.value&&(k=new ResizeObserver(([e])=>{let{width:t,height:n}=e.contentRect;t<=0||n<=0||(clearTimeout(D),D=setTimeout(()=>{D=0;let e=O!=null&&O.height===n&&O.width!==t;O={width:t,height:n},pe(e)},ye))}),k.observe(y.value))});let A=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Tab`]),j=new WeakMap,M=null,N=null,P=new Set,F=_(!1);function I(e){return typeof h.rowKey==`function`?h.rowKey(e):e?.[h.rowKey]}function L(e){if(!e||typeof e!=`object`)return null;let t=j.get(e);return t||(t=ie({editing:!1,focusCol:null,initialValues:null}),j.set(e,t)),t}function R(e){return new Map(h.columns.filter(e=>e.editor).map(t=>[t.dataIndex,e[t.dataIndex]]))}function z(e){let t=j.get(e);t&&t.value.editing&&(t.value={editing:!1,focusCol:null,initialValues:null})}function B(){if(!M)return;let e=j.get(M);M=null,F.value=!1,e&&e.value.editing&&(e.value={editing:!1,focusCol:null,initialValues:null})}function V(e){if(!M||e.includes(M))return;let t=M,n=j.get(t)?.value,r=I(t),i=r==null?null:e.find(e=>String(I(e))===String(r));if(M=null,z(t),!i||!n?.editing){F.value=!1;return}let a=L(i);M=i,F.value=!0,a.value={editing:!0,focusCol:n.focusCol,focused:n.focused,initialValues:R(i)}}function H(e,t){if(!h.editable||!e)return;let n=L(e);if(!n)return;if(M!==e){M&&z(M),M=e,F.value=!0,n.value={editing:!0,focusCol:t,initialValues:R(e)},U=String(I(e));return}let r=n.value;r.editing&&r.focusCol===t||(n.value={...r,editing:!0,focusCol:t},U=String(I(e)))}function me(e,t,n){return e.editor?.type===`select`||e.editor?.type===`checkbox`?Object.is(t,n):String(t??``)===String(n??``)}let U=null,he={isEditing:e=>h.editable&&L(e)?.value.editing,shouldFocus:(e,t)=>L(e)?.value.focusCol===t.dataIndex,wasFocused:e=>!!L(e)?.value.focused,consumePendingFocus:e=>U==null||U!==String(I(e))?!1:(U=null,!0),onEditorFocus:e=>{let t=L(e);t?.value&&(t.value={...t.value,focused:!0})},onEditorBlur:e=>{let t=L(e);t?.value&&(t.value={...t.value,focused:!1})},shouldNotify:(e,t,n)=>{let r=L(e)?.value.initialValues;return!r?.has(t.dataIndex)||!me(t,r.get(t.dataIndex),n)&&(r.set(t.dataIndex,n),!0)},onChange:(e,t,n)=>{g(`change`,e,t,n)}},W=f(()=>{if(!h.seq)return{enabled:!1,title:`序号`,width:50};let e=h.seq===!0?{}:h.seq;return{enabled:!0,title:e.title??`序号`,width:Number(e.width??50)}}),G=_(W.value.width);c(()=>W.value.width,e=>{G.value=e},{immediate:!0});let be=f(()=>{if(!w||!h.columnDraggable)return!1;let e=h.columnDraggable===!0?{}:h.columnDraggable;return{...e,disabled:t=>C(t)||t.type===`seq`||t.type===`dragRow`||t.type===`expand`||t.dataIndex===``||t.dataIndex===`__actions__`?!0:typeof e.disabled==`function`?e.disabled(t):!!e.disabled}}),xe=f(()=>!!h.rowSelection),K=_(44),Se={type:`dragRow`,dataIndex:`__drag_row__`,title:``,width:40},q=_(Se.width);function Ce(e){return e.headerAlign?e.headerAlign:e.type===`seq`||C(e)||e.dataIndex===`actions`||e.actions&&e.actions.length||e.checkbox===!0||e.editor&&e.editor.type===`checkbox`?`center`:`left`}let J=f(()=>{let e=h.columns.map(e=>ge(e,he,F.value)),t=W.value;return t.enabled&&e.unshift({type:`seq`,width:G.value,dataIndex:``,title:t.title}),h.rowDraggable&&e.unshift({...Se,width:q.value}),xe.value&&e.unshift({...De,width:K.value}),e.map(e=>({...e,headerAlign:Ce(e)}))});function we(e){for(let t of e||[])C(t)&&t.width!=null?K.value=Number.parseInt(t.width,10)||K.value:t.type===`seq`&&t.width!=null?G.value=Number.parseInt(t.width,10)||G.value:t.type===`dragRow`&&t.width!=null&&(q.value=Number.parseInt(t.width,10)||q.value);let t=new Map(h.columns.map(e=>[String(e.key??e.dataIndex??``),e])),n=(e||[]).filter(e=>!C(e)&&e.type!==`seq`&&e.type!==`dragRow`&&e.dataIndex!==``).map(e=>{let n=t.get(String(e.key??e.dataIndex??``));return n?{...n,width:e.width??n.width}:e});g(`update:columns`,n)}function Te(e,t){let n=b.value?.getTableData?.()??h.dataSource;b.value?.clearSelectedArea?.(),g(`row-order-change`,[...n],e,t)}let Ee={"--th-bgc":`var(--fms-table-header-bg)`,"--tf-bgc":`var(--fms-background)`},De=fe({getDataSource:()=>h.dataSource,getRowKey:I,getSelectedRowKeys:()=>h.rowSelection?.selectedRowKeys??[],isRowDisabled:e=>!!h.rowSelection?.getCheckboxProps?.(e)?.disabled,onChange:(e,t)=>h.rowSelection?.onChange?.(e,t)});async function Oe(e){await l();let t=b.value;if(!t)return;let n=h.dataSource.findIndex(t=>String(I(t))===String(e));n<0||t.scrollTo(n*h.rowHeight,null)}async function ke(e,t=null){await Oe(e),await l();let n=h.dataSource.find(t=>String(I(t))===String(e));n&&(b.value?.setCurrentRow?.(n,{silent:!0}),H(n,t))}function Ae(){return b.value?.getSelectedArea?.()}function je(){b.value?.clearSelectedArea?.()}function Me(...e){return b.value?.setRowExpand?.(...e)}function Ne(){return b.value?.initVirtualScroll?.()}let Y=null,X=0,Z=!1;function Q(){Y&&=(clearTimeout(Y),null)}function Pe(){Q(),Y=setTimeout(()=>{Y=null,Fe()},100)}function Fe(){let e=N;if(N=null,!e)return;let t=h.dataSource.find(t=>t===e.row||String(I(t))===String(I(e.row)));t&&(H(t,e.focusCol),b.value?.setCurrentRow?.(t,{silent:!0}),X=performance.now())}function $(){window.removeEventListener(`keyup`,Le,!0),window.removeEventListener(`blur`,Re)}function Ie(e){A.has(e.key)&&(P.size||(window.addEventListener(`keyup`,Le,!0),window.addEventListener(`blur`,Re)),P.add(e.key),e.repeat&&(Z=!0))}function Le(e){if(A.has(e.key)&&!(!P.delete(e.key)||P.size)){if($(),Z){Z=!1,Q(),Fe();return}N&&Pe()}}function Re(){$(),P.clear(),Z=!1,Q(),Fe()}function ze(e){if(!h.editable)return;let t=e?.at(-1)?.index.end,n=t?b.value?.getTableData?.()[t.row]:null,r=t?J.value[t.col]:null;if(!n){N=null,B(),Q();return}let i=r?.editor?r.dataIndex:null;if(P.size>0){if(Z)N={row:n,focusCol:i},B();else{let e=performance.now();e-X>=150?(N=null,Q(),H(n,i),b.value?.setCurrentRow?.(n,{silent:!0}),X=e):(N={row:n,focusCol:i},Pe())}return}N=null,Q(),H(n,i),X=performance.now()}return c([()=>h.activeRowKey,()=>h.dataSource],async([e])=>{if(V(h.dataSource),await l(),e==null){b.value?.setCurrentRow?.(void 0,{silent:!0});return}let t=h.dataSource.find(t=>String(I(t))===String(e));b.value?.setCurrentRow?.(t,{silent:!0})},{immediate:!0}),c(()=>h.editable,e=>{e||(N=null,$(),P.clear(),Z=!1,Q(),B(),b.value?.clearSelectedArea?.())}),n(()=>{E&&cancelAnimationFrame(E),clearTimeout(D),k?.disconnect(),k=null,$(),Q(),P.clear()}),o({scrollToRow:Oe,editRow:ke,getSelectedArea:Ae,clearSelectedArea:je,setRowExpand:Me,initVirtualScroll:Ne,refreshLayout:Ne}),(n,o)=>(te(),ce(`div`,{ref_key:`rootRef`,ref:y,class:a([`fms-table`,[t.bordered?`fms-table--bordered`:``,t.autoFitWidth?`fms-table--auto-fit-width`:``]]),onKeydownCapture:Ie},[ee(p(le),i({ref_key:`tableRef`,ref:b,class:`fms-table__inner`},n.$attrs,{style:Ee,theme:S.value,"row-height":h.rowHeight,"header-row-height":h.headerRowHeight,virtual:se.value,"virtual-x":v.value,"smooth-scroll":!0,"auto-resize":!1,"col-resizable":p(T),"header-drag":be.value,columns:J.value,"onUpdate:columns":we,"data-source":t.dataSource,"drag-row-config":{mode:t.rowDraggable?`insert`:`none`},"row-key":t.rowKey,"no-data-full":t.noDataFull,"show-overflow":t.showOverflow,"empty-cell-text":``,"area-selection":t.editable,bordered:!1,onAreaSelectionChange:ze,onRowOrderChange:Te}),d({_:2},[p(x).expand?{name:`expand`,fn:e(e=>[r(n.$slots,`expand`,u(ae(e)),void 0,!0)]),key:`0`}:void 0,p(x).empty?{name:`empty`,fn:e(()=>[r(n.$slots,`empty`,{},void 0,!0)]),key:`1`}:{name:`empty`,fn:e(()=>[o[0]||=oe(`div`,{class:`fms-table__empty`,role:`status`},[oe(`strong`,null,`暂无数据`)],-1)]),key:`2`}]),1040,[`theme`,`row-height`,`header-row-height`,`virtual`,`virtual-x`,`col-resizable`,`header-drag`,`columns`,`data-source`,`drag-row-config`,`row-key`,`no-data-full`,`show-overflow`,`area-selection`])],34))}}),[[`__scopeId`,`data-v-23d7efce`]]);export{W as t};