@ecoding/components.antd 0.3.51 → 0.3.52

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,30 +1,33 @@
1
1
  import React from 'react';
2
2
  import type { FormListFieldData } from 'antd';
3
3
  interface IC {
4
+ type?: "operation";
4
5
  title: string;
5
6
  tooltip?: string;
6
7
  require?: boolean;
7
8
  name: string;
8
9
  rules?: any;
9
10
  width?: number;
10
- render: (field: FormListFieldData, index: number) => React.ReactNode;
11
+ hideRemove?: boolean;
12
+ render: (field: FormListFieldData, index: number, { add, remove }: {
13
+ add: any;
14
+ remove: any;
15
+ }) => React.ReactNode;
11
16
  }
12
17
  interface IProps {
13
18
  columns: IC[];
14
19
  name: string | string[];
15
20
  rules?: any;
16
21
  i18n?: any;
17
- hideOperation?: boolean;
18
22
  hideBottom?: boolean;
19
23
  hideHeader?: boolean;
20
24
  afterRemove?: (index: any) => void;
21
25
  afterAdd?: (index: any) => void;
22
26
  tStyle?: React.CSSProperties;
23
27
  operation?: {
28
+ hide?: boolean;
24
29
  width?: number;
25
- render?: (field: FormListFieldData, index: number) => React.ReactNode;
26
30
  title?: string;
27
- hideRemove?: boolean;
28
31
  };
29
32
  }
30
33
  declare const C: React.FC<IProps>;
@@ -1,7 +1,7 @@
1
1
  import React, { useMemo, useRef } from 'react';
2
2
  import { Typography, Form, Button, Space, Tooltip } from 'antd';
3
3
  import { PlusCircleOutlined, QuestionCircleOutlined } from '@ant-design/icons';
