szld-libs 0.2.44 → 0.2.46

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,13 +1,23 @@
1
- import { CSSProperties, ReactNode } from "react";
1
+ import { CSSProperties, ReactNode } from 'react';
2
2
  interface BackHeaderProps {
3
+ /** 是否显示返回按钮 */
3
4
  isBack?: boolean;
5
+ /** 页头标题 */
4
6
  title: string | ReactNode;
7
+ /** 页头副标题 */
5
8
  subTitle?: string | ReactNode;
9
+ /** 标题右侧元素 */
6
10
  extra?: ReactNode;
11
+ /** 自定义class */
7
12
  className?: string;
13
+ /** 自定义页头style */
8
14
  style?: CSSProperties;
15
+ /** 自定义标题style */
9
16
  titleStyle?: CSSProperties;
17
+ /** 重要程度,相当于 h1、h2、h3、h4、h5 */
10
18
  level?: 1 | 2 | 3 | 4 | 5;
19
+ /** 自定义图标 */
20
+ icon?: React.ReactNode;
11
21
  }
12
22
  declare const BackHeader: (props: BackHeaderProps) => import("react/jsx-runtime").JSX.Element;
13
23
  export default BackHeader;
@@ -1,5 +1,5 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
- import { Space, Typography } from "antd";
2
+ import { Space, Button, Typography } from "antd";
3
3
  import { ArrowLeftOutlined } from "@ant-design/icons";
4
4
  import { useNavigate } from "react-router-dom";
5
5
  import classNames from "classnames";
@@ -13,16 +13,7 @@ const styles = {
13
13
  };
14
14
  const { Title, Text } = Typography;
