@hzab/list-render 1.9.5 → 1.9.7

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 CHANGED
@@ -1,3 +1,12 @@
1
+ # @hzab/list-render@1.9.7
2
+
3
+ fix: 修复 分页配置时数据覆盖问题
4
+
5
+ # @hzab/list-render@1.9.6
6
+
7
+ feat: 新增列筛选,筛选项显隐
8
+ fix: 修复 分页配置
9
+
1
10
  # @hzab/list-render@1.9.5
2
11
 
3
12
  fix: 修复 datePicker 传入 showTime 为 true 时显示时分秒
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/list-render",
3
- "version": "1.9.5",
3
+ "version": "1.9.7",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -41,8 +41,6 @@ export const PrefixNode = (props) => {
41
41
  return showVal?.map((it, i) => {
42
42
  const option = getFieldOptItByVal(it, _field) || {};
43
43
  const PreNode = option.PrefixNode;
44
- console.log(it, option);
45
-
46
44
  return (
47
45
  <div key={it + "" + i} className="table-cell-prefix-box">
48
46
  {PreNode ? (
@@ -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,10 @@ const ListRender = forwardRef(function (props, parentRef) {
71
72
  model.query = {};
72
73
  } else {
73
74
  modelQueryRef.current = model?.query;
75
+ paginationQueryRef.current = {
76
+ pageNum: model?.query?.pageNum ?? paginationQueryRef.current?.pageNum,
77
+ pageSize: model?.query?.pageSize ?? paginationQueryRef.current?.pageSize,
78
+ };
74
79
  }
75
80
  model.query.pageNum = 1;
76
81
  }
@@ -324,10 +329,14 @@ const ListRender = forwardRef(function (props, parentRef) {
324
329
  const modalProps = { ...props.dialogProps, ...props.modalProps };
325
330
  const modalFormMount = props.dialogFormMount ?? props.modalFormMount;
326
331
 
332
+ const handleSetShowSearch = () => {
333
+ setShowSearch(!showSearch);
334
+ };
335
+
327
336
  return (
328
337
  <div className={`list-render ${props.className}`}>
329
338
  <div className={`list-header ${props.verticalHeader ? "vertical-header" : ""}`}>
330
- {props.hasQuery !== false ? (
339
+ {props.hasQuery !== false && showSearch ? (
331
340
  <QueryRender
332
341
  ref={queryRef}
333
342
  schema={schema}
@@ -378,6 +387,7 @@ const ListRender = forwardRef(function (props, parentRef) {
378
387
  onDetail={onDetail}
379
388
  onSearch={onSearch}
380
389
  getList={getList}
390
+ setShowSearch={handleSetShowSearch}
381
391
  loading={listLoading}
382
392
  tableProps={props.tableProps}
383
393
  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 { orderColType, orderColWidth, tableEmptyValue, isTableSortXIdex = false } = config || {};
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: {},
@@ -184,7 +192,6 @@ function TableRender(props) {
184
192
  //详情按钮权限
185
193
  const _hasDetail =
186
194
  hasDetail && typeof hasDetail === "function" ? hasDetail(record, index) : hasDetail !== false;
187
- console.log("_hasDetail", hasDetail, _hasDetail);
188
195
 
189
196
  //删除按钮权限
190
197
  const _hasDel = hasDel && typeof hasDel === "function" ? hasDel(record, index) : hasDel !== false;
@@ -238,6 +245,7 @@ function TableRender(props) {
238
245
  }
239
246
 
240
247
  setColumns(columns);
248
+ setColumnList(columns);
241
249
  }, [props.schema, props.config]);
242
250
 
243
251
  // 解决 FormilyField 中无相关参数报错的问题。自定义参数都从这里传入
@@ -245,8 +253,59 @@ function TableRender(props) {
245
253
  scenario: scenario,
246
254
  };
247
255
 
256
+ const onChange = (e, col) => {
257
+ if (e.target.checked) {
258
+ const list = [...columns, col];
259
+ // 创建映射表提高查找效率
260
+ const columnIndexMap = new Map(columnList.map((item, index) => [item.key, index]));
261
+ setColumns(list.sort((a, b) => columnIndexMap.get(a.key) - columnIndexMap.get(b.key)));
262
+ } else {
263
+ setColumns(columns.filter((item) => item.key !== col.key));
264
+ }
265
+ };
266
+
248
267
  return (
249
268
  <div className="table-render-wrap">
269
+ {isShowTableFilter ? (
270
+ <div className="table-render-wrap-header">
271
+ <div
272
+ className="table-filter"
273
+ onClick={() => {
274
+ props.setShowSearch && props.setShowSearch();
275
+ }}
276
+ >
277
+ <FilterOutlined className="table-filter-icon" />
278
+ 显示过滤项
279
+ </div>
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: 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
+ }