feat: support copyable for SimpleTable component

Support copyable attribute for SimpleTable component

Change-Id: Ia780bca1476c98d699059ee60755c0636997067d
This commit is contained in:
zhangjingwei 2024-01-31 10:27:36 +08:00
parent 8a1d7ab034
commit 7c97ddb3ce

View File

@ -16,7 +16,7 @@ import React from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { get, isString, isEmpty, isEqual, has } from 'lodash'; import { get, isString, isEmpty, isEqual, has } from 'lodash';
import { Table } from 'antd'; import { Table, Typography } from 'antd';
import { import {
getColumnSorter, getColumnSorter,
getSortOrder, getSortOrder,
@ -33,6 +33,8 @@ import {
import { getNoValue } from 'utils/index'; import { getNoValue } from 'utils/index';
import styles from './index.less'; import styles from './index.less';
const { Paragraph } = Typography;
export default class SimpleTable extends React.Component { export default class SimpleTable extends React.Component {
static propTypes = { static propTypes = {
data: PropTypes.array.isRequired, data: PropTypes.array.isRequired,
@ -89,6 +91,7 @@ export default class SimpleTable extends React.Component {
linkPrefix, linkPrefix,
valueMap, valueMap,
unit, unit,
copyable,
...rest ...rest
} = column; } = column;
if (column.key === 'operation') { if (column.key === 'operation') {
@ -123,6 +126,14 @@ export default class SimpleTable extends React.Component {
if (dataIndex === 'cost' || isPrice) { if (dataIndex === 'cost' || isPrice) {
newRender = this.getPriceRender(newRender, column); newRender = this.getPriceRender(newRender, column);
} }
if (copyable) {
newRender = (value) => {
if (value && value !== '-') {
return <Paragraph copyable>{value}</Paragraph>;
}
return '-';
};
}
const newColumn = { const newColumn = {
...rest, ...rest,
dataIndex, dataIndex,