@hzab/list-render 1.12.3 → 1.12.4

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,6 +1,10 @@
1
+ # @hzab/list-render@1.12.4
2
+
3
+ feat: 新增 filterTag 配置
4
+
1
5
  # @hzab/list-render@1.12.3
2
6
 
3
- fix: 操作栏整体div增加样式className
7
+ fix: 操作栏整体 div 增加样式 className
4
8
 
5
9
  # @hzab/list-render@1.12.2
6
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/list-render",
3
- "version": "1.12.3",
3
+ "version": "1.12.4",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -44,9 +44,7 @@
44
44
  "react": "^17.0.2",
45
45
  "react-dom": "^17.0.2",
46
46
  "react-router-dom": "^6.8.1",
47
- "typescript": "^4.9.4",
48
- "@hzab/edit-table": "^0.0.1",
49
- "@silevis/reactgrid": "^4.1.17"
47
+ "typescript": "^4.9.4"
50
48
  },
51
49
  "peerDependencies": {
52
50
  "@formily/core": "2.3.1",
@@ -62,7 +60,8 @@
62
60
  "c-formily-antd": "2.3.1",
63
61
  "lodash": ">=4.17.21",
64
62
  "react": ">=16.8.0",
65
- "react-dom": ">=16.8.0"
63
+ "react-dom": ">=16.8.0",
64
+ "@hzab/edit-table": ">=0.1.2"
66
65
  },
