szld-libs 0.2.32 → 0.2.34

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,8 +1,7 @@
1
1
  import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
2
  import { Table } from "antd";
3
3
  import classNames from "classnames";
4
- import _ from "lodash";
5
- import { useRef, useState, useEffect, useCallback, useMemo } from "react";
4
+ import { useState, useEffect } from "react";
6
5
  import { Resizable } from "react-resizable";
7
6
  import { getLocalStorage } from "../../utils";
8
7
  import CreateForm from "../CreateForm";
@@ -28,7 +27,6 @@ function SearchTable(props) {
28
27
  storageKey = "szld_table_cell_width",
29
28
  ...rest
30
29
  } = tableProps;
31
- const ref = useRef(null);
32
30
  const [columns, setColumns] = useState([]);
33
31
  const getWidth = (v) => {
34
32
  var _a, _b;
@@ -46,24 +44,36 @@ function SearchTable(props) {
46
44
  if (list.length === 0) {
47
45
  return;
48
46
  }
49
- const result = list.map((v) => ({
50
- ...v,
51
- width: getWidth(v)
52
- }));
47
+ const result = list == null ? void 0 : list.filter((v) => !v.hidden).map((v) => {
48
+ if (v.dataIndex) {
49
+ return {
50
+ ...v,
51
+ width: getWidth(v),
52
+ onHeaderCell: (column) => ({
53
+ width: column.width,
54
+ resizeable,
55
+ onResize: (_e, { size }) => handleResize(column, size)
56
+ })
57
+ };
58
+ }
59
+ return v;
60
+ });
61
+ if (result.length > 0) {
62
+ result[result.length - 1].width = void 0;
63
+ }
53
64
  setColumns(result);
54
- ref.current = Date.now();
55
65
  }, [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
- };
66
+ const handleResize = (column, size) => {
67
+ setColumns((prevColumns) => {
68
+ const list = prevColumns == null ? void 0 : prevColumns.map((v) => {
69
+ if (v.dataIndex === column.dataIndex) {
70
+ return {
71
+ ...v,
72
+ width: size.width
73
+ };
74
+ }
75
+ return v;
76
+ });
67
77
  if (tableId) {
68
78
  const obj = getLocalStorage(storageKey) || {};
69
79
  obj[tableId] = obj[tableId] || {};
@@ -74,44 +84,26 @@ function SearchTable(props) {
74
84
  });
75
85
  localStorage.setItem(storageKey, JSON.stringify(obj));
76
86
  }
77
- setColumns(list);
78
- },
79
- [columns, tableId, storageKey]
80
- );
81
- const realColumns = useMemo(() => {
82
- if (!ref.current || columns === void 0) {
83
- return [];
84
- }
85
- const result = columns == null ? void 0 : columns.filter((v) => !v.hidden).map((v) => ({
86
- ...v,
87
- width: v.width,
88
- onHeaderCell: (column) => ({
89
- width: column.width,
90
- resizeable,
91
- onResize: (_e, { size }) => handleResize(column, size)
92
- })
93
- }));
94
- if (result.length > 0) {
95
- result[result.length - 1].width = void 0;
96
- }
97
- return result;
98
- }, [resizeable, columns, ref.current, minColumnWidth]);
87
+ return list;
88
+ });
89
+ };
99
90
  const components = {
100
91
  header: {
101
92
  cell: ResizeableTitle
102
- }
93
+ },
94
+ ...rest == null ? void 0 : rest.components
103
95
  };
