@hzab/list-render 1.9.3 → 1.9.4-beta
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/package.json +1 -1
- package/src/list-render.jsx +7 -1
- package/src/table-render/index.jsx +62 -3
- package/src/table-render/index.less +24 -0
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,
|
|
@@ -324,10 +325,14 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
324
325
|
const modalProps = { ...props.dialogProps, ...props.modalProps };
|
|
325
326
|
const modalFormMount = props.dialogFormMount ?? props.modalFormMount;
|
|
326
327
|
|
|
328
|
+
const handleSetShowSearch = () => {
|
|
329
|
+
setShowSearch(!showSearch);
|
|
330
|
+
};
|
|
331
|
+
|
|
327
332
|
return (
|
|
328
333
|
<div className={`list-render ${props.className}`}>
|
|
329
334
|
<div className={`list-header ${props.verticalHeader ? "vertical-header" : ""}`}>
|
|
330
|
-
{props.hasQuery !== false ? (
|
|
335
|
+
{props.hasQuery !== false && showSearch ? (
|
|
331
336
|
<QueryRender
|
|
332
337
|
ref={queryRef}
|
|
333
338
|
schema={schema}
|
|
@@ -378,6 +383,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
378
383
|
onDetail={onDetail}
|
|
379
384
|
onSearch={onSearch}
|
|
380
385
|
getList={getList}
|
|
386
|
+
setShowSearch={handleSetShowSearch}
|
|
381
387
|
loading={listLoading}
|
|
382
388
|
tableProps={props.tableProps}
|
|
383
389
|
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,15 @@ 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 || {};
|
|
23
29
|
const [columns, setColumns] = useState([]);
|
|
30
|
+
const [columnList, setColumnList] = useState([]);
|
|
24
31
|
|
|
25
32
|
const formilyRef = useRef({
|
|
26
33
|
fields: {},
|
|
@@ -238,6 +245,8 @@ function TableRender(props) {
|
|
|
238
245
|
}
|
|
239
246
|
|
|
240
247
|
setColumns(columns);
|
|
248
|
+
setColumnList(columns);
|
|
249
|
+
console.log("columns", columns);
|
|
241
250
|
}, [props.schema, props.config]);
|
|
242
251
|
|
|
243
252
|
// 解决 FormilyField 中无相关参数报错的问题。自定义参数都从这里传入
|
|
@@ -245,8 +254,58 @@ function TableRender(props) {
|
|
|
245
254
|
scenario: scenario,
|
|
246
255
|
};
|
|
247
256
|
|
|
257
|
+
const onChange = (e, col) => {
|
|
258
|
+
console.log(`checked = ${e.target.checked}`);
|
|
259
|
+
|
|
260
|
+
if (e.target.checked) {
|
|
261
|
+
const list = [...columns, col];
|
|
262
|
+
// 创建映射表提高查找效率
|
|
263
|
+
const columnIndexMap = new Map(columnList.map((item, index) => [item.key, index]));
|
|
264
|
+
setColumns(list.sort((a, b) => columnIndexMap.get(a.key) - columnIndexMap.get(b.key)));
|
|
265
|
+
} else {
|
|
266
|
+
setColumns(columns.filter((item) => item.key !== col.key));
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
248
270
|
return (
|
|
249
271
|
<div className="table-render-wrap">
|
|
272
|
+
{isShowTableFilter ? (
|
|
273
|
+
<div className="table-render-wrap-header">
|
|
274
|
+
<FilterOutlined
|
|
275
|
+
className="table-filter-icon"
|
|
276
|
+
onClick={() => {
|
|
277
|
+
props.setShowSearch && props.setShowSearch();
|
|
278
|
+
}}
|
|
279
|
+
/>
|
|
280
|
+
<Popover
|
|
281
|
+
placement="bottomRight"
|
|
282
|
+
content={
|
|
283
|
+
<div className="table-popover-content">
|
|
284
|
+
{columnList.map((col) => {
|
|
285
|
+
if (col.key === "_$actions") {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
return (
|
|
289
|
+
<Checkbox
|
|
290
|
+
key={col.key}
|
|
291
|
+
checked={columns.findIndex((item) => item.key === col.key) !== -1}
|
|
292
|
+
onChange={(e) => onChange(e, col)}
|
|
293
|
+
>
|
|
294
|
+
{col.title}
|
|
295
|
+
</Checkbox>
|
|
296
|
+
);
|
|
297
|
+
})}
|
|
298
|
+
</div>
|
|
299
|
+
}
|
|
300
|
+
trigger="click"
|
|
301
|
+
>
|
|
302
|
+
<div className="table-filter">
|
|
303
|
+
<SettingOutlined className="table-filter-icon" />
|
|
304
|
+
显示列
|
|
305
|
+
</div>
|
|
306
|
+
</Popover>
|
|
307
|
+
</div>
|
|
308
|
+
) : null}
|
|
250
309
|
<Table
|
|
251
310
|
className="table-render"
|
|
252
311
|
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-left: 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;
|
|
40
|
+
}
|
|
41
|
+
}
|