67
66
  "directories": {
68
67
  "lib": "lib"
@@ -0,0 +1,15 @@
1
+ .has-filter {
2
+ margin-bottom: 16px;
3
+
4
+ .has-filter-tag {
5
+ background: rgba(64, 62, 245, 0.2);
6
+ border-radius: 4px 4px 4px 4px;
7
+ color: #403EF5;
8
+ margin-bottom: 8px;
9
+
10
+ .anticon-close {
11
+ color: #403EF5;
12
+
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,60 @@
1
+ import { useEffect, useState } from "react";
2
+ import "./index.less";
3
+ import { Tag } from "antd";
4
+ import { getVal } from "@hzab/list-render/src/common/utils";
5
+ function hasValue(val) {
6
+ return val !== null && val !== undefined;
7
+ }
8
+ const FilterTag = (props: any) => {
9
+ const { searchQuery, schema, queryRef, onSearch } = props;
10
+ const [worldList, setWorldList] = useState<any>([]);
11
+ useEffect(() => {
12
+ if (queryRef) {
13
+ const list = [];
14
+ const fieldSchemas = queryRef.current?.formRef?.current?.formRender?.fields;
15
+ for (let key in schema?.schema?.properties) {
16
+ const field = schema?.schema?.properties[key];
17
+ if (hasValue(searchQuery[key])) {
18
+ let val = getVal({ ...field, ...fieldSchemas[field?.name] }, searchQuery, {
19
+ fieldSchema: fieldSchemas?.[field?.name],
20
+ });
21
+
22
+ list.push({
23
+ label: field?.title,
24
+ value: val,
25
+ filed: key,
26
+ filedValue: searchQuery[key],
27
+ });
28
+ }
29
+ }
30
+ setWorldList(list?.filter((el) => el?.value));
31
+ }
32
+ }, [searchQuery, schema, queryRef]);
33
+ const onClose = (e, item) => {
34
+ e.preventDefault();
35
+ queryRef.current?.formRef?.current?.formRender.setValues({
36
+ [item?.filed]: null,
37
+ });
38
+ onSearch && onSearch(queryRef.current?.formRef?.current?.formRender?.values);
39
+ setWorldList((pre) => pre?.filter((el) => el?.filed != item?.filed));
40
+ };
41
+
42
+ return (
43
+ <div className="has-filter">
44
+ {worldList?.map((item) => {
45
+ return (
46
+ <Tag
47
+ className="has-filter-tag"
48
+ closable
49
+ onClose={(e) => {
50
+ onClose(e, item);
51
+ }}
52
+ >
53
+ {item?.label}:{item?.value}
54
+ </Tag>
55
+ );
56
+ })}
57
+ </div>
58
+ );
59
+ };
60
+ export default FilterTag;
@@ -13,7 +13,7 @@ import TableRender from "./table-render";
13
13
  import CardRender from "./card-render";
14
14
  import FormModal from "./FormModal";
15
15
  import DetailModal from "./DetailModal";
16
-
16
+ import FilterTag from "./FilterTag"
17
17
  import { objToFormData } from "./common/utils";
18
18
  import {
19
19
  setURLObjectQueryParam,
@@ -60,6 +60,7 @@ const ListRender = forwardRef(function (props, parentRef) {
60
60
  * 自定义设置url query对象参数的key
61
61
  * */
62
62
  appendUrlQueryKey = URL_PARAM_NAME,
63
+ hasFilterTag = false
63
64
  } = props;
64
65
  const { isAllSelect = false, isAllSelectKey = "isAllSelect" } = props.paginationConf || {};
65
66
 
@@ -83,6 +84,7 @@ const ListRender = forwardRef(function (props, parentRef) {
83
84
  const getListSourceRef = useRef();
84
85
  const [showSearch, setShowSearch] = useState(true);
85
86
  const tableRef = useRef({});
87
+ const [searchQuery, setSearchQuery] = useState({})
86
88
 
87
89
  useImperativeHandle(parentRef, () => ({
88
90
  getList,
@@ -95,6 +97,7 @@ const ListRender = forwardRef(function (props, parentRef) {
95
97
  onCreate,
96
98
  onEdit,
97
99
  onDel,
100
+ tableRef
98
101
  }));
99
102
 
100
103
  const { schema = {}, config = {}, model = {}, msgConf = {}, filters } = props;
@@ -263,6 +266,7 @@ const ListRender = forwardRef(function (props, parentRef) {
263
266
  * @returns
264
267
  */
265
268
  function onQueryFormSubmit(query, isReset) {
269
+ setSearchQuery(query)
266
270
  // 是否开启 url query
267
271
  if (appendUrlQuery) {
268
272
  if (isReset) {
@@ -492,6 +496,14 @@ const ListRender = forwardRef(function (props, parentRef) {
492
496
  )}
493
497
  </div>
494
498
  </div>
499
+ {
500
+ hasFilterTag && <FilterTag
501
+ searchQuery={searchQuery}
502
+ schema={schema}
503
+ queryRef={queryRef}
504
+ onSearch={onSearch}
505
+ ></FilterTag>
506
+ }
495
507
  {Slots.HeaderOthersSuffix && <Slots.HeaderOthersSuffix onSearch={onSearch} getList={getList} />}
496
508
  {layout === "card" ? (
497
509
  <CardRender
@@ -10,6 +10,7 @@ import { createForm, onFormValuesChange, onFieldValueChange } from "@formily/cor
10
10
 
11
11
  import EnumRender from "@hzab/formily-result-utils/src/components/EnumRender";
12
12
  import { SHOW_MODE_TYPES } from "@hzab/formily-result-utils/src/common/constant";
13
+ import CellEditTable from "@hzab/edit-table"
13
14
  import { FormilyField } from "../components/Formily/FormilyField";
14
15
  // getColRender 使用 observer 包裹一层 column 的 render 函数,解决数据无法响应的问题
15
16
  import { getColRender } from "../common/formily-utils";
@@ -17,7 +18,6 @@ import { getVal, getFieldList } from "../common/utils";
17
18
  import { handleReactions } from "../common/handleReactions";
18
19
 
19
20
  import { useEditTable, EditableCell } from "../components/Formily/FormilyEditTable";
20
- import CellEditTable from "@hzab/edit-table"
21
21
  import "./index.less";
22
22
 
23
23
  const scenario = "table-render";
@@ -38,8 +38,11 @@ const TableRender = forwardRef(function (props, tableRef) {
38
38
  } = config || {};
39
39
  const { editMode = "modal" } = topProps || {};
40
40
  const isEditTable = editMode !== "modal";
41
+ const cellEditTableRef = useRef()
41
42
  useImperativeHandle(tableRef, () => ({
42
43
  onEditByTable,
44
+ cellEditTableRef,
45
+ columns
43
46
  }));
44
47
 
45
48
  const [columns, setColumns] = useState([]);
@@ -192,11 +195,13 @@ const TableRender = forwardRef(function (props, tableRef) {
192
195
  </span>
193
196
  );
194
197
  }
198
+
195
199
  const childSelectList = fieldSchemas?.[field?.name]?.dataSource?.map((el) => ({
196
200
  ...el,
197
201
  label: el?.[field?.["x-component-props"]?.["fieldNames"]?.["label"]] || el?.label,
198
202
  value: el?.[field?.["x-component-props"]?.["fieldNames"]?.["value"]] || el?.value,
199
203
  }))
204
+
200
205
  return {
201
206
  getField: () => field,
202
207
  editable: true,
@@ -214,6 +219,7 @@ const TableRender = forwardRef(function (props, tableRef) {
214
219
  cellProps: field.cellProps,
215
220
  children: handleChildColumns(field?.children),
216
221
  render: getColRender(colRender),
222
+ required: field?.required
217
223
  }
218
224
 
219
225
  })?.filter((el) => (el))
@@ -440,6 +446,7 @@ const TableRender = forwardRef(function (props, tableRef) {
440
446
  ) : null}
441
447
  {
442
448
  isCellEditTable ? <CellEditTable
449
+ ref={cellEditTableRef}
443
450
  {...tableProps}
444
451
  {...cellEditTableProps}
445
452
  {...props}