From 0960448f5406eac8deb041c9b857e5182dc69a4b Mon Sep 17 00:00:00 2001 From: pengm <674192343@qq.com> Date: Fri, 29 May 2026 14:22:32 +0800 Subject: [PATCH] 1.列表支持点击字段时,键盘ctrl+C支持复制单元格内容 --- src/components/Common/CommonComponent/index.js | 12 ++++++------ src/components/Common/CommonTable/index.js | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/components/Common/CommonComponent/index.js b/src/components/Common/CommonComponent/index.js index 82b6432..6d3a23c 100644 --- a/src/components/Common/CommonComponent/index.js +++ b/src/components/Common/CommonComponent/index.js @@ -785,14 +785,14 @@ export default class CommonComponent extends Component { const { scrollTop } = oTBody; const oTr = this.selectTableRef1.querySelector(".selected-record-row"); - const trRect = oTr.getBoundingClientRect(); - const tbodyRect = oTBody.getBoundingClientRect(); + const trRect = oTr?.getBoundingClientRect(); + const tbodyRect = oTBody?.getBoundingClientRect(); - const tbodyTop = tbodyRect.top + window.scrollY; - const tbodyBottom = tbodyRect.bottom + window.scrollY; + const tbodyTop = tbodyRect?.top + window.scrollY; + const tbodyBottom = tbodyRect?.bottom + window.scrollY; - const trTop = trRect.top + window.scrollY; - const trBottom = trRect.bottom + window.scrollY; + const trTop = trRect?.top + window.scrollY; + const trBottom = trRect?.bottom + window.scrollY; if (keyCode === 40) { const selectTableIndexNew = Math.min(selectTableIndex + 1, selectTableData.length - 1); if (selectTableIndex !== selectTableIndexNew) { diff --git a/src/components/Common/CommonTable/index.js b/src/components/Common/CommonTable/index.js index 44cdfe7..e6077d0 100644 --- a/src/components/Common/CommonTable/index.js +++ b/src/components/Common/CommonTable/index.js @@ -1013,7 +1013,7 @@ class CommonTableRc extends React.Component { if (e.key === 'F10') { message.info(sName); } else if (e.ctrlKey && e.keyCode === 67) { - console.log('复制成功!'); + // console.log('复制成功!'); } else if (e.ctrlKey && e.keyCode === 65) { console.log('全选成功!'); } else if (e.ctrlKey && (e.altKey || e.metaKey) && e.keyCode === 71) { /* CTRL+ALT+G F7 设置界面 */ @@ -5780,12 +5780,23 @@ class CommonTableRc extends React.Component { > this.onKeyDownDiv(e, sName)} onCut={e => e.preventDefault()} onPaste={e => e.preventDefault()} - // suppressContentEditableWarning - // contentEditable="true" + // onInput={e => e.preventDefault()} + suppressContentEditableWarning + contentEditable="true" + tabIndex="0" + onCopy={(e) => { + // 先拿到当前选中的文本(如果没选中,就拿整个span的内容) + let text = window.getSelection().toString() || sValue; + text = text.trimEnd(); // 自动去末尾空格 + e.clipboardData.setData('text/plain', text); + e.preventDefault(); + message.success('复制成功'); + console.log('复制的内容:', text); // 方便调试 + }} onClick={commonUtils.isNotEmptyObject(linkStyle) ? this.handleViewClick.bind(this, isSlaveInfo ? 'slaveInfo' : this.props.name, showConfig.sName, record, index, showConfig) : null} > {isAmount ? this.formatThousands(sValue) : sValue} -- libgit2 0.22.2