bhd-components 0.1.2 → 0.1.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.
package/es2017/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  export { default as Provider } from "./provider";
2
2
  export { default as Table } from "./table";
3
+ export { default as TextTootip } from "./textTootip";
4
+ export { default as zh_CN } from "antd/locale/en_US";
5
+ export { default as en_US } from "antd/locale/zh_CN";
package/es2017/index.js CHANGED
@@ -1,2 +1,5 @@
1
1
  export { default as Provider } from "./provider/index";
2
2
  export { default as Table } from "./table/index";
3
+ export { default as TextTootip } from "./textTootip/index";
4
+ export { default as zh_CN } from "antd/locale/en_US";
5
+ export { default as en_US } from "antd/locale/zh_CN";
@@ -3,10 +3,41 @@ const config = {
3
3
  theme: {
4
4
  token: {
5
5
  colorPrimary: "#f4523b",
6
- colorSuccess: "#f4523b",
7
- borderRadius: 8,
8
- borderRadiusSM: 6,
9
- wireframe: true
6
+ colorError: "#f8700c",
7
+ colorSuccess: "#23d9c3",
8
+ colorWarning: "#f9d579",
9
+ colorInfo: "#5991ef",
10
+ wireframe: true,
11
+ borderRadius: 4,
12
+ borderRadiusLG: 8,
13
+ fontSizeHeading1: 36,
14
+ fontSizeHeading2: 24,
15
+ fontSizeHeading3: 20,
16
+ fontSizeHeading4: 18,
17
+ lineHeight: 1.5,
18
+ lineHeightSM: 1.5,
19
+ colorInfoActive: "#3D7DE8",
20
+ colorInfoHover: "#7EAEFF",
21
+ colorInfoBorderHover: "#7EAEFF",
22
+ colorPrimaryBorderHover: "#FC6955",
23
+ colorPrimaryBorder: "#FC6955",
24
+ colorPrimaryActive: "#D54632",
25
+ colorText: "rgba(0, 0, 0, 0.85)",
26
+ colorTextQuaternary: "rgba(0, 0, 0, 0.25)",
27
+ colorBorder: "rgba(0, 0, 0, 0.15)",
28
+ colorBorderSecondary: "rgba(0, 0, 0, 0.05)"
29
+ },
30
+ components: {
31
+ Button: {
32
+ borderRadiusLG: 8,
33
+ colorBgContainer: "#ffffff",
34
+ colorLinkHover: "#7EAEFF",
35
+ colorLinkActive: "#3D7DE8",
36
+ colorPrimaryBorder: "#FC6955"
37
+ },
38
+ Slider: {
39
+ colorPrimaryBorder: "#FC6955"
40
+ }
10
41
  }
11
42
  }
12
43
  };
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
- declare const Provider: (Component: any) => (props: any) => JSX.Element;
2
+ declare const Provider: (Component: any, customConfig?: {}) => ({ ...props }: any) => JSX.Element;
3
3
  export default Provider;
@@ -1,12 +1,17 @@
1
+ import _extends from "@swc/helpers/src/_extends.mjs";
2
+ import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs";
1
3
  import _object_spread from "@swc/helpers/src/_object_spread.mjs";
2
4
  import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
3
5
  import { jsx as _jsx } from "@ice/jsx-runtime/jsx-runtime";
4
6
  import * as React from "react";
5
7
  import { ConfigProvider } from "antd";
6
8
  import config from "./config";
