@zjlab-fe/data-hub-ui 0.32.4 → 0.32.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  type ArrayKeys<T extends readonly string[]> = T[number];
2
2
  interface IDataTable {
3
3
  head: string[];
4
- /** 单元格内容最多显示多少行,默认固定显示2行,超出显示省略号 */
4
+ /** 单元格内容最多显示多少行,默认固定显示3行,超出显示省略号 */
5
5
  maxLines?: number;
6
6
  data: {
7
7
  [k in ArrayKeys<IDataTable['head']>]: string;
@@ -5,6 +5,7 @@ import { InfoCircleOutlined } from '@ant-design/icons';
5
5
  import i18next from 'i18next';
6
6
  import { cell, textContent, pagination, table, downloadTip } from './index.module.scss.js';
7
7
 
8
+ const DEFAULT_MAX_LINES = 3;
8
9
  function getScrollHeight(containerHeight) {
9
10
  if (containerHeight) {
10
11
  // 减去表格头部高度、分页器高度、横向滚动条高度
@@ -14,7 +15,7 @@ function getScrollHeight(containerHeight) {
14
15
  return 55 * 10;
15
16
  }
16
17
  }
17
- function getPageSize(containerHeight, maxLines = 2) {
18
+ function getPageSize(containerHeight, maxLines = DEFAULT_MAX_LINES) {
18
19
  if (containerHeight) {
19
20
  const scrollHeight = getScrollHeight(containerHeight);
20
21
  // console.log('+++ scrollHeight', scrollHeight);
@@ -46,7 +47,7 @@ function getTextWidth(text, style = {}) {
46
47
  return width;
47
48
  }
48
49
  function DataTable(props) {
49
- const { maxLines = 5, containerWidth = window.innerWidth - 24 } = props;
50
+ const { maxLines = DEFAULT_MAX_LINES, containerWidth = window.innerWidth - 24 } = props;
50
51
  const headerTextWidth = useRef([]);
51
52
  const locale = i18next.resolvedLanguage || localStorage.getItem('i18nextLng') || 'zh';
52
53
  if (headerTextWidth.current.length === 0) {
@@ -60,10 +61,10 @@ function DataTable(props) {
60
61
  dataIndex: item,
61
62
  key: index,
62
63
  render: (text) => {
63
- const str = typeof text === 'object' ? JSON.stringify(text) : text;
64
+ const str = typeof text === 'object' && text !== null && text !== undefined ? JSON.stringify(text) : text;
64
65
  return (jsx("div", { className: cell, style: {
65
66
  height: 22 * maxLines,
66
- maxWidth: containerWidth,
67
+ maxWidth: props.head.length > 3 ? containerWidth / 3 : containerWidth / props.head.length,
67
68
  minWidth: headerTextWidth.current[index],
68
69
  }, children: jsx("div", { className: textContent, style: {
69
70
  WebkitLineClamp: maxLines,
@@ -11,7 +11,12 @@ function transformData(data) {
11
11
  const result = {};
12
12
  Object.keys(data).forEach((key) => {
13
13
  const value = data[key];
14
- result[key] = typeof value === 'bigint' ? value.toString() : String(value);
14
+ if (value === null || value === undefined) {
15
+ result[key] = '';
16
+ }
17
+ else {
18
+ result[key] = typeof value === 'bigint' ? value.toString() : String(value);
19
+ }
15
20
  });
16
21
  return result;
17
22
  }