104
96
  return /* @__PURE__ */ jsxs(Fragment, { children: [
105
97
  searchProps && /* @__PURE__ */ jsx(CreateForm, { hiddenTitle: true, ...searchProps, items: searchProps.items }),
106
98
  /* @__PURE__ */ jsx(
107
99
  Table,
108
100
  {
109
- ...rest,
110
- columns: realColumns,
111
101
  scroll: {
112
- x: realColumns.reduce((a, b) => a + (typeof b.width === "number" ? b.width : minColumnWidth), 0)
102
+ x: columns == null ? void 0 : columns.reduce((a, b) => a + (typeof b.width === "number" ? b.width : minColumnWidth), 0)
113
103
  },
104
+ ...rest,
114
105
  components,
106
+ columns,
115
107
  className: classNames(classes.table, tableProps == null ? void 0 : tableProps.className),
116
108
  pagination: typeof (tableProps == null ? void 0 : tableProps.pagination) === "boolean" ? tableProps.pagination : {
117
109
  showPrevNextJumpers: true,
package/es/index.js CHANGED
@@ -2,38 +2,26 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
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
+ import { Table, Button } from "antd";
6
6
  import useConfig from "./hooks/useConfig";
7
- import { AES, SearchTable } from "./main";
7
+ import { SearchTable } from "./main";
8
8
  let key = "U2FsdGVkX1/dG1NSXNR9hnp3Ech/v6Gh8CDDJxgBm1EPFQel12ySIf84ARXCPwTae7TzwgPvjOyE3S5rAEzl/wAZmId6pbezpFeFcJqxdmIl3FeluYHFxJzQHDETTvrr3G/REvv00kHptOVwg6ecjPH6yk7PNit0sWTBLorROxLxMD8lVDmOA66p7Zp4QnYzqScYJGFbutmfHYXfBRBe1Q2UKummJ798svNY5SIwEwl4spzgyWmhARtuyq4zhysFrj/xODuNDjtwitA6XfX566WcZkj3F+2P+mkYzDYOhXXaomnlybjrZ2hEHfcczQhUfJd89O8PNIuEWo24wjYRgMdKlw5CWSeocFCqV7ZJ/CV/7vNRcaO4awKlFNobLikkwDznxpcX+4UEej+ED+pgfmPQLsKedcfEscStkSAZXaD5pBRTiFU9xGLfDt6seUrEnMBeXkpMIY9j1SZDDK18/G7lSHjDQMZYZP6sfLdBdwY=";
9
9
  const Demo = () => {
10
10
  useConfig(key);
11
11
  useEffect(() => {
12
- jiami();
13
12
  }, []);
14
- const jiami = () => {
15
- const aes = new AES();
16
- aes.encrypt(
17
- JSON.stringify({
18
- AppID: "GZY_SZLD_GZYDP",
19
- Password: "GZY_SZLD_GZYDP2557013",
20
- copyright: " © 云雁科技有限公司 2023 版权所有",
21
- icp: 'ICP备案/许可证号:<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">湘B2-20090059</a> 公网安备号 44030502008569 隐私政策',
22
- tel: "400-607-0705",
23
- Salt: "HnSzldjt#2557013#"
24
- })
25
- );
26
- };
27
13
  const columns = [
28
14
  {
29
15
  dataIndex: "a",
30
16
  title: "a"
31
17
  },
18
+ Table.EXPAND_COLUMN,
32
19
  {
33
20
  dataIndex: "b",
34
21
  title: "b",
35
22
  width: 400
36
23
  },
24
+ Table.SELECTION_COLUMN,
37
25
  {
38
26
  dataIndex: "c",
39
27
  title: "c"
@@ -42,9 +30,39 @@ const Demo = () => {
42
30
  const [list, setList] = useState([]);
43
31
  return /* @__PURE__ */ jsxs("div", { style: { height: "100vh" }, children: [
44
32
  /* @__PURE__ */ jsx(Button, { onClick: () => setList(columns), children: "test" }),
45
- /* @__PURE__ */ jsx(SearchTable, { tableProps: { columns: list, dataSource: [], resizeable: true, tableId: "demo1" } })
33
+ /* @__PURE__ */ jsx(
34
+ SearchTable,
35
+ {
36
+ tableProps: {
37
+ columns: list,
38
+ dataSource: [
39
+ { a: 1, b: 2, c: 3, id: 1 },
40
+ { a: 1, b: 2, c: 3, id: 2 },
41
+ { a: 1, b: 2, c: 3, id: 3 }
42
+ ],
43
+ resizeable: true,
44
+ rowKey: "id",
45
+ rowSelection: {},
46
+ expandable: {
47
+ expandedRowRender: () => {
48
+ return /* @__PURE__ */ jsx("div", { children: "123" });
49
+ }
50
+ },
51
+ tableId: "demo1",
52
+ storageKey: "szld-libs-test",
53
+ components: {
54
+ body: {
55
+ cell: CustomCell
56
+ }
57
+ }
58
+ }
59
+ }
60
+ )
46
61
  ] });
47
62
  };
63
+ const CustomCell = (props) => {
64
+ return /* @__PURE__ */ jsx("td", { ...props, className: "tdtdtdtd", children: props.children });
65
+ };
48
66
  ReactDOM.createRoot(document.getElementById("root")).render(
49
67
  /* @__PURE__ */ jsx(BrowserRouter, { children: /* @__PURE__ */ jsx(Demo, {}) })
50
68
  );
@@ -2,7 +2,6 @@
2
2
  const jsxRuntime = require("react/jsx-runtime");
3
3
  const antd = require("antd");
4
4
  const classNames = require("classnames");
5
- const _ = require("lodash");
6
5
  const react = require("react");
7
6
  const reactResizable = require("react-resizable");
8
7
  const utils = require("../../utils");
@@ -29,7 +28,6 @@ function SearchTable(props) {
29
28
  storageKey = "szld_table_cell_width",
30
29
  ...rest
31
30
  } = tableProps;
32
- const ref = react.useRef(null);
33
31
  const [columns, setColumns] = react.useState([]);
34
32
  const getWidth = (v) => {
35
33
  var _a, _b;
@@ -47,24 +45,36 @@ function SearchTable(props) {
47
45
  if (list.length === 0) {
48
46
  return;
49
47
  }
50
- const result = list.map((v) => ({
51
- ...v,
52
- width: getWidth(v)
53
- }));
48
+ const result = list == null ? void 0 : list.filter((v) => !v.hidden).map((v) => {
49
+ if (v.dataIndex) {
50
+ return {
51
+ ...v,
52
+ width: getWidth(v),
53
+ onHeaderCell: (column) => ({
54
+ width: column.width,
55
+ resizeable,
56
+ onResize: (_e, { size }) => handleResize(column, size)
57
+ })
58
+ };
59
+ }
60
+ return v;
61
+ });
62
+ if (result.length > 0) {
63
+ result[result.length - 1].width = void 0;
64
+ }
54
65
  setColumns(result);
55
- ref.current = Date.now();
56
66
  }, [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
- };
67
+ const handleResize = (column, size) => {
68
+ setColumns((prevColumns) => {
69
+ const list = prevColumns == null ? void 0 : prevColumns.map((v) => {
70
+ if (v.dataIndex === column.dataIndex) {
71
+ return {
72
+ ...v,
73
+ width: size.width
74
+ };
75
+ }
76
+ return v;
77
+ });
68
78
  if (tableId) {
69
79
  const obj = utils.getLocalStorage(storageKey) || {};
70
80
  obj[tableId] = obj[tableId] || {};
@@ -75,44 +85,26 @@ function SearchTable(props) {
75
85
  });
76
86
  localStorage.setItem(storageKey, JSON.stringify(obj));
77
87
  }
78
- setColumns(list);
79
- },
80
- [columns, tableId, storageKey]
81
- );
82
- const realColumns = react.useMemo(() => {
83
- if (!ref.current || columns === void 0) {
84
- return [];
85
- }
86
- const result = columns == null ? void 0 : columns.filter((v) => !v.hidden).map((v) => ({
87
- ...v,
88
- width: v.width,
89
- onHeaderCell: (column) => ({
90
- width: column.width,
91
- resizeable,
92
- onResize: (_e, { size }) => handleResize(column, size)
93
- })
94
- }));
95
- if (result.length > 0) {
96
- result[result.length - 1].width = void 0;
97
- }
98
- return result;
99
- }, [resizeable, columns, ref.current, minColumnWidth]);
88
+ return list;
89
+ });
90
+ };
100
91
  const components = {
101
92
  header: {
102
93
  cell: ResizeableTitle
103
- }
94
+ },
95
+ ...rest == null ? void 0 : rest.components
104
96
  };
105
97
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
106
98
  searchProps && /* @__PURE__ */ jsxRuntime.jsx(CreateForm, { hiddenTitle: true, ...searchProps, items: searchProps.items }),
107
99
  /* @__PURE__ */ jsxRuntime.jsx(
108
100
  antd.Table,
109
101
  {
110
- ...rest,
111
- columns: realColumns,
112
102
  scroll: {
113
- x: realColumns.reduce((a, b) => a + (typeof b.width === "number" ? b.width : minColumnWidth), 0)
103
+ x: columns == null ? void 0 : columns.reduce((a, b) => a + (typeof b.width === "number" ? b.width : minColumnWidth), 0)
114
104
  },
105
+ ...rest,
115
106
  components,
107
+ columns,
116
108
  className: classNames(classes.table, tableProps == null ? void 0 : tableProps.className),
117
109
  pagination: typeof (tableProps == null ? void 0 : tableProps.pagination) === "boolean" ? tableProps.pagination : {
118
110
  showPrevNextJumpers: true,
package/lib/index.js CHANGED
@@ -10,31 +10,19 @@ let key = "U2FsdGVkX1/dG1NSXNR9hnp3Ech/v6Gh8CDDJxgBm1EPFQel12ySIf84ARXCPwTae7Tzw
10
10
  const Demo = () => {
11
11
  useConfig(key);
12
12
  react.useEffect(() => {
13
- jiami();
14
13
  }, []);
15
- const jiami = () => {
16
- const aes = new main.AES();
17
- aes.encrypt(
18
- JSON.stringify({
19
- AppID: "GZY_SZLD_GZYDP",
20
- Password: "GZY_SZLD_GZYDP2557013",
21
- copyright: " © 云雁科技有限公司 2023 版权所有",
22
- icp: 'ICP备案/许可证号:<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">湘B2-20090059</a> 公网安备号 44030502008569 隐私政策',
23
- tel: "400-607-0705",
24
- Salt: "HnSzldjt#2557013#"
25
- })
26
- );
27
- };
28
14
  const columns = [
29
15
  {
30
16
  dataIndex: "a",
31
17
  title: "a"
32
18
  },
19
+ antd.Table.EXPAND_COLUMN,
33
20
  {
34
21
  dataIndex: "b",
35
22
  title: "b",
36
23
  width: 400
37
24
  },
25
+ antd.Table.SELECTION_COLUMN,
38
26
  {
39
27
  dataIndex: "c",
40
28
  title: "c"
@@ -43,9 +31,39 @@ const Demo = () => {
43
31
  const [list, setList] = react.useState([]);
44
32
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { height: "100vh" }, children: [
45
33
  /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { onClick: () => setList(columns), children: "test" }),
46
- /* @__PURE__ */ jsxRuntime.jsx(main.SearchTable, { tableProps: { columns: list, dataSource: [], resizeable: true, tableId: "demo1" } })
34
+ /* @__PURE__ */ jsxRuntime.jsx(
35
+ main.SearchTable,
36
+ {
37
+ tableProps: {
38
+ columns: list,
39
+ dataSource: [
40
+ { a: 1, b: 2, c: 3, id: 1 },
41
+ { a: 1, b: 2, c: 3, id: 2 },
42
+ { a: 1, b: 2, c: 3, id: 3 }
43
+ ],
44
+ resizeable: true,
45
+ rowKey: "id",
46
+ rowSelection: {},
47
+ expandable: {
48
+ expandedRowRender: () => {
49
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { children: "123" });
50
+ }
51
+ },
52
+ tableId: "demo1",
53
+ storageKey: "szld-libs-test",
54
+ components: {
55
+ body: {
56
+ cell: CustomCell
57
+ }
58
+ }
59
+ }
60
+ }
61
+ )
47
62
  ] });
48
63
  };
64
+ const CustomCell = (props) => {
65
+ return /* @__PURE__ */ jsxRuntime.jsx("td", { ...props, className: "tdtdtdtd", children: props.children });
66
+ };
49
67
  ReactDOM.createRoot(document.getElementById("root")).render(
50
68
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.BrowserRouter, { children: /* @__PURE__ */ jsxRuntime.jsx(Demo, {}) })
51
69
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "szld-libs",
3
3
  "private": false,
4
- "version": "0.2.32",
4
+ "version": "0.2.34",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",