2 lines
6.0 KiB
Java
2 lines
6.0 KiB
Java
var ie=Object.defineProperty;var G=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var J=(p,m,a)=>m in p?ie(p,m,{enumerable:!0,configurable:!0,writable:!0,value:a}):p[m]=a,R=(p,m)=>{for(var a in m||(m={}))ce.call(m,a)&&J(p,a,m[a]);if(G)for(var a of G(m))re.call(m,a)&&J(p,a,m[a]);return p};import{e as ue,h as me,C,z as _,Q as w,H as K,f,A as x,F as z,D as L,c as b,T as pe,K as de,E as S,R as N,J as fe,b as ve}from"./vue-vendor-DNhG1Cve.js";import{aE as Ce,av as _e,aw as xe,aG as ge,au as we}from"./index-X7Y8jykP.js";import Me from"./index-DklMb9Qc.js";import"./emoji-mart-vue-fast-R0uJEDq-.js";import"./UpOutlined-B1UMbtrP.js";const he={class:"header-config-editor"},be={class:"toolbar"},Se={class:"grid-table"},ye=["rowspan","colspan","onMousedown","onMousemove","onContextmenu"],$e=ue({__name:"TableHeaderConfigEditor",props:{rowCount:{},colCount:{},columnTitles:{},value:{}},emits:["update:value"],setup(p,{emit:m}){const a=p,A=m,o=ve({cells:[],selecting:!1,selection:{r1:0,c1:0,r2:0,c2:0},contextMenu:{visible:!1,x:0,y:0}}),M=b(()=>Math.max(1,Number(a.colCount||1))),g=b(()=>Math.max(1,Number(a.rowCount||1)));function B(t){var n;const e=(n=a.columnTitles)==null?void 0:n[t];return String(e||`列${t+1}`)}function E(t,e){const n=[];for(let l=0;l<t;l+=1)for(let i=0;i<e;i+=1)n.push({id:`h_${l}_${i}_${Math.random().toString(36).slice(2,8)}`,row:l,col:i,rowspan:1,colspan:1,title:l===t-1?B(i):`表头${l+1}-${i+1}`,align:"center"});return n}function Q(t,e,n){return!n||!Array.isArray(n.cells)||n.colCount!==e||n.rowCount!==t?E(t,e):n.cells.map(l=>R({},l))}me(()=>[a.rowCount,a.colCount,a.value],()=>{o.cells=Q(g.value,M.value,a.value)},{immediate:!0,deep:!0});function y(){A("update:value",{rowCount:g.value,colCount:M.value,cells:o.cells.map(t=>R({},t))})}function v(t,e){return o.cells.find(n=>n.row===t&&n.col===e)}function $(t,e){return o.cells.find(n=>t>=n.row&&t<n.row+n.rowspan&&e>=n.col&&e<n.col+n.colspan)}function X(t,e){return!!v(t,e)}function V(t,e){const n=Math.min(o.selection.r1,o.selection.r2),l=Math.max(o.selection.r1,o.selection.r2),i=Math.min(o.selection.c1,o.selection.c2),r=Math.max(o.selection.c1,o.selection.c2);return t>=n&&t<=l&&e>=i&&e<=r}function Y(t,e){var l;const n=v(t,e);return{selected:V(t,e),focused:(n==null?void 0:n.id)===((l=$(o.selection.r2,o.selection.c2))==null?void 0:l.id)}}function q(t,e){o.selecting=!0,o.selection={r1:t,c1:e,r2:t,c2:e},k()}function P(t,e){o.selecting&&(o.selection.r2=t,o.selection.c2=e)}function W(){o.selecting=!1}function Z(t,e,n){const l=v(t,e);l&&(l.title=String(n||""),y())}function U(){return{minR:Math.min(o.selection.r1,o.selection.r2),maxR:Math.max(o.selection.r1,o.selection.r2),minC:Math.min(o.selection.c1,o.selection.c2),maxC:Math.max(o.selection.c1,o.selection.c2)}}function ee(){const{minR:t,maxR:e,minC:n,maxC:l}=U(),i=o.cells.filter(s=>s.row>=t&&s.row<=e&&s.col>=n&&s.col<=l),r=(e-t+1)*(l-n+1);return i.length===r&&i.every(s=>s.rowspan===1&&s.colspan===1)}function H(){if(!ee())return;const{minR:t,maxR:e,minC:n,maxC:l}=U(),i=Array.from({length:l-n+1}).map((s,d)=>{const c=n+d,u=$(g.value-1,c);return String((u==null?void 0:u.title)||B(c))}),r=v(t,n);r&&(r.rowspan=e-t+1,r.colspan=l-n+1,e===g.value-1&&(r.title=n===l?i[0]:i.join(" / ")),o.cells=o.cells.filter(s=>s===r||s.row<t||s.row>e||s.col<n||s.col>l),y())}function D(){const t=$(o.selection.r2,o.selection.c2);if(!t||t.rowspan===1&&t.colspan===1)return;const{row:e,col:n,rowspan:l,colspan:i,title:r}=t;o.cells=o.cells.filter(s=>s.id!==t.id);for(let s=e;s<e+l;s+=1)for(let d=n;d<n+i;d+=1)o.cells.push({id:`h_${s}_${d}_${Math.random().toString(36).slice(2,8)}`,row:s,col:d,rowspan:1,colspan:1,title:s===e&&d===n?r:"",align:t.align||"center"});y()}function te(t){const e=Math.max(1,Math.min(6,Number(t||1)));o.cells=E(e,M.value),A("update:value",{rowCount:e,colCount:M.value,cells:o.cells.map(n=>R({},n))})}function ne(t,e,n){V(e,n)||(o.selection={r1:e,c1:n,r2:e,c2:n}),o.contextMenu={visible:!0,x:t.clientX,y:t.clientY}}function k(){o.contextMenu.visible=!1}function oe(){H(),k()}function le(){D(),k()}const T=b(()=>o.contextMenu),F=b(()=>$(o.selection.r2,o.selection.c2)),se=b(()=>{var t;return String(((t=F.value)==null?void 0:t.align)||"center")});function ae(t){const e=F.value;e&&(e.align=String(t||"center"),y())}return(t,e)=>{const n=Me,l=xe,i=_e,r=de("a-button"),s=Ce,d=ge;return _(),C("div",he,[w("div",be,[f(s,null,{default:x(()=>[f(n,{value:g.value,min:1,max:6,"addon-before":"表头行数","onUpdate:value":e[0]||(e[0]=c=>te(Number(c||1)))},null,8,["value"]),f(i,{value:se.value,style:{width:"120px"},"onUpdate:value":e[1]||(e[1]=c=>ae(c))},{default:x(()=>[f(l,{value:"left"},{default:x(()=>[...e[2]||(e[2]=[S("左对齐",-1)])]),_:1}),f(l,{value:"center"},{default:x(()=>[...e[3]||(e[3]=[S("居中",-1)])]),_:1}),f(l,{value:"right"},{default:x(()=>[...e[4]||(e[4]=[S("右对齐",-1)])]),_:1})]),_:1},8,["value"]),f(r,{size:"small",onClick:H},{default:x(()=>[...e[5]||(e[5]=[S("合并选中",-1)])]),_:1}),f(r,{size:"small",onClick:D},{default:x(()=>[...e[6]||(e[6]=[S("拆分当前",-1)])]),_:1})]),_:1})]),w("div",{class:"grid-wrap",onClick:k},[w("table",Se,[w("tbody",null,[(_(!0),C(z,null,L(g.value,c=>(_(),C("tr",{key:`row_${c-1}`},[(_(!0),C(z,null,L(M.value,u=>{var I,O,j;return _(),C(z,{key:`slot_${c-1}_${u-1}`},[X(c-1,u-1)?(_(),C("td",{key:0,rowspan:((I=v(c-1,u-1))==null?void 0:I.rowspan)||1,colspan:((O=v(c-1,u-1))==null?void 0:O.colspan)||1,class:fe(Y(c-1,u-1)),onMousedown:N(h=>q(c-1,u-1),["prevent"]),onMousemove:N(h=>P(c-1,u-1),["prevent"]),onMouseup:N(W,["prevent"]),onContextmenu:N(h=>ne(h,c-1,u-1),["prevent"])},[f(d,{size:"small",value:((j=v(c-1,u-1))==null?void 0:j.title)||"","onUpdate:value":h=>Z(c-1,u-1,h)},null,8,["value","onUpdate:value"])],42,ye)):K("",!0)],64)}),128))]))),128))])])]),T.value.visible?(_(),C("div",{key:0,class:"context-menu",style:pe({left:`${T.value.x}px`,top:`${T.value.y}px`})},[w("div",{class:"menu-item",onClick:oe},"合并"),w("div",{class:"menu-item",onClick:le},"拆分")],4)):K("",!0)])}}}),Be=we($e,[["__scopeId","data-v-d18c037e"]]);export{Be as default};
|