@hzab/list-render 1.12.0 → 1.12.2
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/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/card-render/index.jsx +131 -123
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,123 +1,131 @@
|
|
|
1
|
-
import { useEffect, useState, useMemo, useCallback, useRef } from "react";
|
|
2
|
-
import { Table, Button, Popconfirm, Tooltip, Checkbox, Popover } from "antd";
|
|
3
|
-
import { QuestionCircleOutlined, FilterOutlined, SettingOutlined } from "@ant-design/icons";
|
|
4
|
-
import _ from "lodash";
|
|
5
|
-
import DetailRender from "@hzab/schema-descriptions";
|
|
6
|
-
import { removeInTableFalseFields } from "../common/utils";
|
|
7
|
-
import "./index.less";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const {
|
|
16
|
-
const {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
{
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return (
|
|
106
|
-
<
|
|
107
|
-
{
|
|
108
|
-
|
|
109
|
-
<div
|
|
110
|
-
{props.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
1
|
+
import { useEffect, useState, useMemo, useCallback, useRef } from "react";
|
|
2
|
+
import { Table, Button, Popconfirm, Tooltip, Checkbox, Popover, Spin, Empty } from "antd";
|
|
3
|
+
import { QuestionCircleOutlined, FilterOutlined, SettingOutlined } from "@ant-design/icons";
|
|
4
|
+
import _ from "lodash";
|
|
5
|
+
import DetailRender from "@hzab/schema-descriptions";
|
|
6
|
+
import { removeInTableFalseFields } from "../common/utils";
|
|
7
|
+
import "./index.less";
|
|
8
|
+
|
|
9
|
+
const scenario = "table-render";
|
|
10
|
+
|
|
11
|
+
function CardRender(props) {
|
|
12
|
+
const [schema, setSchema] = useState({});
|
|
13
|
+
|
|
14
|
+
const { config = {}, cardProps = {}, query = {}, i18n, onEdit, onDel, onSearch, getList, Slots = {}, loading } = props;
|
|
15
|
+
const { tableDel = "删除", tableEdit = "编辑", tableDelTip = "确认删除该项?", tableDetail = "详情" } = i18n || {};
|
|
16
|
+
const { columns = 3, CardItemRender, hasEdit, hasDel, hasDelTips, hasDetail = false } = config || {};
|
|
17
|
+
|
|
18
|
+
const functionProps = { onEdit: onEdit, onDel: onDel, onSearch, getList };
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const schemas = removeInTableFalseFields(props?.schema);
|
|
22
|
+
setSchema(schemas);
|
|
23
|
+
}, [props?.schema, props?.schema?.schema]);
|
|
24
|
+
|
|
25
|
+
const getColRender = (record, index) => {
|
|
26
|
+
const _colConf = props.config?.colConf?._$actions || {};
|
|
27
|
+
|
|
28
|
+
const slotProps = { record, index, ...functionProps };
|
|
29
|
+
|
|
30
|
+
if (Slots?.tableActionsSlot) {
|
|
31
|
+
return <Slots.tableActionsSlot {...slotProps} />;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//编辑按钮权限
|
|
35
|
+
const _hasEdit = hasEdit && typeof hasEdit === "function" ? hasEdit(record, index) : hasEdit !== false;
|
|
36
|
+
|
|
37
|
+
//详情按钮权限
|
|
38
|
+
const _hasDetail = hasDetail && typeof hasDetail === "function" ? hasDetail(record, index) : hasDetail !== false;
|
|
39
|
+
|
|
40
|
+
//删除按钮权限
|
|
41
|
+
const _hasDel = hasDel && typeof hasDel === "function" ? hasDel(record, index) : hasDel !== false;
|
|
42
|
+
|
|
43
|
+
//删除按钮提示
|
|
44
|
+
const delTips =
|
|
45
|
+
hasDelTips && typeof hasDelTips === "function" ? hasDelTips(record, index) : hasDelTips || tableDelTip;
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div style={{ width: _colConf?.width, maxWidth: "100%" }}>
|
|
49
|
+
{Slots?.actionPrefixSlot && <Slots.actionPrefixSlot {...slotProps} />}
|
|
50
|
+
{_hasDetail ? (
|
|
51
|
+
<Button
|
|
52
|
+
type="link"
|
|
53
|
+
onClick={() => {
|
|
54
|
+
props.onDetail && props.onDetail(record, index);
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
{tableDetail}
|
|
58
|
+
</Button>
|
|
59
|
+
) : null}
|
|
60
|
+
{_hasEdit ? (
|
|
61
|
+
<Button
|
|
62
|
+
type="link"
|
|
63
|
+
onClick={() => {
|
|
64
|
+
props.onEdit && props.onEdit(record, index);
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
{tableEdit}
|
|
68
|
+
</Button>
|
|
69
|
+
) : null}
|
|
70
|
+
{Slots?.actionCenterSlot && <Slots.actionCenterSlot {...slotProps} />}
|
|
71
|
+
{_hasDel ? (
|
|
72
|
+
<Popconfirm
|
|
73
|
+
placement="topRight"
|
|
74
|
+
title={delTips}
|
|
75
|
+
onConfirm={() => {
|
|
76
|
+
props.onDel && props.onDel(record, index);
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
79
|
+
<Button type="link" danger>
|
|
80
|
+
{tableDel}
|
|
81
|
+
</Button>
|
|
82
|
+
</Popconfirm>
|
|
83
|
+
) : null}
|
|
84
|
+
{Slots?.actionSuffixSlot && <Slots.actionSuffixSlot {...slotProps} />}
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const ItemRender = ({ item, index }) => {
|
|
90
|
+
return CardItemRender ? (
|
|
91
|
+
<CardItemRender item={item} index={index} functionProps={functionProps} />
|
|
92
|
+
) : (
|
|
93
|
+
<DetailRender
|
|
94
|
+
config={props.config}
|
|
95
|
+
schema={schema}
|
|
96
|
+
bordered={false}
|
|
97
|
+
data={item}
|
|
98
|
+
schemaScope={{ scenario: "table-render", ...props.schemaScope }}
|
|
99
|
+
components={props.components}
|
|
100
|
+
{...cardProps}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<Spin spinning={loading}>
|
|
107
|
+
{
|
|
108
|
+
props.list?.length > 0 ?
|
|
109
|
+
<div className="card-render-wrap" style={{ gridTemplateColumns: `repeat(${columns}, 1fr` }}>
|
|
110
|
+
{props.list?.map((item, index) => {
|
|
111
|
+
return (
|
|
112
|
+
<div key={item["id"]} className="item-render-card">
|
|
113
|
+
{props.hasAction !== false ? (
|
|
114
|
+
<div className="item-render-card-title">{getColRender(item, index)}</div>
|
|
115
|
+
) : null}
|
|
116
|
+
<div className="item-render-card-content">
|
|
117
|
+
<ItemRender item={item} index={index} />
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
})}
|
|
122
|
+
</div> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE}></Empty>
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
</Spin>
|
|
127
|
+
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export default CardRender;
|