Commit 0960448f5406eac8deb041c9b857e5182dc69a4b

Authored by Min
1 parent 24c52a3e

1.列表支持点击字段时,键盘ctrl+C支持复制单元格内容

src/components/Common/CommonComponent/index.js
... ... @@ -785,14 +785,14 @@ export default class CommonComponent extends Component {
785 785 const { scrollTop } = oTBody;
786 786  
787 787 const oTr = this.selectTableRef1.querySelector(".selected-record-row");
788   - const trRect = oTr.getBoundingClientRect();
789   - const tbodyRect = oTBody.getBoundingClientRect();
  788 + const trRect = oTr?.getBoundingClientRect();
  789 + const tbodyRect = oTBody?.getBoundingClientRect();
790 790  
791   - const tbodyTop = tbodyRect.top + window.scrollY;
792   - const tbodyBottom = tbodyRect.bottom + window.scrollY;
  791 + const tbodyTop = tbodyRect?.top + window.scrollY;
  792 + const tbodyBottom = tbodyRect?.bottom + window.scrollY;
793 793  
794   - const trTop = trRect.top + window.scrollY;
795   - const trBottom = trRect.bottom + window.scrollY;
  794 + const trTop = trRect?.top + window.scrollY;
  795 + const trBottom = trRect?.bottom + window.scrollY;
796 796 if (keyCode === 40) {
797 797 const selectTableIndexNew = Math.min(selectTableIndex + 1, selectTableData.length - 1);
798 798 if (selectTableIndex !== selectTableIndexNew) {
... ...
src/components/Common/CommonTable/index.js
... ... @@ -1013,7 +1013,7 @@ class CommonTableRc extends React.Component {
1013 1013 if (e.key === 'F10') {
1014 1014 message.info(sName);
1015 1015 } else if (e.ctrlKey && e.keyCode === 67) {
1016   - console.log('复制成功!');
  1016 + // console.log('复制成功!');
1017 1017 } else if (e.ctrlKey && e.keyCode === 65) {
1018 1018 console.log('全选成功!');
1019 1019 } else if (e.ctrlKey && (e.altKey || e.metaKey) && e.keyCode === 71) { /* CTRL+ALT+G F7 设置界面 */
... ... @@ -5780,12 +5780,23 @@ class CommonTableRc extends React.Component {
5780 5780 >
5781 5781 <span
5782 5782 className={linkStyle}
5783   - style={{ border: 'none', outline: 'none' }}
  5783 + style={{ border: 'none', outline: 'none', userSelect: 'text' }} // 允许选中复制
5784 5784 onKeyDown={e => this.onKeyDownDiv(e, sName)}
5785 5785 onCut={e => e.preventDefault()}
5786 5786 onPaste={e => e.preventDefault()}
5787   - // suppressContentEditableWarning
5788   - // contentEditable="true"
  5787 + // onInput={e => e.preventDefault()}
  5788 + suppressContentEditableWarning
  5789 + contentEditable="true"
  5790 + tabIndex="0"
  5791 + onCopy={(e) => {
  5792 + // 先拿到当前选中的文本(如果没选中,就拿整个span的内容)
  5793 + let text = window.getSelection().toString() || sValue;
  5794 + text = text.trimEnd(); // 自动去末尾空格
  5795 + e.clipboardData.setData('text/plain', text);
  5796 + e.preventDefault();
  5797 + message.success('复制成功');
  5798 + console.log('复制的内容:', text); // 方便调试
  5799 + }}
5789 5800 onClick={commonUtils.isNotEmptyObject(linkStyle) ? this.handleViewClick.bind(this, isSlaveInfo ? 'slaveInfo' : this.props.name, showConfig.sName, record, index, showConfig) : null}
5790 5801 > {isAmount ? this.formatThousands(sValue) : sValue}</span>
5791 5802 </Tooltip>
... ...