@hzab/list-render 1.9.4 → 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 CHANGED
@@ -1,3 +1,13 @@
1
+ # @hzab/list-render@1.9.6
2
+
3
+ feat: 新增列筛选,筛选项显隐
4
+ fix: 修复 分页配置
5
+
6
+ # @hzab/list-render@1.9.5
7
+
8
+ fix: 修复 datePicker 传入 showTime 为 true 时显示时分秒
9
+ fix: 修复 QueryRender 内部组件 props 的执行函数
10
+
1
11
  # @hzab/list-render@1.9.4
2
12
 
3
13
  fix: 修复分页数据来源
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/list-render",
3
- "version": "1.9.4",
3
+ "version": "1.9.6",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -1,5 +1,6 @@
1
1
  import _ from "lodash";
2
2
  import { getFieldMap } from "./utils";
3
+ import { isRunStr, handleSchemaStrVal, isScopeKey as formIsScopeKey, getScopeKeyVal } from '@hzab/form-render/src/common/schema-handler';
3
4
 
4
5
  export const handleQuerySchema = (opt) => {
5
6
  const { schema, search, filters, onSearch, replaceComList, schemaScope } = opt || {};
@@ -212,6 +213,13 @@ export const handleHoc = (source, cb, opt) => {
212
213
  let _source = getSchemaVal(source, schemaScope);
213
214
 
214
215
  let res = null;
216
+ if (isRunStr(source)) {
217
+
218
+ _source = handleSchemaStrVal(source, schemaScope);
219
+ }
220
+ if (formIsScopeKey(source, schemaScope)) {
221
+ _source = getScopeKeyVal(source, schemaScope);
222
+ }
215
223
  if (_source) {
216
224
  res = await _source(...args);
217
225
  }
@@ -32,7 +32,7 @@ export function getVal(field = {}, data = {}, opt = {}) {
32
32
 
33
33
  if (val && (xComponent === "DatePicker" || xComponent === "DatePicker.RangePicker")) {
34
34
  const { picker, showTime } = xComponentProps || {};
35
- const mode = picker === "date" && showTime === true ? "time" : picker || "date";
35
+ const mode = showTime === true ? "time" : picker || "date";
36
36
  const _formatEnum = opt.dateFormatEnum || dateFormatEnum;
37
37
  const format = xComponentProps?.format || _formatEnum[mode];
38
38
 
@@ -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}
@@ -18,7 +18,7 @@ function QueryRender(props, parentRef) {
18
18
  setSchema(
19
19
  handleQuerySchema({
20
20
  ...props?.config,
21
- schemaScope: props.schemaScope,
21
+ schemaScope: { ...props.schemaScope, scenario: "query" },
22
22
  schema: _.cloneDeep(props.schema),
23
23
  search: props.search,
24
24
  filters: _.cloneDeep(props.filters),
@@ -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: {},
@@ -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
+ }