szld-libs 0.2.30 → 0.2.32
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/dist/szld-components.es.js +4017 -3978
- package/dist/szld-components.umd.js +35 -35
- package/es/components/SearchTable/index.d.ts +3 -1
- package/es/components/SearchTable/index.js +68 -16
- package/es/index.js +8 -3
- package/lib/components/SearchTable/index.d.ts +3 -1
- package/lib/components/SearchTable/index.js +67 -15
- package/lib/index.js +6 -1
- package/package.json +1 -1
|
@@ -3,12 +3,14 @@ import { ColumnType } from 'antd/es/table';
|
|
|
3
3
|
import { CreateFormProps } from '../CreateForm';
|
|
4
4
|
export interface TableColumnProps<T> extends ColumnType<T> {
|
|
5
5
|
hidden?: boolean;
|
|
6
|
-
width?: number;
|
|
6
|
+
width?: number | string;
|
|
7
7
|
}
|
|
8
8
|
export interface MTableProps<T> extends Omit<TableProps<T>, 'columns'> {
|
|
9
9
|
columns?: TableColumnProps<T>[];
|
|
10
10
|
minColumnWidth?: number;
|
|
11
11
|
resizeable?: boolean;
|
|
12
|
+
tableId?: string;
|
|
13
|
+
storageKey?: string;
|
|
12
14
|
}
|
|
13
15
|
export interface SearchTableProps<RecordType> {
|
|
14
16
|
searchProps?: CreateFormProps;
|
|
@@ -2,8 +2,9 @@ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { Table } from "antd";
|
|
3
3
|
import classNames from "classnames";
|
|
4
4
|
import _ from "lodash";
|
|
5
|
-
import { useState, useMemo } from "react";
|
|
5
|
+
import { useRef, useState, useEffect, useCallback, useMemo } from "react";
|
|
6
6
|
import { Resizable } from "react-resizable";
|
|
7
|
+
import { getLocalStorage } from "../../utils";
|
|
7
8
|
import CreateForm from "../CreateForm";
|
|
8
9
|
const search = "search-table-module_search_17add";
|
|
9
10
|
const table = "search-table-module_table_5f652";
|
|
@@ -20,30 +21,81 @@ const ResizeableTitle = (props) => {
|
|
|
20
21
|
};
|
|
21
22
|
function SearchTable(props) {
|
|
22
23
|
const { tableProps = {}, searchProps } = props;
|
|
23
|
-
const {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
const {
|
|
25
|
+
minColumnWidth = 200,
|
|
26
|
+
resizeable = true,
|
|
27
|
+
tableId,
|
|
28
|
+
storageKey = "szld_table_cell_width",
|
|
29
|
+
...rest
|
|
30
|
+
} = tableProps;
|
|
31
|
+
const ref = useRef(null);
|
|
32
|
+
const [columns, setColumns] = useState([]);
|
|
33
|
+
const getWidth = (v) => {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
let width = v.width || minColumnWidth;
|
|
36
|
+
if (typeof v.dataIndex === "string" && tableId) {
|
|
37
|
+
const _width = (_b = (_a = getLocalStorage(storageKey)) == null ? void 0 : _a[tableId]) == null ? void 0 : _b[v.dataIndex];
|
|
38
|
+
if (_width) {
|
|
39
|
+
width = _width;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return width;
|
|
33
43
|
};
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
const list = tableProps.columns || [];
|
|
46
|
+
if (list.length === 0) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const result = list.map((v) => ({
|
|
50
|
+
...v,
|
|
51
|
+
width: getWidth(v)
|
|
52
|
+
}));
|
|
53
|
+
setColumns(result);
|
|
54
|
+
ref.current = Date.now();
|
|
55
|
+
}, [tableProps.columns, tableId, minColumnWidth]);
|
|
56
|
+
const handleResize = useCallback(
|
|
57
|
+
(column, size) => {
|
|
58
|
+
const list = _.cloneDeep(columns);
|
|
59
|
+
if (!list || list.length === 0) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const index = list == null ? void 0 : list.findIndex((v) => v.dataIndex === column.dataIndex);
|
|
63
|
+
list[index] = {
|
|
64
|
+
...list[index],
|
|
65
|
+
width: size.width
|
|
66
|
+
};
|
|
67
|
+
if (tableId) {
|
|
68
|
+
const obj = getLocalStorage(storageKey) || {};
|
|
69
|
+
obj[tableId] = obj[tableId] || {};
|
|
70
|
+
list == null ? void 0 : list.forEach((v) => {
|
|
71
|
+
if (typeof v.dataIndex === "string") {
|
|
72
|
+
obj[tableId][v.dataIndex] = v.width;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
localStorage.setItem(storageKey, JSON.stringify(obj));
|
|
76
|
+
}
|
|
77
|
+
setColumns(list);
|
|
78
|
+
},
|
|
79
|
+
[columns, tableId, storageKey]
|
|
80
|
+
);
|
|
34
81
|
const realColumns = useMemo(() => {
|
|
35
|
-
|
|
82
|
+
if (!ref.current || columns === void 0) {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
const result = columns == null ? void 0 : columns.filter((v) => !v.hidden).map((v) => ({
|
|
36
86
|
...v,
|
|
37
|
-
width: v.width
|
|
38
|
-
onHeaderCell: (column
|
|
87
|
+
width: v.width,
|
|
88
|
+
onHeaderCell: (column) => ({
|
|
39
89
|
width: column.width,
|
|
40
90
|
resizeable,
|
|
41
91
|
onResize: (_e, { size }) => handleResize(column, size)
|
|
42
92
|
})
|
|
43
93
|
}));
|
|
44
|
-
result
|
|
94
|
+
if (result.length > 0) {
|
|
95
|
+
result[result.length - 1].width = void 0;
|
|
96
|
+
}
|
|
45
97
|
return result;
|
|
46
|
-
}, [resizeable, columns, minColumnWidth]);
|
|
98
|
+
}, [resizeable, columns, ref.current, minColumnWidth]);
|
|
47
99
|
const components = {
|
|
48
100
|
header: {
|
|
49
101
|
cell: ResizeableTitle
|
package/es/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect } from "react";
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
3
|
import ReactDOM from "react-dom/client";
|
|
4
4
|
import { BrowserRouter } from "react-router-dom";
|
|
5
|
+
import { Button } from "antd";
|
|
5
6
|
import useConfig from "./hooks/useConfig";
|
|
6
7
|
import { AES, SearchTable } from "./main";
|
|
7
8
|
let key = "U2FsdGVkX1/dG1NSXNR9hnp3Ech/v6Gh8CDDJxgBm1EPFQel12ySIf84ARXCPwTae7TzwgPvjOyE3S5rAEzl/wAZmId6pbezpFeFcJqxdmIl3FeluYHFxJzQHDETTvrr3G/REvv00kHptOVwg6ecjPH6yk7PNit0sWTBLorROxLxMD8lVDmOA66p7Zp4QnYzqScYJGFbutmfHYXfBRBe1Q2UKummJ798svNY5SIwEwl4spzgyWmhARtuyq4zhysFrj/xODuNDjtwitA6XfX566WcZkj3F+2P+mkYzDYOhXXaomnlybjrZ2hEHfcczQhUfJd89O8PNIuEWo24wjYRgMdKlw5CWSeocFCqV7ZJ/CV/7vNRcaO4awKlFNobLikkwDznxpcX+4UEej+ED+pgfmPQLsKedcfEscStkSAZXaD5pBRTiFU9xGLfDt6seUrEnMBeXkpMIY9j1SZDDK18/G7lSHjDQMZYZP6sfLdBdwY=";
|
|
@@ -38,7 +39,11 @@ const Demo = () => {
|
|
|
38
39
|
title: "c"
|
|
39
40
|
}
|
|
40
41
|
];
|
|
41
|
-
|
|
42
|
+
const [list, setList] = useState([]);
|
|
43
|
+
return /* @__PURE__ */ jsxs("div", { style: { height: "100vh" }, children: [
|
|
44
|
+
/* @__PURE__ */ jsx(Button, { onClick: () => setList(columns), children: "test" }),
|
|
45
|
+
/* @__PURE__ */ jsx(SearchTable, { tableProps: { columns: list, dataSource: [], resizeable: true, tableId: "demo1" } })
|
|
46
|
+
] });
|
|
42
47
|
};
|
|
43
48
|
ReactDOM.createRoot(document.getElementById("root")).render(
|
|
44
49
|
/* @__PURE__ */ jsx(BrowserRouter, { children: /* @__PURE__ */ jsx(Demo, {}) })
|
|
@@ -3,12 +3,14 @@ import { ColumnType } from 'antd/es/table';
|
|
|
3
3
|
import { CreateFormProps } from '../CreateForm';
|
|
4
4
|
export interface TableColumnProps<T> extends ColumnType<T> {
|
|
5
5
|
hidden?: boolean;
|
|
6
|
-
width?: number;
|
|
6
|
+
width?: number | string;
|
|
7
7
|
}
|
|
8
8
|
export interface MTableProps<T> extends Omit<TableProps<T>, 'columns'> {
|
|
9
9
|
columns?: TableColumnProps<T>[];
|
|
10
10
|
minColumnWidth?: number;
|
|
11
11
|
resizeable?: boolean;
|
|
12
|
+
tableId?: string;
|
|
13
|
+
storageKey?: string;
|
|
12
14
|
}
|
|
13
15
|
export interface SearchTableProps<RecordType> {
|
|
14
16
|
searchProps?: CreateFormProps;
|
|
@@ -5,6 +5,7 @@ const classNames = require("classnames");
|
|
|
5
5
|
const _ = require("lodash");
|
|
6
6
|
const react = require("react");
|
|
7
7
|
const reactResizable = require("react-resizable");
|
|
8
|
+
const utils = require("../../utils");
|
|
8
9
|
const CreateForm = require("../CreateForm");
|
|
9
10
|
const search = "search-table-module_search_17add";
|
|
10
11
|
const table = "search-table-module_table_5f652";
|
|
@@ -21,30 +22,81 @@ const ResizeableTitle = (props) => {
|
|
|
21
22
|
};
|
|
22
23
|
function SearchTable(props) {
|
|
23
24
|
const { tableProps = {}, searchProps } = props;
|
|
24
|
-
const {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
const {
|
|
26
|
+
minColumnWidth = 200,
|
|
27
|
+
resizeable = true,
|
|
28
|
+
tableId,
|
|
29
|
+
storageKey = "szld_table_cell_width",
|
|
30
|
+
...rest
|
|
31
|
+
} = tableProps;
|
|
32
|
+
const ref = react.useRef(null);
|
|
33
|
+
const [columns, setColumns] = react.useState([]);
|
|
34
|
+
const getWidth = (v) => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
let width = v.width || minColumnWidth;
|
|
37
|
+
if (typeof v.dataIndex === "string" && tableId) {
|
|
38
|
+
const _width = (_b = (_a = utils.getLocalStorage(storageKey)) == null ? void 0 : _a[tableId]) == null ? void 0 : _b[v.dataIndex];
|
|
39
|
+
if (_width) {
|
|
40
|
+
width = _width;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return width;
|
|
34
44
|
};
|
|
45
|
+
react.useEffect(() => {
|
|
46
|
+
const list = tableProps.columns || [];
|
|
47
|
+
if (list.length === 0) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const result = list.map((v) => ({
|
|
51
|
+
...v,
|
|
52
|
+
width: getWidth(v)
|
|
53
|
+
}));
|
|
54
|
+
setColumns(result);
|
|
55
|
+
ref.current = Date.now();
|
|
56
|
+
}, [tableProps.columns, tableId, minColumnWidth]);
|
|
57
|
+
const handleResize = react.useCallback(
|
|
58
|
+
(column, size) => {
|
|
59
|
+
const list = _.cloneDeep(columns);
|
|
60
|
+
if (!list || list.length === 0) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const index = list == null ? void 0 : list.findIndex((v) => v.dataIndex === column.dataIndex);
|
|
64
|
+
list[index] = {
|
|
65
|
+
...list[index],
|
|
66
|
+
width: size.width
|
|
67
|
+
};
|
|
68
|
+
if (tableId) {
|
|
69
|
+
const obj = utils.getLocalStorage(storageKey) || {};
|
|
70
|
+
obj[tableId] = obj[tableId] || {};
|
|
71
|
+
list == null ? void 0 : list.forEach((v) => {
|
|
72
|
+
if (typeof v.dataIndex === "string") {
|
|
73
|
+
obj[tableId][v.dataIndex] = v.width;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
localStorage.setItem(storageKey, JSON.stringify(obj));
|
|
77
|
+
}
|
|
78
|
+
setColumns(list);
|
|
79
|
+
},
|
|
80
|
+
[columns, tableId, storageKey]
|
|
81
|
+
);
|
|
35
82
|
const realColumns = react.useMemo(() => {
|
|
36
|
-
|
|
83
|
+
if (!ref.current || columns === void 0) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
const result = columns == null ? void 0 : columns.filter((v) => !v.hidden).map((v) => ({
|
|
37
87
|
...v,
|
|
38
|
-
width: v.width
|
|
39
|
-
onHeaderCell: (column
|
|
88
|
+
width: v.width,
|
|
89
|
+
onHeaderCell: (column) => ({
|
|
40
90
|
width: column.width,
|
|
41
91
|
resizeable,
|
|
42
92
|
onResize: (_e, { size }) => handleResize(column, size)
|
|
43
93
|
})
|
|
44
94
|
}));
|
|
45
|
-
result
|
|
95
|
+
if (result.length > 0) {
|
|
96
|
+
result[result.length - 1].width = void 0;
|
|
97
|
+
}
|
|
46
98
|
return result;
|
|
47
|
-
}, [resizeable, columns, minColumnWidth]);
|
|
99
|
+
}, [resizeable, columns, ref.current, minColumnWidth]);
|
|
48
100
|
const components = {
|
|
49
101
|
header: {
|
|
50
102
|
cell: ResizeableTitle
|
package/lib/index.js
CHANGED
|
@@ -3,6 +3,7 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
3
3
|
const react = require("react");
|
|
4
4
|
const ReactDOM = require("react-dom/client");
|
|
5
5
|
const reactRouterDom = require("react-router-dom");
|
|
6
|
+
const antd = require("antd");
|
|
6
7
|
const useConfig = require("./hooks/useConfig");
|
|
7
8
|
const main = require("./main");
|
|
8
9
|
let key = "U2FsdGVkX1/dG1NSXNR9hnp3Ech/v6Gh8CDDJxgBm1EPFQel12ySIf84ARXCPwTae7TzwgPvjOyE3S5rAEzl/wAZmId6pbezpFeFcJqxdmIl3FeluYHFxJzQHDETTvrr3G/REvv00kHptOVwg6ecjPH6yk7PNit0sWTBLorROxLxMD8lVDmOA66p7Zp4QnYzqScYJGFbutmfHYXfBRBe1Q2UKummJ798svNY5SIwEwl4spzgyWmhARtuyq4zhysFrj/xODuNDjtwitA6XfX566WcZkj3F+2P+mkYzDYOhXXaomnlybjrZ2hEHfcczQhUfJd89O8PNIuEWo24wjYRgMdKlw5CWSeocFCqV7ZJ/CV/7vNRcaO4awKlFNobLikkwDznxpcX+4UEej+ED+pgfmPQLsKedcfEscStkSAZXaD5pBRTiFU9xGLfDt6seUrEnMBeXkpMIY9j1SZDDK18/G7lSHjDQMZYZP6sfLdBdwY=";
|
|
@@ -39,7 +40,11 @@ const Demo = () => {
|
|
|
39
40
|
title: "c"
|
|
40
41
|
}
|
|
41
42
|
];
|
|
42
|
-
|
|
43
|
+
const [list, setList] = react.useState([]);
|
|
44
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { height: "100vh" }, children: [
|
|
45
|
+
/* @__PURE__ */ jsxRuntime.jsx(antd.Button, { onClick: () => setList(columns), children: "test" }),
|
|
46
|
+
/* @__PURE__ */ jsxRuntime.jsx(main.SearchTable, { tableProps: { columns: list, dataSource: [], resizeable: true, tableId: "demo1" } })
|
|
47
|
+
] });
|
|
43
48
|
};
|
|
44
49
|
ReactDOM.createRoot(document.getElementById("root")).render(
|
|
45
50
|
/* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.BrowserRouter, { children: /* @__PURE__ */ jsxRuntime.jsx(Demo, {}) })
|