4
- const C = ({ columns, rules, tStyle, name, hideOperation, hideHeader, hideBottom, operation, i18n, afterRemove, afterAdd }) => {
4
+ const C = ({ columns, rules, tStyle, name, hideHeader, hideBottom, operation, i18n, afterRemove, afterAdd }) => {
5
5
  const tbodyRef = useRef(null);
6
6
  const tdStyle = {
7
7
  verticalAlign: 'top',
@@ -32,6 +32,9 @@ const C = ({ columns, rules, tStyle, name, hideOperation, hideHeader, hideBottom
32
32
  }
33
33
  return w;
34
34
  }, []);
35
+ const needDefaultOperation = useMemo(() => {
36
+ return columns.findIndex(column => column.type == "operation") == -1;
37
+ }, []);
35
38
  return (React.createElement(Form.List, { name: name, rules: rules || [] }, (fields, { add, remove }, { errors }) => {
36
39
  return (React.createElement("div", { className: 'm-form-list' },
37
40
  React.createElement("div", { ref: tbodyRef, className: "m-form-list-table", style: Object.assign({}, { marginBottom: '4px', paddingBottom: '12px', overflow: "auto", position: 'relative' }, tStyle) },
@@ -41,7 +44,7 @@ const C = ({ columns, rules, tStyle, name, hideOperation, hideHeader, hideBottom
41
44
  columns.map((column) => {
42
45
  return (React.createElement("col", { style: Object.assign({}, { width: column.width || 200 }) }));
43
46
  }),
44
- hideOperation ? null : (React.createElement("col", { style: Object.assign({}, { width: (operation === null || operation === void 0 ? void 0 : operation.width) || 150 }) }))),
47
+ (operation === null || operation === void 0 ? void 0 : operation.hide) ? null : (React.createElement("col", { style: Object.assign({}, { width: (operation === null || operation === void 0 ? void 0 : operation.width) || 150 }) }))),
45
48
  React.createElement("thead", null, hideHeader ? null : (React.createElement("tr", null,
46
49
  React.createElement("th", { style: thStyle }, i18n ? i18n.$t("global.num", "序号") : "序号"),
47
50
  columns.map((column, i) => {
@@ -57,25 +60,30 @@ const C = ({ columns, rules, tStyle, name, hideOperation, hideHeader, hideBottom
57
60
  column.tooltip ? (React.createElement(Tooltip, { placement: "top", title: column.tooltip || undefined },
58
61
  React.createElement(QuestionCircleOutlined, { style: { paddingLeft: 4, color: "rgba(0, 0, 0, 0.45)" } }))) : null));
59
62
  }),
60
- hideOperation ? null : operation ? (React.createElement("th", { style: Object.assign({}, thStyle, { right: 0 }) }, operation.title || "操作")) : (React.createElement("th", { style: Object.assign({}, thStyle, { right: 0 }) }, i18n ? i18n.$t("global.operation", "操作") : "操作"))))),
63
+ (operation === null || operation === void 0 ? void 0 : operation.hide) ? null : (React.createElement("th", { style: Object.assign({}, thStyle, { right: 0 }) }, i18n ? i18n.$t("global.operation", "操作") : "操作"))))),
61
64
  React.createElement("tbody", null, fields.map((field, index) => {
62
65
  return (React.createElement("tr", { style: trStyle },
63
66
  React.createElement("td", { style: tdStyle }, index + 1),
64
67
  columns.map((column, i) => {
65
- return (React.createElement("td", { style: tdStyle },
66
- React.createElement(Form.Item, { style: { marginBottom: 0 }, name: [field.name, column.name], rules: column.rules || [] }, column.render(field, index))));
68
+ if (column.type == "operation") {
69
+ return (React.createElement("td", { style: Object.assign({}, tdStyle, { right: 0, position: "sticky", backgroundColor: "#fff" }) },
70
+ React.createElement(Space, null,
71
+ column.render && column.render(field, index, { add, remove }),
72
+ column.hideRemove ? null : (React.createElement(Typography.Text, { style: { cursor: 'pointer' }, type: "danger", onClick: () => {
73
+ remove(field.name);
74
+ afterRemove && afterRemove(field.name);
75
+ } }, i18n ? i18n.$t("global.del", '删除') : '删除')))));
76
+ }
77
+ else {
78
+ return (React.createElement("td", { style: tdStyle },
79
+ React.createElement(Form.Item, { style: { marginBottom: 0 }, name: [field.name, column.name], rules: column.rules || [] }, column.render(field, index, { add, remove }))));
80
+ }
67
81
  }),
68
- hideOperation ? null : operation ? (React.createElement("td", { style: Object.assign({}, tdStyle, { right: 0, position: "sticky", backgroundColor: "#fff" }) },
69
- React.createElement(Space, null,
70
- operation.render && operation.render(field, index),
71
- operation.hideRemove ? null : (React.createElement(Typography.Text, { style: { cursor: 'pointer' }, type: "danger", onClick: () => {
72
- remove(field.name);
73
- afterRemove && afterRemove(field.name);
74
- } }, i18n ? i18n.$t("global.del", '删除') : '删除'))))) : (React.createElement("td", { style: Object.assign({}, tdStyle, { right: 0, position: "sticky", backgroundColor: "#fff" }) },
82
+ needDefaultOperation ? (React.createElement("td", { style: Object.assign({}, tdStyle, { right: 0, position: "sticky", backgroundColor: "#fff" }) },
75
83
  React.createElement(Typography.Text, { style: { cursor: 'pointer' }, type: "danger", onClick: () => {
76
84
  remove(field.name);
77
85
  afterRemove && afterRemove(field.name);
78
- } }, i18n ? i18n.$t("global.del", '删除') : '删除')))));
86
+ } }, i18n ? i18n.$t("global.del", '删除') : '删除'))) : null));
79
87
  })))),
80
88
  hideBottom ? null : (React.createElement("div", null,
81
89
  React.createElement(Button, { icon: React.createElement(PlusCircleOutlined, null), type: "dashed", onClick: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecoding/components.antd",
3
- "version": "0.3.51",
3
+ "version": "0.3.52",
4
4
  "author": "cxc",
5
5
  "homepage": "",
6
6
  "license": "MIT",
@@ -43,5 +43,5 @@
43
43
  "antd": "^5.8.4",
44
44
  "axios": "^1.1.2"
45
45
  },
46
- "gitHead": "96d7a7d82eb85ab9e5cd69b6e0b8f5005c41725c"
46
+ "gitHead": "22b626329c16b7de1ff9d11f8f5667c18fde36d5"
47
47
  }