@hzab/list-render 1.9.5 → 1.9.6
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 +5 -0
- package/package.json +1 -1
- package/src/list-render.jsx +8 -1
- package/src/table-render/index.jsx +66 -3
- package/src/table-render/index.less +24 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/list-render.jsx
CHANGED
|
@@ -50,6 +50,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
50
50
|
const paginationQueryRef = useRef({ pageNum: 1, pageSize: 10 });
|
|
51
51
|
const useFormData = _useFormData ?? dialogConf.useFormData ?? modalConf?.useFormData;
|
|
52
52
|
const getListSourceRef = useRef();
|
|
53
|
+
const [showSearch, setShowSearch] = useState(true);
|
|
53
54
|
|
|
54
55
|
useImperativeHandle(parentRef, () => ({
|
|
55
56
|
getList,
|
|
@@ -71,6 +72,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
71
72
|
model.query = {};
|
|
72
73
|
} else {
|
|
73
74
|
modelQueryRef.current = model?.query;
|
|
75
|
+
paginationQueryRef.current = model?.query;
|
|
74
76
|
}
|
|
75
77
|
model.query.pageNum = 1;
|
|
76
78
|
}
|
|
@@ -324,10 +326,14 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
324
326
|
const modalProps = { ...props.dialogProps, ...props.modalProps };
|
|
325
327
|
const modalFormMount = props.dialogFormMount ?? props.modalFormMount;
|
|
326
328
|
|
|
329
|
+
const handleSetShowSearch = () => {
|
|
330
|
+
setShowSearch(!showSearch);
|
|
331
|
+
};
|
|
332
|
+
|
|
327
333
|
return (
|
|
328
334
|
<div className={`list-render ${props.className}`}>
|
|
329
335
|
<div className={`list-header ${props.verticalHeader ? "vertical-header" : ""}`}>
|
|
330
|
-
{props.hasQuery !== false ? (
|
|
336
|
+
{props.hasQuery !== false && showSearch ? (
|
|
331
337
|
<QueryRender
|
|
332
338
|
ref={queryRef}
|
|
333
339
|
schema={schema}
|
|
@@ -378,6 +384,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
378
384
|
onDetail={onDetail}
|
|
379
385
|
onSearch={onSearch}
|
|
380
386
|
getList={getList}
|
|
387
|
+
setShowSearch={handleSetShowSearch}
|
|
381
388
|
loading={listLoading}
|
|
382
389
|
tableProps={props.tableProps}
|
|
383
390
|
getFieldListOpt={props.getFieldListOpt}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState, useMemo, useCallback, useRef } from "react";
|
|
2
|
-
import { Table, Button, Popconfirm, Tooltip } from "antd";
|
|
2
|
+
import { Table, Button, Popconfirm, Tooltip, Checkbox, Popover } from "antd";
|
|
3
3
|
import { Schema } from "@formily/json-schema";
|
|
4
|
-
import { QuestionCircleOutlined } from "@ant-design/icons";
|
|
4
|
+
import { QuestionCircleOutlined, FilterOutlined, SettingOutlined } from "@ant-design/icons";
|
|
5
5
|
import _ from "lodash";
|
|
6
6
|
|
|
7
7
|
import { FormilyField } from "../components/Formily/FormilyField";
|
|
@@ -19,8 +19,16 @@ const scenario = "table-render";
|
|
|
19
19
|
function TableRender(props) {
|
|
20
20
|
const { config = {}, query = {}, i18n } = props;
|
|
21
21
|
const { tableDel = "删除", tableEdit = "编辑", tableDelTip = "确认删除该项?", tableDetail = "详情" } = i18n || {};
|
|
22
|
-
const {
|
|
22
|
+
const {
|
|
23
|
+
orderColType,
|
|
24
|
+
orderColWidth,
|
|
25
|
+
tableEmptyValue,
|
|
26
|
+
isShowTableFilter = false,
|
|
27
|
+
isTableSortXIdex = false,
|
|
28
|
+
} = config || {};
|
|
29
|
+
|
|
23
30
|
const [columns, setColumns] = useState([]);
|
|
31
|
+
const [columnList, setColumnList] = useState([]);
|
|
24
32
|
|
|
25
33
|
const formilyRef = useRef({
|
|
26
34
|
fields: {},
|
|
@@ -238,6 +246,8 @@ function TableRender(props) {
|
|
|
238
246
|
}
|
|
239
247
|
|
|
240
248
|
setColumns(columns);
|
|
249
|
+
setColumnList(columns);
|
|
250
|
+
console.log("columns", columns);
|
|
241
251
|
}, [props.schema, props.config]);
|
|
242
252
|
|
|
243
253
|
// 解决 FormilyField 中无相关参数报错的问题。自定义参数都从这里传入
|
|
@@ -245,8 +255,61 @@ function TableRender(props) {
|
|
|
245
255
|
scenario: scenario,
|
|
246
256
|
};
|
|
247
257
|
|
|
258
|
+
const onChange = (e, col) => {
|
|
259
|
+
console.log(`checked = ${e.target.checked}`);
|
|
260
|
+
|
|
261
|
+
if (e.target.checked) {
|
|
262
|
+
const list = [...columns, col];
|
|
263
|
+
// 创建映射表提高查找效率
|
|
264
|
+
const columnIndexMap = new Map(columnList.map((item, index) => [item.key, index]));
|
|
265
|
+
setColumns(list.sort((a, b) => columnIndexMap.get(a.key) - columnIndexMap.get(b.key)));
|
|
266
|
+
} else {
|
|
267
|
+
setColumns(columns.filter((item) => item.key !== col.key));
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
248
271
|
return (
|
|
249
272
|
<div className="table-render-wrap">
|
|
273
|
+
{isShowTableFilter ? (
|
|
274
|
+
<div className="table-render-wrap-header">
|
|
275
|
+
<div
|
|
276
|
+
className="table-filter"
|
|
277
|
+
onClick={() => {
|
|
278
|
+
props.setShowSearch && props.setShowSearch();
|
|
279
|
+
}}
|
|
280
|
+
>
|
|
281
|
+
<FilterOutlined className="table-filter-icon" />
|
|
282
|
+
显示过滤项
|
|
283
|
+
</div>
|
|
284
|
+
<Popover
|
|
285
|
+
placement="bottomRight"
|
|
286
|
+
content={
|
|
287
|
+
<div className="table-popover-content">
|
|
288
|
+
{columnList.map((col) => {
|
|
289
|
+
if (col.key === "_$actions") {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
return (
|
|
293
|
+
<Checkbox
|
|
294
|
+
key={col.key}
|
|
295
|
+
checked={columns.findIndex((item) => item.key === col.key) !== -1}
|
|
296
|
+
onChange={(e) => onChange(e, col)}
|
|
297
|
+
>
|
|
298
|
+
{col.title}
|
|
299
|
+
</Checkbox>
|
|
300
|
+
);
|
|
301
|
+
})}
|
|
302
|
+
</div>
|
|
303
|
+
}
|
|
304
|
+
trigger="click"
|
|
305
|
+
>
|
|
306
|
+
<div className="table-filter">
|
|
307
|
+
<SettingOutlined className="table-filter-icon" />
|
|
308
|
+
显示列
|
|
309
|
+
</div>
|
|
310
|
+
</Popover>
|
|
311
|
+
</div>
|
|
312
|
+
) : null}
|
|
250
313
|
<Table
|
|
251
314
|
className="table-render"
|
|
252
315
|
rowKey={props.idKey || "id"}
|
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
.table-render-wrap {
|
|
2
|
+
.table-render-wrap-header {
|
|
3
|
+
padding: 0 12px;
|
|
4
|
+
display: flex;
|
|
5
|
+
justify-content: flex-end;
|
|
6
|
+
align-items: center;
|
|
7
|
+
margin-bottom: 12px;
|
|
8
|
+
.table-filter {
|
|
9
|
+
font-size: 16px;
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
.table-filter-icon {
|
|
12
|
+
margin: 0 4px 0 10px;
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
2
17
|
.inline-block-max-w {
|
|
3
18
|
display: inline-block;
|
|
4
19
|
max-width: 100%;
|
|
@@ -15,3 +30,12 @@
|
|
|
15
30
|
text-overflow: ellipsis;
|
|
16
31
|
}
|
|
17
32
|
}
|
|
33
|
+
.table-popover-content {
|
|
34
|
+
max-width: 400px;
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
.ant-checkbox-wrapper {
|
|
38
|
+
margin-bottom: 8px;
|
|
39
|
+
margin-left: 0 !important;
|
|
40
|
+
}
|
|
41
|
+
}
|