15
15
  const BackHeader = (props) => {
16
- const {
17
- isBack = true,
18
- title: title2,
19
- extra,
20
- subTitle = null,
21
- className,
22
- style,
23
- titleStyle,
24
- level = 2
25
- } = props;
16
+ const { isBack = true, title: title2, extra, subTitle = null, className, style, titleStyle, level = 2, icon } = props;
26
17
  const navigate = useNavigate();
27
18
  const renderSubtitle = () => {
28
19
  if (typeof subTitle === "string") {
@@ -35,7 +26,7 @@ const BackHeader = (props) => {
35
26
  };
36
27
  return /* @__PURE__ */ jsxs("div", { className: classNames(styles.main, className), style, children: [
37
28
  /* @__PURE__ */ jsxs(Space, { children: [
38
- isBack && /* @__PURE__ */ jsx(ArrowLeftOutlined, { style: { fontSize: 24 }, onClick: goBack }),
29
+ isBack && /* @__PURE__ */ jsx(Button, { type: "text", icon: icon || /* @__PURE__ */ jsx(ArrowLeftOutlined, { style: { fontSize: 24 } }), onClick: goBack }),
39
30
  /* @__PURE__ */ jsxs(Title, { level, className: styles.title, style: titleStyle, children: [
40
31
  title2,
41
32
  renderSubtitle()
@@ -4,6 +4,7 @@ import { CreateFormProps } from '../CreateForm';
4
4
  export interface TableColumnProps<T> extends ColumnType<T> {
5
5
  hidden?: boolean;
6
6
  width?: number | string;
7
+ minWidth?: number | string;
7
8
  }
8
9
  export interface MTableProps<T> extends Omit<TableProps<T>, 'columns'> {
9
10
  columns?: TableColumnProps<T>[];
@@ -1,7 +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 { useState, useEffect } from "react";
4
+ import { useState, useEffect, useMemo } from "react";
5
5
  import { Resizable } from "react-resizable";
6
6
  import { getLocalStorage } from "../../utils";
7
7
  import CreateForm from "../CreateForm";
@@ -22,12 +22,12 @@ function SearchTable(props) {
22
22
  const { tableProps = {}, searchProps } = props;
23
23
  const {
24
24
  minColumnWidth = 200,
25
- resizeable = true,
25
+ resizeable = false,
26
26
  tableId,
27
27
  storageKey = "szld_table_cell_width",
28
28
  ...rest
29
29
  } = tableProps;
30
- const [columns, setColumns] = useState([]);
30
+ const [columns, setColumns] = useState(tableProps.columns || []);
31
31
  const getWidth = (v) => {
32
32
  var _a, _b;
33
33
  let width = v.width || minColumnWidth;
@@ -42,7 +42,7 @@ function SearchTable(props) {
42
42
  };
43
43
  useEffect(() => {
44
44
  const list = tableProps.columns || [];
45
- if (list.length === 0) {
45
+ if (list.length === 0 || !resizeable) {
46
46
  return;
47
47
  }
48
48
  const result = list == null ? void 0 : list.filter((v) => !v.hidden).map((v) => {
@@ -60,10 +60,11 @@ function SearchTable(props) {
60
60
  return v;
61
61
  });
62
62
  if (result.length > 0) {
63
+ result[result.length - 1].minWidth = result[result.length - 1].width;
63
64
  result[result.length - 1].width = void 0;
64
65
  }
65
66
  setColumns(result);
66
- }, [tableProps.columns, tableId, minColumnWidth]);
67
+ }, [tableProps.columns, tableId, minColumnWidth, resizeable]);
67
68
  const handleResize = (column, size) => {
68
69
  setColumns((prevColumns) => {
69
70
  const list = prevColumns == null ? void 0 : prevColumns.map((v) => {
@@ -95,13 +96,24 @@ function SearchTable(props) {
95
96
  },
96
97
  ...rest == null ? void 0 : rest.components
97
98
  };
99
+ const scollX = useMemo(() => {
100
+ var _a;
101
+ const getWidth2 = (v) => {
102
+ let width = v.width || v.minWidth;
103
+ if (!width || typeof width === "string") {
104
+ width = minColumnWidth;
105
+ }
106
+ return width;
107
+ };
108
+ return (_a = columns == null ? void 0 : columns.map((v) => getWidth2(v))) == null ? void 0 : _a.reduce((a, b) => a + b, 0);
109
+ }, [columns, minColumnWidth]);
98
110
  return /* @__PURE__ */ jsxs(Fragment, { children: [
99
111
  searchProps && /* @__PURE__ */ jsx(CreateForm, { hiddenTitle: true, ...searchProps, items: searchProps.items }),
100
112
  /* @__PURE__ */ jsx(
101
113
  Table,
102
114
  {
103
115
  scroll: {
104
- x: columns == null ? void 0 : columns.reduce((a, b) => a + (typeof b.width === "number" ? b.width : minColumnWidth), 0)
116
+ x: scollX
105
117
  },
106
118
  ...rest,
107
119
  components,
package/es/index.js CHANGED
@@ -4,7 +4,7 @@ import ReactDOM from "react-dom/client";
4
4
  import { BrowserRouter } from "react-router-dom";
5
5
  import { Table, Button } from "antd";
6
6
  import useConfig from "./hooks/useConfig";
7
- import { useRowSelection, SearchTable } from "./main";
7
+ import { useRowSelection, BackHeader, 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);
@@ -27,14 +27,21 @@ const Demo = () => {
27
27
  title: "c"
28
28
  }
29
29
  ];
30
- const [list, setList] = useState(Array(10).fill(0).map((v, i) => ({ id: i })));
30
+ const [list, setList] = useState(
31
+ Array(10).fill(0).map((v, i) => ({ id: i }))
32
+ );
31
33
  const [current, setCurrent] = useState(1);
32
34
  const data = [{ id: 1 }, { id: 12 }, { id: 21 }];
33
- const { selectedKeys, selectedRows, setSelectedKeys } = useRowSelection({ dataSource: list, rowKey: "id", defaultRows: data });
35
+ const { selectedKeys, selectedRows, setSelectedKeys } = useRowSelection({
36
+ dataSource: list,
37
+ rowKey: "id",
38
+ defaultRows: data
39
+ });
34
40
  useEffect(() => {
35
41
  setSelectedKeys([1, 12, 21]);
36
42
  }, []);
37
43
  return /* @__PURE__ */ jsxs("div", { style: { height: "100vh" }, children: [
44
+ /* @__PURE__ */ jsx(BackHeader, { title: "新增系统", isBack: true }),
38
45
  /* @__PURE__ */ jsx(Button, { onClick: () => setList(columns), children: "test" }),
39
46
  /* @__PURE__ */ jsx(
40
47
  "div",
@@ -54,18 +61,31 @@ const Demo = () => {
54
61
  {
55
62
  dataIndex: "id",
56
63
  title: "ID"
64
+ },
65
+ {
66
+ dataIndex: "a",
67
+ title: "a",
68
+ width: 200
69
+ },
70
+ {
71
+ dataIndex: "a2",
72
+ title: "a",
73
+ width: 200
74
+ },
75
+ {
76
+ dataIndex: "a3",
77
+ title: "a",
78
+ width: 200
79
+ },
80
+ {
81
+ dataIndex: "a4",
82
+ title: "a",
83
+ width: 400
57
84
  }
58
85
  ],
59
86
  dataSource: list,
60
87
  resizeable: true,
61
88
  rowKey: "id",
62
- rowSelection: {
63
- selectedRowKeys: selectedKeys,
64
- preserveSelectedRowKeys: true,
65
- onChange(keys) {
66
- setSelectedKeys(keys);
67
- }
68
- },
69
89
  pagination: {
70
90
  total: 25,
71
91
  current,
@@ -1,13 +1,23 @@
1
- import { CSSProperties, ReactNode } from "react";
1
+ import { CSSProperties, ReactNode } from 'react';
2
2
  interface BackHeaderProps {
3
+ /** 是否显示返回按钮 */
3
4
  isBack?: boolean;
5
+ /** 页头标题 */
4
6
  title: string | ReactNode;
7
+ /** 页头副标题 */
5
8
  subTitle?: string | ReactNode;
9
+ /** 标题右侧元素 */
6
10
  extra?: ReactNode;
11
+ /** 自定义class */
7
12
  className?: string;
13
+ /** 自定义页头style */
8
14
  style?: CSSProperties;
15
+ /** 自定义标题style */
9
16
  titleStyle?: CSSProperties;
17
+ /** 重要程度,相当于 h1、h2、h3、h4、h5 */
10
18
  level?: 1 | 2 | 3 | 4 | 5;
19
+ /** 自定义图标 */
20
+ icon?: React.ReactNode;
11
21
  }
12
22
  declare const BackHeader: (props: BackHeaderProps) => import("react/jsx-runtime").JSX.Element;
13
23
  export default BackHeader;
@@ -14,16 +14,7 @@ const styles = {
14
14
  };
15
15
  const { Title, Text } = antd.Typography;
16
16
  const BackHeader = (props) => {
17
- const {
18
- isBack = true,
19
- title: title2,
20
- extra,
21
- subTitle = null,
22
- className,
23
- style,
24
- titleStyle,
25
- level = 2
26
- } = props;
17
+ const { isBack = true, title: title2, extra, subTitle = null, className, style, titleStyle, level = 2, icon } = props;
27
18
  const navigate = reactRouterDom.useNavigate();
28
19
  const renderSubtitle = () => {
29
20
  if (typeof subTitle === "string") {
@@ -36,7 +27,7 @@ const BackHeader = (props) => {
36
27
  };
37
28
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: classNames(styles.main, className), style, children: [
38
29
  /* @__PURE__ */ jsxRuntime.jsxs(antd.Space, { children: [
39
- isBack && /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeftOutlined, { style: { fontSize: 24 }, onClick: goBack }),
30
+ isBack && /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { type: "text", icon: icon || /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeftOutlined, { style: { fontSize: 24 } }), onClick: goBack }),
40
31
  /* @__PURE__ */ jsxRuntime.jsxs(Title, { level, className: styles.title, style: titleStyle, children: [
41
32
  title2,
42
33
  renderSubtitle()
@@ -4,6 +4,7 @@ import { CreateFormProps } from '../CreateForm';
4
4
  export interface TableColumnProps<T> extends ColumnType<T> {
5
5
  hidden?: boolean;
6
6
  width?: number | string;
7
+ minWidth?: number | string;
7
8
  }
8
9
  export interface MTableProps<T> extends Omit<TableProps<T>, 'columns'> {
9
10
  columns?: TableColumnProps<T>[];
@@ -23,12 +23,12 @@ function SearchTable(props) {
23
23
  const { tableProps = {}, searchProps } = props;
24
24
  const {
25
25
  minColumnWidth = 200,
26
- resizeable = true,
26
+ resizeable = false,
27
27
  tableId,
28
28
  storageKey = "szld_table_cell_width",
29
29
  ...rest
30
30
  } = tableProps;
31
- const [columns, setColumns] = react.useState([]);
31
+ const [columns, setColumns] = react.useState(tableProps.columns || []);
32
32
  const getWidth = (v) => {
33
33
  var _a, _b;
34
34
  let width = v.width || minColumnWidth;
@@ -43,7 +43,7 @@ function SearchTable(props) {
43
43
  };
44
44
  react.useEffect(() => {
45
45
  const list = tableProps.columns || [];
46
- if (list.length === 0) {
46
+ if (list.length === 0 || !resizeable) {
47
47
  return;
48
48
  }
49
49
  const result = list == null ? void 0 : list.filter((v) => !v.hidden).map((v) => {
@@ -61,10 +61,11 @@ function SearchTable(props) {
61
61
  return v;
62
62
  });
63
63
  if (result.length > 0) {
64
+ result[result.length - 1].minWidth = result[result.length - 1].width;
64
65
  result[result.length - 1].width = void 0;
65
66
  }
66
67
  setColumns(result);
67
- }, [tableProps.columns, tableId, minColumnWidth]);
68
+ }, [tableProps.columns, tableId, minColumnWidth, resizeable]);
68
69
  const handleResize = (column, size) => {
69
70
  setColumns((prevColumns) => {
70
71
  const list = prevColumns == null ? void 0 : prevColumns.map((v) => {
@@ -96,13 +97,24 @@ function SearchTable(props) {
96
97
  },
97
98
  ...rest == null ? void 0 : rest.components
98
99
  };
100
+ const scollX = react.useMemo(() => {
101
+ var _a;
102
+ const getWidth2 = (v) => {
103
+ let width = v.width || v.minWidth;
104
+ if (!width || typeof width === "string") {
105
+ width = minColumnWidth;
106
+ }
107
+ return width;
108
+ };
109
+ return (_a = columns == null ? void 0 : columns.map((v) => getWidth2(v))) == null ? void 0 : _a.reduce((a, b) => a + b, 0);
110
+ }, [columns, minColumnWidth]);
99
111
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
100
112
  searchProps && /* @__PURE__ */ jsxRuntime.jsx(CreateForm, { hiddenTitle: true, ...searchProps, items: searchProps.items }),
101
113
  /* @__PURE__ */ jsxRuntime.jsx(
102
114
  antd.Table,
103
115
  {
104
116
  scroll: {
105
- x: columns == null ? void 0 : columns.reduce((a, b) => a + (typeof b.width === "number" ? b.width : minColumnWidth), 0)
117
+ x: scollX
106
118
  },
107
119
  ...rest,
108
120
  components,
package/lib/index.js CHANGED
@@ -28,14 +28,21 @@ const Demo = () => {
28
28
  title: "c"
29
29
  }
30
30
  ];
31
- const [list, setList] = react.useState(Array(10).fill(0).map((v, i) => ({ id: i })));
31
+ const [list, setList] = react.useState(
32
+ Array(10).fill(0).map((v, i) => ({ id: i }))
33
+ );
32
34
  const [current, setCurrent] = react.useState(1);
33
35
  const data = [{ id: 1 }, { id: 12 }, { id: 21 }];
34
- const { selectedKeys, selectedRows, setSelectedKeys } = main.useRowSelection({ dataSource: list, rowKey: "id", defaultRows: data });
36
+ const { selectedKeys, selectedRows, setSelectedKeys } = main.useRowSelection({
37
+ dataSource: list,
38
+ rowKey: "id",
39
+ defaultRows: data
40
+ });
35
41
  react.useEffect(() => {
36
42
  setSelectedKeys([1, 12, 21]);
37
43
  }, []);
38
44
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { height: "100vh" }, children: [
45
+ /* @__PURE__ */ jsxRuntime.jsx(main.BackHeader, { title: "新增系统", isBack: true }),
39
46
  /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { onClick: () => setList(columns), children: "test" }),
40
47
  /* @__PURE__ */ jsxRuntime.jsx(
41
48
  "div",
@@ -55,18 +62,31 @@ const Demo = () => {
55
62
  {
56
63
  dataIndex: "id",
57
64
  title: "ID"
65
+ },
66
+ {
67
+ dataIndex: "a",
68
+ title: "a",
69
+ width: 200
70
+ },
71
+ {
72
+ dataIndex: "a2",
73
+ title: "a",
74
+ width: 200
75
+ },
76
+ {
77
+ dataIndex: "a3",
78
+ title: "a",
79
+ width: 200
80
+ },
81
+ {
82
+ dataIndex: "a4",
83
+ title: "a",
84
+ width: 400
58
85
  }
59
86
  ],
60
87
  dataSource: list,
61
88
  resizeable: true,
62
89
  rowKey: "id",
63
- rowSelection: {
64
- selectedRowKeys: selectedKeys,
65
- preserveSelectedRowKeys: true,
66
- onChange(keys) {
67
- setSelectedKeys(keys);
68
- }
69
- },
70
90
  pagination: {
71
91
  total: 25,
72
92
  current,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "szld-libs",
3
3
  "private": false,
4
- "version": "0.2.44",
4
+ "version": "0.2.46",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",