@hzab/list-render 1.11.0 → 1.12.1
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 +13 -1
- package/README.md +0 -20
- package/package.json +4 -3
- package/src/DetailModal/index.jsx +120 -120
- package/src/FormModal/index.tsx +210 -210
- package/src/card-render/index.jsx +127 -123
- package/src/table-render/index.jsx +123 -119
- package/src/components/CellEditTable/Template/ExpandListTemplate/index.less +0 -18
- package/src/components/CellEditTable/Template/ExpandListTemplate/index.tsx +0 -92
- package/src/components/CellEditTable/Template/NumberCellTemplate.tsx +0 -168
- package/src/components/CellEditTable/Template/SelectCellTemplate.tsx +0 -202
- package/src/components/CellEditTable/Template/TextCellTemplate.tsx +0 -123
- package/src/components/CellEditTable/Template/utils.ts +0 -257
- package/src/components/CellEditTable/Template/widthWrap.tsx +0 -263
- package/src/components/CellEditTable/index.less +0 -11
- package/src/components/CellEditTable/index.tsx +0 -344
package/src/FormModal/index.tsx
CHANGED
|
@@ -1,210 +1,210 @@
|
|
|
1
|
-
import { forwardRef, useEffect, useImperativeHandle, useRef, useState, useMemo } from "react";
|
|
2
|
-
import _ from "lodash";
|
|
3
|
-
|
|
4
|
-
import { Modal, Drawer, Button, message } from "antd";
|
|
5
|
-
|
|
6
|
-
import FormRender from "@hzab/form-render";
|
|
7
|
-
|
|
8
|
-
import "./index.less";
|
|
9
|
-
|
|
10
|
-
let _formData = null;
|
|
11
|
-
|
|
12
|
-
export interface IFormRender {
|
|
13
|
-
setValues: Function;
|
|
14
|
-
reset: Function;
|
|
15
|
-
validate: Function;
|
|
16
|
-
values: Object;
|
|
17
|
-
}
|
|
18
|
-
export interface IFormRef {
|
|
19
|
-
formRender: IFormRender;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 表单弹层,包含弹窗、抽屉两种模式
|
|
24
|
-
* @param props
|
|
25
|
-
* @param parentRef
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
export function FormModal(props, parentRef) {
|
|
29
|
-
const { modalMode, Slots = {}, modalConf = {}, modalProps = {} } = props;
|
|
30
|
-
const [loading, setLoading] = useState(false);
|
|
31
|
-
const [title, setTitle] = useState("新增");
|
|
32
|
-
const [open, setOpen] = useState(false);
|
|
33
|
-
const formRef = useRef<IFormRef>();
|
|
34
|
-
const scenarioRef = useRef<string>("create");
|
|
35
|
-
|
|
36
|
-
const FormSlot = useMemo(() => props.Slots?.FormSlot, [props.Slots?.FormSlot]);
|
|
37
|
-
|
|
38
|
-
function show(formData = props.formInitialValues, title, scenario = "create") {
|
|
39
|
-
scenarioRef.current = scenario || "create";
|
|
40
|
-
setOpen(true);
|
|
41
|
-
// 处理 formRef.current 为 undefined 的问题
|
|
42
|
-
if (formRef.current?.formRender?.setValues) {
|
|
43
|
-
formRef.current?.formRender?.setValues(formData);
|
|
44
|
-
_formData = null;
|
|
45
|
-
} else {
|
|
46
|
-
_formData = formData;
|
|
47
|
-
}
|
|
48
|
-
setTitle(title || "新增");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function close() {
|
|
52
|
-
props.onClose && props.onClose();
|
|
53
|
-
setOpen(false);
|
|
54
|
-
formRef.current?.formRender?.reset();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
useImperativeHandle(parentRef, () => ({
|
|
58
|
-
show,
|
|
59
|
-
close,
|
|
60
|
-
cancel: close,
|
|
61
|
-
onOk,
|
|
62
|
-
formRef,
|
|
63
|
-
}));
|
|
64
|
-
|
|
65
|
-
// Hack: 解决 FormModal DetailModal 相互影响的问题
|
|
66
|
-
if (!open) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function onOk() {
|
|
71
|
-
validate().then(async () => {
|
|
72
|
-
const submitForm = _.cloneDeep(await formRef.current?.formRender?.values);
|
|
73
|
-
if (modalConf.beforeSubmit) {
|
|
74
|
-
const isContinue = await modalConf.beforeSubmit(submitForm, {
|
|
75
|
-
cancel: close,
|
|
76
|
-
formRef,
|
|
77
|
-
scenario: scenarioRef.current,
|
|
78
|
-
});
|
|
79
|
-
if (isContinue === false) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
setLoading(true);
|
|
86
|
-
await (props.onSubmit && props.onSubmit(submitForm));
|
|
87
|
-
close();
|
|
88
|
-
} catch (error) {
|
|
89
|
-
console.error(error);
|
|
90
|
-
}
|
|
91
|
-
setLoading(false);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* 校验表单
|
|
97
|
-
* @returns
|
|
98
|
-
*/
|
|
99
|
-
function validate(hideMessage = false) {
|
|
100
|
-
return new Promise((resolve, reject) => {
|
|
101
|
-
formRef.current?.formRender
|
|
102
|
-
?.validate()
|
|
103
|
-
.then((values) => {
|
|
104
|
-
resolve(values);
|
|
105
|
-
})
|
|
106
|
-
.catch((err) => {
|
|
107
|
-
reject(err);
|
|
108
|
-
console.error("Error validate: ", err);
|
|
109
|
-
!hideMessage && message.error("输入有误!");
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
let footer = undefined;
|
|
115
|
-
const options = {
|
|
116
|
-
cancel: close,
|
|
117
|
-
onOk,
|
|
118
|
-
close,
|
|
119
|
-
formRef,
|
|
120
|
-
validate,
|
|
121
|
-
scenario: scenarioRef.current,
|
|
122
|
-
};
|
|
123
|
-
if (modalConf?.footer) {
|
|
124
|
-
footer = typeof modalConf?.footer === "function" ? modalConf.footer({ ...options, options }) : modalConf?.footer;
|
|
125
|
-
} else {
|
|
126
|
-
footer = [];
|
|
127
|
-
|
|
128
|
-
if (Slots.modalFooterPre) {
|
|
129
|
-
footer.push(<Slots.modalFooterPre key="pre" options={options} />);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
footer.push(
|
|
133
|
-
<Button key="cancel" onClick={close}>
|
|
134
|
-
{modalConf.cancelText || "取 消"}
|
|
135
|
-
</Button>,
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
if (Slots.modalFooterCenter) {
|
|
139
|
-
footer.push(<Slots.modalFooterCenter key="center" options={options} />);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
footer.push(
|
|
143
|
-
<Button key="confirm" type="primary" onClick={onOk} loading={loading}>
|
|
144
|
-
{modalConf.okText || "确 定"}
|
|
145
|
-
</Button>,
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
if (Slots.modalFooterSuffix) {
|
|
149
|
-
footer.push(<Slots.modalFooterSuffix key="suffix" options={options} />);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* 解决 show 函数中 formRef.current 为 undefined 的问题
|
|
155
|
-
*/
|
|
156
|
-
function didMount() {
|
|
157
|
-
props.modalFormMount && props.modalFormMount();
|
|
158
|
-
if (_formData) {
|
|
159
|
-
formRef.current?.formRender?.setValues(_formData);
|
|
160
|
-
_formData = null;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const CModal = modalMode === "drawer" ? Drawer : Modal;
|
|
165
|
-
const _modalProps = {
|
|
166
|
-
className: "form-modal",
|
|
167
|
-
wrapClassName: "form-modal",
|
|
168
|
-
title: title,
|
|
169
|
-
visible: open,
|
|
170
|
-
open: open,
|
|
171
|
-
onClose: close,
|
|
172
|
-
onCancel: close,
|
|
173
|
-
onOk: onOk,
|
|
174
|
-
footer: footer,
|
|
175
|
-
maskClosable: modalProps.maskClosable || false,
|
|
176
|
-
width: modalConf?.width ?? 720,
|
|
177
|
-
// 解决弹窗不销毁,表单远程数据没有更新的问题
|
|
178
|
-
destroyOnClose: true,
|
|
179
|
-
...modalProps,
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
return (
|
|
183
|
-
<CModal {..._modalProps}>
|
|
184
|
-
{FormSlot ? (
|
|
185
|
-
<FormSlot {...props} formRef={formRef} scenario={scenarioRef.current} schema={props.schema} />
|
|
186
|
-
) : (
|
|
187
|
-
<FormRender
|
|
188
|
-
{...props.formProps}
|
|
189
|
-
ref={formRef}
|
|
190
|
-
schema={props.schema}
|
|
191
|
-
schemaScope={{
|
|
192
|
-
scenario: scenarioRef.current,
|
|
193
|
-
...(props.schemaScope || {}),
|
|
194
|
-
}}
|
|
195
|
-
components={props.components}
|
|
196
|
-
></FormRender>
|
|
197
|
-
)}
|
|
198
|
-
<DidMount didMount={didMount} />
|
|
199
|
-
</CModal>
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function DidMount(props) {
|
|
204
|
-
useEffect(() => {
|
|
205
|
-
props.didMount();
|
|
206
|
-
}, []);
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export default forwardRef(FormModal);
|
|
1
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState, useMemo } from "react";
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
|
|
4
|
+
import { Modal, Drawer, Button, message } from "antd";
|
|
5
|
+
|
|
6
|
+
import FormRender from "@hzab/form-render";
|
|
7
|
+
|
|
8
|
+
import "./index.less";
|
|
9
|
+
|
|
10
|
+
let _formData = null;
|
|
11
|
+
|
|
12
|
+
export interface IFormRender {
|
|
13
|
+
setValues: Function;
|
|
14
|
+
reset: Function;
|
|
15
|
+
validate: Function;
|
|
16
|
+
values: Object;
|
|
17
|
+
}
|
|
18
|
+
export interface IFormRef {
|
|
19
|
+
formRender: IFormRender;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 表单弹层,包含弹窗、抽屉两种模式
|
|
24
|
+
* @param props
|
|
25
|
+
* @param parentRef
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export function FormModal(props, parentRef) {
|
|
29
|
+
const { modalMode, Slots = {}, modalConf = {}, modalProps = {} } = props;
|
|
30
|
+
const [loading, setLoading] = useState(false);
|
|
31
|
+
const [title, setTitle] = useState("新增");
|
|
32
|
+
const [open, setOpen] = useState(false);
|
|
33
|
+
const formRef = useRef<IFormRef>();
|
|
34
|
+
const scenarioRef = useRef<string>("create");
|
|
35
|
+
|
|
36
|
+
const FormSlot = useMemo(() => props.Slots?.FormSlot, [props.Slots?.FormSlot]);
|
|
37
|
+
|
|
38
|
+
function show(formData = props.formInitialValues, title, scenario = "create") {
|
|
39
|
+
scenarioRef.current = scenario || "create";
|
|
40
|
+
setOpen(true);
|
|
41
|
+
// 处理 formRef.current 为 undefined 的问题
|
|
42
|
+
if (formRef.current?.formRender?.setValues) {
|
|
43
|
+
formRef.current?.formRender?.setValues(formData);
|
|
44
|
+
_formData = null;
|
|
45
|
+
} else {
|
|
46
|
+
_formData = formData;
|
|
47
|
+
}
|
|
48
|
+
setTitle(title || "新增");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function close() {
|
|
52
|
+
props.onClose && props.onClose();
|
|
53
|
+
setOpen(false);
|
|
54
|
+
formRef.current?.formRender?.reset();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
useImperativeHandle(parentRef, () => ({
|
|
58
|
+
show,
|
|
59
|
+
close,
|
|
60
|
+
cancel: close,
|
|
61
|
+
onOk,
|
|
62
|
+
formRef,
|
|
63
|
+
}));
|
|
64
|
+
|
|
65
|
+
// Hack: 解决 FormModal DetailModal 相互影响的问题
|
|
66
|
+
if (!open) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function onOk() {
|
|
71
|
+
validate().then(async () => {
|
|
72
|
+
const submitForm = _.cloneDeep(await formRef.current?.formRender?.values);
|
|
73
|
+
if (modalConf.beforeSubmit) {
|
|
74
|
+
const isContinue = await modalConf.beforeSubmit(submitForm, {
|
|
75
|
+
cancel: close,
|
|
76
|
+
formRef,
|
|
77
|
+
scenario: scenarioRef.current,
|
|
78
|
+
});
|
|
79
|
+
if (isContinue === false) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
setLoading(true);
|
|
86
|
+
await (props.onSubmit && props.onSubmit(submitForm));
|
|
87
|
+
close();
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error(error);
|
|
90
|
+
}
|
|
91
|
+
setLoading(false);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 校验表单
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
function validate(hideMessage = false) {
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
formRef.current?.formRender
|
|
102
|
+
?.validate()
|
|
103
|
+
.then((values) => {
|
|
104
|
+
resolve(values);
|
|
105
|
+
})
|
|
106
|
+
.catch((err) => {
|
|
107
|
+
reject(err);
|
|
108
|
+
console.error("Error validate: ", err);
|
|
109
|
+
!hideMessage && message.error("输入有误!");
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let footer = undefined;
|
|
115
|
+
const options = {
|
|
116
|
+
cancel: close,
|
|
117
|
+
onOk,
|
|
118
|
+
close,
|
|
119
|
+
formRef,
|
|
120
|
+
validate,
|
|
121
|
+
scenario: scenarioRef.current,
|
|
122
|
+
};
|
|
123
|
+
if (modalConf?.footer) {
|
|
124
|
+
footer = typeof modalConf?.footer === "function" ? modalConf.footer({ ...options, options }) : modalConf?.footer;
|
|
125
|
+
} else {
|
|
126
|
+
footer = [];
|
|
127
|
+
|
|
128
|
+
if (Slots.modalFooterPre) {
|
|
129
|
+
footer.push(<Slots.modalFooterPre key="pre" options={options} />);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
footer.push(
|
|
133
|
+
<Button key="cancel" onClick={close}>
|
|
134
|
+
{modalConf.cancelText || "取 消"}
|
|
135
|
+
</Button>,
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
if (Slots.modalFooterCenter) {
|
|
139
|
+
footer.push(<Slots.modalFooterCenter key="center" options={options} />);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
footer.push(
|
|
143
|
+
<Button key="confirm" type="primary" onClick={onOk} loading={loading}>
|
|
144
|
+
{modalConf.okText || "确 定"}
|
|
145
|
+
</Button>,
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
if (Slots.modalFooterSuffix) {
|
|
149
|
+
footer.push(<Slots.modalFooterSuffix key="suffix" options={options} />);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 解决 show 函数中 formRef.current 为 undefined 的问题
|
|
155
|
+
*/
|
|
156
|
+
function didMount() {
|
|
157
|
+
props.modalFormMount && props.modalFormMount();
|
|
158
|
+
if (_formData) {
|
|
159
|
+
formRef.current?.formRender?.setValues(_formData);
|
|
160
|
+
_formData = null;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const CModal = modalMode === "drawer" ? Drawer : Modal;
|
|
165
|
+
const _modalProps = {
|
|
166
|
+
className: "form-modal",
|
|
167
|
+
wrapClassName: "form-modal",
|
|
168
|
+
title: title,
|
|
169
|
+
visible: open,
|
|
170
|
+
open: open,
|
|
171
|
+
onClose: close,
|
|
172
|
+
onCancel: close,
|
|
173
|
+
onOk: onOk,
|
|
174
|
+
footer: footer,
|
|
175
|
+
maskClosable: modalProps.maskClosable || false,
|
|
176
|
+
width: modalConf?.width ?? 720,
|
|
177
|
+
// 解决弹窗不销毁,表单远程数据没有更新的问题
|
|
178
|
+
destroyOnClose: true,
|
|
179
|
+
...modalProps,
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<CModal {..._modalProps}>
|
|
184
|
+
{FormSlot ? (
|
|
185
|
+
<FormSlot {...props} formRef={formRef} scenario={scenarioRef.current} schema={props.schema} />
|
|
186
|
+
) : (
|
|
187
|
+
<FormRender
|
|
188
|
+
{...props.formProps}
|
|
189
|
+
ref={formRef}
|
|
190
|
+
schema={props.schema}
|
|
191
|
+
schemaScope={{
|
|
192
|
+
scenario: scenarioRef.current,
|
|
193
|
+
...(props.schemaScope || {}),
|
|
194
|
+
}}
|
|
195
|
+
components={props.components}
|
|
196
|
+
></FormRender>
|
|
197
|
+
)}
|
|
198
|
+
<DidMount didMount={didMount} />
|
|
199
|
+
</CModal>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function DidMount(props) {
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
props.didMount();
|
|
206
|
+
}, []);
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export default forwardRef(FormModal);
|
|
@@ -1,123 +1,127 @@
|
|
|
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
|
-
import { use } from "react";
|
|
9
|
-
|
|
10
|
-
const scenario = "table-render";
|
|
11
|
-
|
|
12
|
-
function CardRender(props) {
|
|
13
|
-
const [schema, setSchema] = useState({});
|
|
14
|
-
|
|
15
|
-
const { config = {}, cardProps = {}, query = {}, i18n, onEdit, onDel, onSearch, getList, Slots = {} } = props;
|
|
16
|
-
const { tableDel = "删除", tableEdit = "编辑", tableDelTip = "确认删除该项?", tableDetail = "详情" } = i18n || {};
|
|
17
|
-
const { columns = 3, CardItemRender, hasEdit, hasDel, hasDelTips, hasDetail = false } = config || {};
|
|
18
|
-
|
|
19
|
-
const functionProps = { onEdit: onEdit, onDel: onDel, onSearch, getList };
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
const schemas = removeInTableFalseFields(props?.schema);
|
|
23
|
-
setSchema(schemas);
|
|
24
|
-
}, [props?.schema, props?.schema?.schema]);
|
|
25
|
-
|
|
26
|
-
const getColRender = (record, index) => {
|
|
27
|
-
const _colConf = props.config?.colConf?._$actions || {};
|
|
28
|
-
|
|
29
|
-
const slotProps = { record, index, ...functionProps };
|
|
30
|
-
|
|
31
|
-
if (Slots?.tableActionsSlot) {
|
|
32
|
-
return <Slots.tableActionsSlot {...slotProps} />;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//编辑按钮权限
|
|
36
|
-
const _hasEdit = hasEdit && typeof hasEdit === "function" ? hasEdit(record, index) : hasEdit !== false;
|
|
37
|
-
|
|
38
|
-
//详情按钮权限
|
|
39
|
-
const _hasDetail = hasDetail && typeof hasDetail === "function" ? hasDetail(record, index) : hasDetail !== false;
|
|
40
|
-
|
|
41
|
-
//删除按钮权限
|
|
42
|
-
const _hasDel = hasDel && typeof hasDel === "function" ? hasDel(record, index) : hasDel !== false;
|
|
43
|
-
|
|
44
|
-
//删除按钮提示
|
|
45
|
-
const delTips =
|
|
46
|
-
hasDelTips && typeof hasDelTips === "function" ? hasDelTips(record, index) : hasDelTips || tableDelTip;
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<div style={{ width: _colConf?.width, maxWidth: "100%" }}>
|
|
50
|
-
{Slots?.actionPrefixSlot && <Slots.actionPrefixSlot {...slotProps} />}
|
|
51
|
-
{_hasDetail ? (
|
|
52
|
-
<Button
|
|
53
|
-
type="link"
|
|
54
|
-
onClick={() => {
|
|
55
|
-
props.onDetail && props.onDetail(record, index);
|
|
56
|
-
}}
|
|
57
|
-
>
|
|
58
|
-
{tableDetail}
|
|
59
|
-
</Button>
|
|
60
|
-
) : null}
|
|
61
|
-
{_hasEdit ? (
|
|
62
|
-
<Button
|
|
63
|
-
type="link"
|
|
64
|
-
onClick={() => {
|
|
65
|
-
props.onEdit && props.onEdit(record, index);
|
|
66
|
-
}}
|
|
67
|
-
>
|
|
68
|
-
{tableEdit}
|
|
69
|
-
</Button>
|
|
70
|
-
) : null}
|
|
71
|
-
{Slots?.actionCenterSlot && <Slots.actionCenterSlot {...slotProps} />}
|
|
72
|
-
{_hasDel ? (
|
|
73
|
-
<Popconfirm
|
|
74
|
-
placement="topRight"
|
|
75
|
-
title={delTips}
|
|
76
|
-
onConfirm={() => {
|
|
77
|
-
props.onDel && props.onDel(record, index);
|
|
78
|
-
}}
|
|
79
|
-
>
|
|
80
|
-
<Button type="link" danger>
|
|
81
|
-
{tableDel}
|
|
82
|
-
</Button>
|
|
83
|
-
</Popconfirm>
|
|
84
|
-
) : null}
|
|
85
|
-
{Slots?.actionSuffixSlot && <Slots.actionSuffixSlot {...slotProps} />}
|
|
86
|
-
</div>
|
|
87
|
-
);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const ItemRender = ({ item, index }) => {
|
|
91
|
-
return CardItemRender ? (
|
|
92
|
-
<CardItemRender item={item} index={index} functionProps={functionProps} />
|
|
93
|
-
) : (
|
|
94
|
-
<DetailRender
|
|
95
|
-
config={props.config}
|
|
96
|
-
schema={schema}
|
|
97
|
-
bordered={false}
|
|
98
|
-
data={item}
|
|
99
|
-
schemaScope={{ scenario: "table-render", ...props.schemaScope }}
|
|
100
|
-
components={props.components}
|
|
101
|
-
{...cardProps}
|
|
102
|
-
/>
|
|
103
|
-
);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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 } 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
|
+
import { use } from "react";
|
|
9
|
+
|
|
10
|
+
const scenario = "table-render";
|
|
11
|
+
|
|
12
|
+
function CardRender(props) {
|
|
13
|
+
const [schema, setSchema] = useState({});
|
|
14
|
+
|
|
15
|
+
const { config = {}, cardProps = {}, query = {}, i18n, onEdit, onDel, onSearch, getList, Slots = {}, loading } = props;
|
|
16
|
+
const { tableDel = "删除", tableEdit = "编辑", tableDelTip = "确认删除该项?", tableDetail = "详情" } = i18n || {};
|
|
17
|
+
const { columns = 3, CardItemRender, hasEdit, hasDel, hasDelTips, hasDetail = false } = config || {};
|
|
18
|
+
|
|
19
|
+
const functionProps = { onEdit: onEdit, onDel: onDel, onSearch, getList };
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const schemas = removeInTableFalseFields(props?.schema);
|
|
23
|
+
setSchema(schemas);
|
|
24
|
+
}, [props?.schema, props?.schema?.schema]);
|
|
25
|
+
|
|
26
|
+
const getColRender = (record, index) => {
|
|
27
|
+
const _colConf = props.config?.colConf?._$actions || {};
|
|
28
|
+
|
|
29
|
+
const slotProps = { record, index, ...functionProps };
|
|
30
|
+
|
|
31
|
+
if (Slots?.tableActionsSlot) {
|
|
32
|
+
return <Slots.tableActionsSlot {...slotProps} />;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//编辑按钮权限
|
|
36
|
+
const _hasEdit = hasEdit && typeof hasEdit === "function" ? hasEdit(record, index) : hasEdit !== false;
|
|
37
|
+
|
|
38
|
+
//详情按钮权限
|
|
39
|
+
const _hasDetail = hasDetail && typeof hasDetail === "function" ? hasDetail(record, index) : hasDetail !== false;
|
|
40
|
+
|
|
41
|
+
//删除按钮权限
|
|
42
|
+
const _hasDel = hasDel && typeof hasDel === "function" ? hasDel(record, index) : hasDel !== false;
|
|
43
|
+
|
|
44
|
+
//删除按钮提示
|
|
45
|
+
const delTips =
|
|
46
|
+
hasDelTips && typeof hasDelTips === "function" ? hasDelTips(record, index) : hasDelTips || tableDelTip;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div style={{ width: _colConf?.width, maxWidth: "100%" }}>
|
|
50
|
+
{Slots?.actionPrefixSlot && <Slots.actionPrefixSlot {...slotProps} />}
|
|
51
|
+
{_hasDetail ? (
|
|
52
|
+
<Button
|
|
53
|
+
type="link"
|
|
54
|
+
onClick={() => {
|
|
55
|
+
props.onDetail && props.onDetail(record, index);
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
58
|
+
{tableDetail}
|
|
59
|
+
</Button>
|
|
60
|
+
) : null}
|
|
61
|
+
{_hasEdit ? (
|
|
62
|
+
<Button
|
|
63
|
+
type="link"
|
|
64
|
+
onClick={() => {
|
|
65
|
+
props.onEdit && props.onEdit(record, index);
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
68
|
+
{tableEdit}
|
|
69
|
+
</Button>
|
|
70
|
+
) : null}
|
|
71
|
+
{Slots?.actionCenterSlot && <Slots.actionCenterSlot {...slotProps} />}
|
|
72
|
+
{_hasDel ? (
|
|
73
|
+
<Popconfirm
|
|
74
|
+
placement="topRight"
|
|
75
|
+
title={delTips}
|
|
76
|
+
onConfirm={() => {
|
|
77
|
+
props.onDel && props.onDel(record, index);
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
<Button type="link" danger>
|
|
81
|
+
{tableDel}
|
|
82
|
+
</Button>
|
|
83
|
+
</Popconfirm>
|
|
84
|
+
) : null}
|
|
85
|
+
{Slots?.actionSuffixSlot && <Slots.actionSuffixSlot {...slotProps} />}
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const ItemRender = ({ item, index }) => {
|
|
91
|
+
return CardItemRender ? (
|
|
92
|
+
<CardItemRender item={item} index={index} functionProps={functionProps} />
|
|
93
|
+
) : (
|
|
94
|
+
<DetailRender
|
|
95
|
+
config={props.config}
|
|
96
|
+
schema={schema}
|
|
97
|
+
bordered={false}
|
|
98
|
+
data={item}
|
|
99
|
+
schemaScope={{ scenario: "table-render", ...props.schemaScope }}
|
|
100
|
+
components={props.components}
|
|
101
|
+
{...cardProps}
|
|
102
|
+
/>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<Spin spinning={loading}>
|
|
108
|
+
<div className="card-render-wrap" style={{ gridTemplateColumns: `repeat(${columns}, 1fr` }}>
|
|
109
|
+
{props.list?.map((item, index) => {
|
|
110
|
+
return (
|
|
111
|
+
<div key={item["id"]} className="item-render-card">
|
|
112
|
+
{props.hasAction !== false ? (
|
|
113
|
+
<div className="item-render-card-title">{getColRender(item, index)}</div>
|
|
114
|
+
) : null}
|
|
115
|
+
<div className="item-render-card-content">
|
|
116
|
+
<ItemRender item={item} index={index} />
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
})}
|
|
121
|
+
</div>
|
|
122
|
+
</Spin>
|
|
123
|
+
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export default CardRender;
|