@hzab/list-render 1.9.11 → 1.9.12-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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # @hzab/list-render@1.9.12
2
+
3
+ fix: 修复 model query 被污染 2
4
+
1
5
  # @hzab/list-render@1.9.11
2
6
 
3
7
  fix: 修复 model query 被污染 2
package/README.md CHANGED
@@ -117,6 +117,8 @@ const listDM = useMemo(
117
117
  | orderColWidth | string/number | | - | 序号列 width 的参数 |
118
118
  | tableEmptyValue | string/number | | undefined | table 列表空值展示数 |
119
119
  | isTableSortXIdex | Boolean | | undefined | table 列表列排序是否按照 x-index 排序 |
120
+ | isDargTable | Boolean | | undefined | 是否开启表格拖拽排序 |
121
+ | dargEndBack | function | | undefined | 拖拽结束后返回表格数据 |
120
122
 
121
123
  ##### tableConf.colConf[xxx]
122
124
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/list-render",
3
- "version": "1.9.11",
3
+ "version": "1.9.12-beta",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -55,5 +55,9 @@
55
55
  },
56
56
  "directories": {
57
57
  "lib": "lib"
58
+ },
59
+ "dependencies": {
60
+ "array-move": "^4.0.0",
61
+ "react-sortable-hoc": "^2.0.0"
58
62
  }
59
63
  }
@@ -427,6 +427,7 @@ const ListRender = forwardRef(function (props, parentRef) {
427
427
  Slots={props.Slots}
428
428
  onEdit={onEdit}
429
429
  onDel={onDel}
430
+ setList={setList}
430
431
  onDetail={onDetail}
431
432
  onSearch={onSearch}
432
433
  getList={getList}
@@ -1,6 +1,8 @@
1
1
  import { useEffect, useState, useMemo, useCallback, useRef } from "react";
2
2
  import { Table, Button, Popconfirm, Tooltip, Checkbox, Popover } from "antd";
3
- import { QuestionCircleOutlined, FilterOutlined, SettingOutlined } from "@ant-design/icons";
3
+ import { QuestionCircleOutlined, FilterOutlined, SettingOutlined, MenuOutlined } from "@ant-design/icons";
4
+ import { SortableContainer, SortableElement, SortableHandle } from "react-sortable-hoc";
5
+ import { arrayMoveImmutable } from "array-move";
4
6
  import _ from "lodash";
5
7
 
6
8
  import EnumRender from "@hzab/formily-result-utils/src/components/EnumRender";
@@ -16,9 +18,11 @@ import "./index.less";
16
18
  const scenario = "table-render";
17
19
 
18
20
  function TableRender(props) {
19
- const { config = {}, query = {}, i18n } = props;
21
+ const { config = {}, query = {}, i18n, setList } = props;
20
22
  const { tableDel = "删除", tableEdit = "编辑", tableDelTip = "确认删除该项?", tableDetail = "详情" } = i18n || {};
21
23
  const {
24
+ isDargTable,
25
+ dargEndBack,
22
26
  orderColType,
23
27
  orderColWidth,
24
28
  tableEmptyValue,
@@ -28,6 +32,28 @@ function TableRender(props) {
28
32
 
29
33
  const [columns, setColumns] = useState([]);
30
34
  const [columnList, setColumnList] = useState([]);
35
+ const DragHandle = SortableHandle(() => <MenuOutlined style={{ cursor: "grab", color: "#999" }} />);
36
+
37
+ const SortableItem = SortableElement((props) => <tr {...props} />);
38
+ const SortableBody = SortableContainer((props) => <tbody {...props} />);
39
+
40
+ const onSortEnd = ({ oldIndex, newIndex }) => {
41
+ if (oldIndex !== newIndex) {
42
+ const newData = arrayMoveImmutable(props.list.slice(), oldIndex, newIndex).filter((el) => !!el);
43
+ setList([...newData]);
44
+ dargEndBack && dargEndBack(newData, query);
45
+ }
46
+ };
47
+
48
+ const DraggableContainer = (props) => (
49
+ <SortableBody useDragHandle disableAutoscroll helperClass="row-dragging" onSortEnd={onSortEnd} {...props} />
50
+ );
51
+
52
+ const DraggableBodyRow = ({ className, style, ...restProps }) => {
53
+ // function findIndex base on Table rowKey props and should always be a right array index
54
+ const index = props.list.findIndex((x) => x[props.idKey || "id"] === restProps["data-row-key"]);
55
+ return <SortableItem index={index} {...restProps} />;
56
+ };
31
57
 
32
58
  const formilyRef = useRef({
33
59
  fields: {},
@@ -240,6 +266,14 @@ function TableRender(props) {
240
266
  });
241
267
  }
242
268
 
269
+ if (isDargTable) {
270
+ columns.unshift({
271
+ title: "",
272
+ dataIndex: "sort",
273
+ width: 30,
274
+ render: () => <DragHandle />,
275
+ });
276
+ }
243
277
  setColumns(columns);
244
278
  setColumnList(columns);
245
279
  }, [props.schema, props.config]);
@@ -314,6 +348,12 @@ function TableRender(props) {
314
348
  loading={props.loading}
315
349
  onRow={config?.onRow}
316
350
  {...props.tableProps}
351
+ components={{
352
+ body: {
353
+ wrapper: DraggableContainer,
354
+ row: DraggableBodyRow,
355
+ },
356
+ }}
317
357
  />
318
358
  <FormilyField
319
359
  schema={props.schema}
@@ -5,37 +5,62 @@
5
5
  justify-content: flex-end;
6
6
  align-items: center;
7
7
  margin-bottom: 12px;
8
+
8
9
  .table-filter {
9
10
  font-size: 16px;
10
11
  cursor: pointer;
12
+
11
13
  .table-filter-icon {
12
14
  margin: 0 4px 0 10px;
13
15
  cursor: pointer;
14
16
  }
15
17
  }
16
18
  }
19
+
17
20
  .inline-block-max-w {
18
21
  display: inline-block;
19
22
  max-width: 100%;
20
23
  }
24
+
21
25
  .col-title-tooltip-icon {
22
26
  margin-left: 8px;
23
27
  }
28
+
24
29
  .table-render {
25
30
  border-top: 1px solid #f0f0f0;
26
31
  }
32
+
27
33
  .table-cell-ellipsis {
28
34
  overflow: hidden;
29
35
  white-space: nowrap;
30
36
  text-overflow: ellipsis;
31
37
  }
38
+
32
39
  }
40
+
41
+ .row-dragging {
42
+ background: #FFF;
43
+ border: 1px solid #ccc;
44
+ display: flex;
45
+ justify-content: space-between;
46
+ align-items: center;
47
+ }
48
+
49
+ .row-dragging td {
50
+ padding: 16px;
51
+ }
52
+
53
+ .row-dragging .drag-visible {
54
+ visibility: visible;
55
+ }
56
+
33
57
  .table-popover-content {
34
58
  max-width: 400px;
35
59
  display: flex;
36
60
  flex-direction: column;
61
+
37
62
  .ant-checkbox-wrapper {
38
63
  margin-bottom: 8px;
39
64
  margin-left: 0 !important;
40
65
  }
41
- }
66
+ }