7
- const Provider = (Component)=>{
8
- return (props)=>{
9
- return /*#__PURE__*/ _jsx(ConfigProvider, _object_spread_props(_object_spread({}, config), {
9
+ const Provider = (Component, customConfig = {})=>{
10
+ let AppConfig = Object.assign(config, customConfig);
11
+ ConfigProvider.config(AppConfig);
12
+ return (_param)=>{
13
+ var props = _extends({}, _object_destructuring_empty(_param));
14
+ return /*#__PURE__*/ _jsx(ConfigProvider, _object_spread_props(_object_spread({}, AppConfig), {
10
15
  children: /*#__PURE__*/ _jsx(Component, _object_spread({}, props))
11
16
  }));
12
17
  };
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
- declare const _default: (props: any) => JSX.Element;
2
+ declare const _default: ({ ...props }: any) => JSX.Element;
3
3
  export default _default;
@@ -1,13 +1,143 @@
1
1
  import _object_spread from "@swc/helpers/src/_object_spread.mjs";
2
+ import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
2
3
  import { jsx as _jsx } from "@ice/jsx-runtime/jsx-runtime";
3
4
  import * as React from "react";
5
+ import { useState, useEffect, useRef } from "react";
4
6
  import styles from "./index.module.less";
5
7
  import Provider from "../provider";
6
8
  import { Table as AntdTable } from "antd";
9
+ import TextTootip from "../textTootip";
10
+ const widthPercentage = /^\d+%$/;
11
+ const widthPx = /^\d+px$/;
12
+ const defaultWidthRang = [
13
+ 180,
14
+ 240,
15
+ 320
16
+ ]; //默认自适应的值 [最小值,最佳值,最大值]
7
17
  const Table = (props)=>{
18
+ const ref = useRef(null);
19
+ const [columns, setColumns] = useState(props.columns || []);
20
+ const [scrollObject, setScrollObject] = useState(props.scroll || undefined);
21
+ let { columnTootipClassName , columnTootipColor } = props;
22
+ const initColumns = ()=>{
23
+ let { columns: selfColumns , scrollWidth } = initColumnsWidth(columns, ref.current.offsetWidth);
24
+ setColumns(selfColumns);
25
+ let obj = scrollObject ? scrollObject : {};
26
+ obj = _object_spread_props(_object_spread({}, obj), {
27
+ // x: scrollWidth,
28
+ x: ref.current.offsetWidth
29
+ });
30
+ setScrollObject(obj);
31
+ };
32
+ const initColumnsWidth = (columns, tableWidth)=>{
33
+ let autoNum = 0; //自适应的列数
34
+ let minWidth = 0; //最小宽度
35
+ let scrollWidth = 0; //出现滚动条时 滚动宽度
36
+ columns = columns.map((item)=>{
37
+ item.width = item.width || "auto";
38
+ // item.width=parseFloat(item.width)
39
+ if (widthPercentage.test(item.width)) //检测到宽度为百分比 则转换为具体px 如大于100% 则视为自适应
40
+ item.width = parseFloat(item.width) >= 100 ? "auto" : tableWidth * item.width;
41
+ else if (typeof item.width === "number") //检测为number 则为具体的像素值
42
+ item.width = item.width;
43
+ else if (widthPx.test(item.width)) //检测为 "12px" 则为具体的值
44
+ item.width = parseFloat(item.width);
45
+ else //其它为auto
46
+ item.width = "auto";
47
+ if (item.width === "auto") {
48
+ autoNum += 1;
49
+ if (!item.widthRang) //没有设置自适应区间的 走默认区间
50
+ item.widthRang = defaultWidthRang;
51
+ minWidth += item.widthRang[0];
52
+ scrollWidth += item.widthRang[1];
53
+ } else {
54
+ minWidth += item.width;
55
+ scrollWidth += item.width;
56
+ }
57
+ if (!item.onColumnCell) item.onColumnCell = item.onCell || (()=>({}));
58
+ if (!item.render) {
59
+ item.ellipsis = {
60
+ showTitle: false
61
+ };
62
+ item.render = (text)=>{
63
+ return /*#__PURE__*/ _jsx(TextTootip, {
64
+ width: item.width,
65
+ title: text,
66
+ trigger: "hover",
67
+ overlayClassName: columnTootipClassName || styles.columnTootipClassName,
68
+ color: columnTootipColor || "#FFF",
69
+ children: /*#__PURE__*/ _jsx("span", {
70
+ children: text
71
+ })
72
+ });
73
+ };
74
+ }
75
+ return item;
76
+ });
77
+ let diff = tableWidth - minWidth;
78
+ if (diff > 0) {
79
+ let avgWidth = 0;
80
+ // 有多余空间 平均分配至每个自适应的列
81
+ columns = columns.map((item)=>{
82
+ if (item.width === "auto") {
83
+ //自适应列均分 多出来的宽度(除最后一列)
84
+ item.width = item.widthRang[0] + diff / autoNum;
85
+ if (item.width > item.widthRang[2]) {
86
+ //超过最大宽度 则取最大宽度 多出来的值均分至每一列
87
+ avgWidth += item.width - item.widthRang[2];
88
+ item.width = item.widthRang[2];
89
+ }
90
+ }
91
+ });
92
+ columns = columns.map((item, index)=>{
93
+ //存在适应自适应列侯 多余宽度 则平均分配每一列(除最后一列)
94
+ if (avgWidth > 0 && index !== columns.length - 1) item.width += avgWidth / columns.length - 1;
95
+ });
96
+ } else if (diff < 0) //宽度不足 自适应列取最佳宽度 并出现滚动条 且第一列 最后一列 固定
97
+ columns = columns.map((item, index)=>{
98
+ if (index === 0 || index === columns.length - 1) item.fixed = index === 0 ? "left" : "right";
99
+ if (item.width === "auto") item.width = item.widthRang[1];
100
+ return item;
101
+ });
102
+ else // 相等 自适应列取最小宽度
103
+ columns = columns.map((item)=>{
104
+ if (item.width === "auto") item.width = item.widthRang[0];
105
+ return item;
106
+ });
107
+ columns.map((item)=>{
108
+ item.onCell = (record, rowIndex)=>{
109
+ let obj = typeof item.onColumnCell === "function" ? item.onColumnCell(record, rowIndex) : {};
110
+ obj.style = obj.style ? obj.style : {};
111
+ return _object_spread_props(_object_spread({}, obj), {
112
+ style: _object_spread({
113
+ maxWidth: item.width + "px"
114
+ }, obj.style)
115
+ });
116
+ };
117
+ return item;
118
+ });
119
+ return {
120
+ columns,
121
+ scrollWidth
122
+ };
123
+ };
124
+ useEffect(()=>{
125
+ initColumns();
126
+ window.addEventListener("resize", initColumns);
127
+ return ()=>{
128
+ window.removeEventListener("resize", initColumns);
129
+ };
130
+ }, []);
131
+ let config = _object_spread_props(_object_spread({
132
+ bordered: false
133
+ }, props), {
134
+ columns,
135
+ scroll: scrollObject
136
+ });
8
137
  return /*#__PURE__*/ _jsx("div", {
9
138
  className: styles.Table,
10
- children: /*#__PURE__*/ _jsx(AntdTable, _object_spread({}, props))
139
+ ref: ref,
140
+ children: /*#__PURE__*/ _jsx(AntdTable, _object_spread({}, config))
11
141
  });
12
142
  };
13
143
  export default Provider(Table);
@@ -1,3 +1,64 @@
1
- .Table{
2
-
3
- }
1
+ .Table {
2
+ width: 100%;
3
+ :global {
4
+ table {
5
+ th,
6
+ td {
7
+ border: none;
8
+ border-bottom: 1px solid #e8e8e8;
9
+ }
10
+ thead {
11
+ tr {
12
+ th {
13
+ &:nth-child(1){
14
+ padding-left: 40px;
15
+ }
16
+ &:last-child{
17
+ padding-right: 40px;
18
+ }
19
+ background: #fafafa;
20
+ &::before {
21
+ display: none;
22
+ }
23
+ }
24
+ }
25
+ }
26
+ tbody {
27
+ tr {
28
+ background: transparent;
29
+ &:hover {
30
+ td {
31
+
32
+ // background-color: rgba(244, 82, 59, 0.1) !important;
33
+ background-color: #FFEEEB !important;
34
+ }
35
+ }
36
+ td {
37
+ word-wrap: break-word;
38
+ word-break: break-all;
39
+ overflow: hidden;
40
+ white-space: nowrap;
41
+ text-overflow: ellipsis;
42
+ &:nth-child(1){
43
+ padding-left: 40px;
44
+ }
45
+ &:last-child{
46
+ padding-right: 40px;
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+
55
+ .columnTootipClassName{
56
+ :global{
57
+ .bhd-tooltip-content{
58
+ .bhd-tooltip-inner{
59
+ color: rgba(0,0,0,0.85);
60
+ word-break: break-all;
61
+ }
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import type { TooltipProps } from 'antd/es/tooltip';
3
+ type TextTootipProps = TooltipProps & {
4
+ children: any;
5
+ width?: number;
6
+ title: any;
7
+ };
8
+ declare const TextTootip: (props: TextTootipProps) => JSX.Element;
9
+ export default TextTootip;
@@ -0,0 +1,40 @@
1
+ import _object_spread from "@swc/helpers/src/_object_spread.mjs";
2
+ import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
3
+ import { jsx as _jsx } from "@ice/jsx-runtime/jsx-runtime";
4
+ import * as React from "react";
5
+ import { useState } from "react";
6
+ import { Tooltip } from "antd";
7
+ const getTextSize = (str, fontSize = 14)=>{
8
+ let result = 0;
9
+ let ele = document.createElement("div");
10
+ ele.style.position = "absolute";
11
+ ele.style.whiteSpace = "nowrap";
12
+ ele.style.fontSize = fontSize + "px";
13
+ ele.style.opacity = "0";
14
+ ele.innerText = str;
15
+ document.body.append(ele);
16
+ result = ele.getBoundingClientRect().width;
17
+ document.body.removeChild(ele);
18
+ return result;
19
+ };
20
+ const TextTootip = (props)=>{
21
+ let { children , width , title } = props;
22
+ const [open, setOpen] = useState(false);
23
+ const mouseEnter = ()=>{
24
+ if (!width) setOpen(true);
25
+ else //存在width
26
+ setOpen(getTextSize(title) < width ? false : true);
27
+ };
28
+ const mouseLeave = ()=>{
29
+ setOpen(false);
30
+ };
31
+ return /*#__PURE__*/ _jsx(Tooltip, _object_spread_props(_object_spread({}, props), {
32
+ open: open,
33
+ children: /*#__PURE__*/ _jsx("span", {
34
+ onMouseEnter: mouseEnter,
35
+ onMouseLeave: mouseLeave,
36
+ children: children
37
+ })
38
+ }));
39
+ };
40
+ export default TextTootip;
File without changes
@@ -0,0 +1,2 @@
1
+ declare const cloneDeep: (obj: any) => any;
2
+ export { cloneDeep };
@@ -0,0 +1,26 @@
1
+ const cloneDeep = (obj)=>{
2
+ // 处理null
3
+ if (obj === null) return null;
4
+ // 处理原始值
5
+ if (typeof obj != "object" && typeof obj != "function") return obj;
6
+ // 处理函数
7
+ if (typeof obj === "function") {
8
+ let func = obj + "";
9
+ // 返回匿名函数
10
+ // new Function('...')() 直接执行引号中的内容,与eval
11
+ return new Function("return " + func)();
12
+ }
13
+ // 处理正则
14
+ if (obj instanceof RegExp) return new RegExp(obj);
15
+ // 处理Set对象
16
+ if (obj instanceof Set) return new Set(obj);
17
+ // 处理Map对象
18
+ if (obj instanceof Map) return new Map(obj);
19
+ // 处理日期
20
+ if (obj instanceof Date) return new Date(obj);
21
+ // 用被克隆对象的构造函数创建一个实例,这样克隆出来的对象也是那个构造函数的实例,保持相同的所属类
22
+ let newObj = new obj.constructor();
23
+ for(let key in obj)if (obj.hasOwnProperty(key)) newObj[key] = cloneDeep(obj[key]);
24
+ return newObj;
25
+ };
26
+ export { cloneDeep };
package/esm/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  export { default as Provider } from "./provider";
2
2
  export { default as Table } from "./table";
3
+ export { default as TextTootip } from "./textTootip";
4
+ export { default as zh_CN } from "antd/locale/en_US";
5
+ export { default as en_US } from "antd/locale/zh_CN";
package/esm/index.js CHANGED
@@ -1,2 +1,5 @@
1
1
  export { default as Provider } from "./provider/index";
2
2
  export { default as Table } from "./table/index";
3
+ export { default as TextTootip } from "./textTootip/index";
4
+ export { default as zh_CN } from "antd/locale/en_US";
5
+ export { default as en_US } from "antd/locale/zh_CN";
@@ -3,10 +3,41 @@ var config = {
3
3
  theme: {
4
4
  token: {
5
5
  colorPrimary: "#f4523b",
6
- colorSuccess: "#f4523b",
7
- borderRadius: 8,
8
- borderRadiusSM: 6,
9
- wireframe: true
6
+ colorError: "#f8700c",
7
+ colorSuccess: "#23d9c3",
8
+ colorWarning: "#f9d579",
9
+ colorInfo: "#5991ef",
10
+ wireframe: true,
11
+ borderRadius: 4,
12
+ borderRadiusLG: 8,
13
+ fontSizeHeading1: 36,
14
+ fontSizeHeading2: 24,
15
+ fontSizeHeading3: 20,
16
+ fontSizeHeading4: 18,
17
+ lineHeight: 1.5,
18
+ lineHeightSM: 1.5,
19
+ colorInfoActive: "#3D7DE8",
20
+ colorInfoHover: "#7EAEFF",
21
+ colorInfoBorderHover: "#7EAEFF",
22
+ colorPrimaryBorderHover: "#FC6955",
23
+ colorPrimaryBorder: "#FC6955",
24
+ colorPrimaryActive: "#D54632",
25
+ colorText: "rgba(0, 0, 0, 0.85)",
26
+ colorTextQuaternary: "rgba(0, 0, 0, 0.25)",
27
+ colorBorder: "rgba(0, 0, 0, 0.15)",
28
+ colorBorderSecondary: "rgba(0, 0, 0, 0.05)"
29
+ },
30
+ components: {
31
+ Button: {
32
+ borderRadiusLG: 8,
33
+ colorBgContainer: "#ffffff",
34
+ colorLinkHover: "#7EAEFF",
35
+ colorLinkActive: "#3D7DE8",
36
+ colorPrimaryBorder: "#FC6955"
37
+ },
38
+ Slider: {
39
+ colorPrimaryBorder: "#FC6955"
40
+ }
10
41
  }
11
42
  }
12
43
  };
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
- declare const Provider: (Component: any) => (props: any) => JSX.Element;
2
+ declare const Provider: (Component: any, customConfig?: {}) => ({ ...props }: any) => JSX.Element;
3
3
  export default Provider;
@@ -1,3 +1,5 @@
1
+ import _extends from "@swc/helpers/src/_extends.mjs";
2
+ import _object_destructuring_empty from "@swc/helpers/src/_object_destructuring_empty.mjs";
1
3
  import _object_spread from "@swc/helpers/src/_object_spread.mjs";
2
4
  import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
3
5
  import { jsx as _jsx } from "@ice/jsx-runtime/jsx-runtime";
@@ -5,8 +7,12 @@ import * as React from "react";
5
7
  import { ConfigProvider } from "antd";
6
8
  import config from "./config";
7
9
  var Provider = function(Component) {
8
- return function(props) {
9
- return /*#__PURE__*/ _jsx(ConfigProvider, _object_spread_props(_object_spread({}, config), {
10
+ var customConfig = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
11
+ var AppConfig = Object.assign(config, customConfig);
12
+ ConfigProvider.config(AppConfig);
13
+ return function(_param) {
14
+ var props = _extends({}, _object_destructuring_empty(_param));
15
+ return /*#__PURE__*/ _jsx(ConfigProvider, _object_spread_props(_object_spread({}, AppConfig), {
10
16
  children: /*#__PURE__*/ _jsx(Component, _object_spread({}, props))
11
17
  }));
12
18
  };
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
- declare const _default: (props: any) => JSX.Element;
2
+ declare const _default: ({ ...props }: any) => JSX.Element;
3
3
  export default _default;
@@ -1,13 +1,146 @@
1
1
  import _object_spread from "@swc/helpers/src/_object_spread.mjs";
2
+ import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
3
+ import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs";
2
4
  import { jsx as _jsx } from "@ice/jsx-runtime/jsx-runtime";
3
5
  import * as React from "react";
6
+ import { useState, useEffect, useRef } from "react";
4
7
  import styles from "./index.module.less";
5
8
  import Provider from "../provider";
6
9
  import { Table as AntdTable } from "antd";
10
+ import TextTootip from "../textTootip";
11
+ var widthPercentage = /^\d+%$/;
12
+ var widthPx = /^\d+px$/;
13
+ var defaultWidthRang = [
14
+ 180,
15
+ 240,
16
+ 320
17
+ ]; //默认自适应的值 [最小值,最佳值,最大值]
7
18
  var Table = function(props) {
19
+ var ref = useRef(null);
20
+ var _useState = _sliced_to_array(useState(props.columns || []), 2), columns = _useState[0], setColumns = _useState[1];
21
+ var _useState1 = _sliced_to_array(useState(props.scroll || undefined), 2), scrollObject = _useState1[0], setScrollObject = _useState1[1];
22
+ var columnTootipClassName = props.columnTootipClassName, columnTootipColor = props.columnTootipColor;
23
+ var initColumns = function() {
24
+ var _initColumnsWidth = initColumnsWidth(columns, ref.current.offsetWidth), selfColumns = _initColumnsWidth.columns, scrollWidth = _initColumnsWidth.scrollWidth;
25
+ setColumns(selfColumns);
26
+ var obj = scrollObject ? scrollObject : {};
27
+ obj = _object_spread_props(_object_spread({}, obj), {
28
+ // x: scrollWidth,
29
+ x: ref.current.offsetWidth
30
+ });
31
+ setScrollObject(obj);
32
+ };
33
+ var initColumnsWidth = function(columns, tableWidth) {
34
+ var autoNum = 0; //自适应的列数
35
+ var minWidth = 0; //最小宽度
36
+ var scrollWidth = 0; //出现滚动条时 滚动宽度
37
+ columns = columns.map(function(item) {
38
+ item.width = item.width || "auto";
39
+ // item.width=parseFloat(item.width)
40
+ if (widthPercentage.test(item.width)) //检测到宽度为百分比 则转换为具体px 如大于100% 则视为自适应
41
+ item.width = parseFloat(item.width) >= 100 ? "auto" : tableWidth * item.width;
42
+ else if (typeof item.width === "number") //检测为number 则为具体的像素值
43
+ item.width = item.width;
44
+ else if (widthPx.test(item.width)) //检测为 "12px" 则为具体的值
45
+ item.width = parseFloat(item.width);
46
+ else //其它为auto
47
+ item.width = "auto";
48
+ if (item.width === "auto") {
49
+ autoNum += 1;
50
+ if (!item.widthRang) //没有设置自适应区间的 走默认区间
51
+ item.widthRang = defaultWidthRang;
52
+ minWidth += item.widthRang[0];
53
+ scrollWidth += item.widthRang[1];
54
+ } else {
55
+ minWidth += item.width;
56
+ scrollWidth += item.width;
57
+ }
58
+ if (!item.onColumnCell) item.onColumnCell = item.onCell || function() {
59
+ return {};
60
+ };
61
+ if (!item.render) {
62
+ item.ellipsis = {
63
+ showTitle: false
64
+ };
65
+ item.render = function(text) {
66
+ return /*#__PURE__*/ _jsx(TextTootip, {
67
+ width: item.width,
68
+ title: text,
69
+ trigger: "hover",
70
+ overlayClassName: columnTootipClassName || styles.columnTootipClassName,
71
+ color: columnTootipColor || "#FFF",
72
+ children: /*#__PURE__*/ _jsx("span", {
73
+ children: text
74
+ })
75
+ });
76
+ };
77
+ }
78
+ return item;
79
+ });
80
+ var diff = tableWidth - minWidth;
81
+ if (diff > 0) {
82
+ var avgWidth = 0;
83
+ // 有多余空间 平均分配至每个自适应的列
84
+ columns = columns.map(function(item) {
85
+ if (item.width === "auto") {
86
+ //自适应列均分 多出来的宽度(除最后一列)
87
+ item.width = item.widthRang[0] + diff / autoNum;
88
+ if (item.width > item.widthRang[2]) {
89
+ //超过最大宽度 则取最大宽度 多出来的值均分至每一列
90
+ avgWidth += item.width - item.widthRang[2];
91
+ item.width = item.widthRang[2];
92
+ }
93
+ }
94
+ });
95
+ columns = columns.map(function(item, index) {
96
+ //存在适应自适应列侯 多余宽度 则平均分配每一列(除最后一列)
97
+ if (avgWidth > 0 && index !== columns.length - 1) item.width += avgWidth / columns.length - 1;
98
+ });
99
+ } else if (diff < 0) //宽度不足 自适应列取最佳宽度 并出现滚动条 且第一列 最后一列 固定
100
+ columns = columns.map(function(item, index) {
101
+ if (index === 0 || index === columns.length - 1) item.fixed = index === 0 ? "left" : "right";
102
+ if (item.width === "auto") item.width = item.widthRang[1];
103
+ return item;
104
+ });
105
+ else // 相等 自适应列取最小宽度
106
+ columns = columns.map(function(item) {
107
+ if (item.width === "auto") item.width = item.widthRang[0];
108
+ return item;
109
+ });
110
+ columns.map(function(item) {
111
+ item.onCell = function(record, rowIndex) {
112
+ var obj = typeof item.onColumnCell === "function" ? item.onColumnCell(record, rowIndex) : {};
113
+ obj.style = obj.style ? obj.style : {};
114
+ return _object_spread_props(_object_spread({}, obj), {
115
+ style: _object_spread({
116
+ maxWidth: item.width + "px"
117
+ }, obj.style)
118
+ });
119
+ };
120
+ return item;
121
+ });
122
+ return {
123
+ columns: columns,
124
+ scrollWidth: scrollWidth
125
+ };
126
+ };
127
+ useEffect(function() {
128
+ initColumns();
129
+ window.addEventListener("resize", initColumns);
130
+ return function() {
131
+ window.removeEventListener("resize", initColumns);
132
+ };
133
+ }, []);
134
+ var config = _object_spread_props(_object_spread({
135
+ bordered: false
136
+ }, props), {
137
+ columns: columns,
138
+ scroll: scrollObject
139
+ });
8
140
  return /*#__PURE__*/ _jsx("div", {
9
141
  className: styles.Table,
10
- children: /*#__PURE__*/ _jsx(AntdTable, _object_spread({}, props))
142
+ ref: ref,
143
+ children: /*#__PURE__*/ _jsx(AntdTable, _object_spread({}, config))
11
144
  });
12
145
  };
13
146
  export default Provider(Table);