@hzab/list-render 1.9.9 → 1.10.0-beta1
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 +4 -0
- package/README.md +47 -45
- package/package.json +2 -1
- package/src/common/constant.ts +2 -0
- package/src/common/handleQuerySchema.ts +225 -0
- package/src/components/Formily/FormilyField.tsx +1 -1
- package/src/list-render.jsx +51 -16
- package/src/query-render/index.jsx +3 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -49,58 +49,60 @@ const listDM = useMemo(
|
|
|
49
49
|
|
|
50
50
|
### InfoPanel Attributes
|
|
51
51
|
|
|
52
|
-
| 属性名称 | 属性类型
|
|
53
|
-
| ---------------------------
|
|
52
|
+
| 属性名称 | 属性类型 | 必须 | 默认值 | 描述 |
|
|
53
|
+
| --------------------------- |------------------|-----| --------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
54
54
|
| layout | string | 否 | default | 列表渲染类型格式 |
|
|
55
55
|
| className | string | 否 | - | 外层 div className |
|
|
56
56
|
| idKey | string | 否 | id | 唯一值字段的 key |
|
|
57
57
|
| schema | Object | 是 | - | 字段描述文件,包含各个字段的信息 |
|
|
58
58
|
| model | Object | 是 | - | 数据模型,包含 CURD 接口信息,传入 DataModel 的实例 |
|
|
59
59
|
| isPatchUpdate | boolean | 否 | false | 编辑提交接口是否使用 patch 发起请求 |
|
|
60
|
-
| list | Array |
|
|
61
|
-
| closeAutoRequest | Boolean |
|
|
62
|
-
| hasQuery | Boolean |
|
|
63
|
-
| verticalHeader | Boolean |
|
|
64
|
-
| search | String |
|
|
65
|
-
| filters | Array |
|
|
66
|
-
| queryConf | Object |
|
|
67
|
-
| createText | String/ReactNote |
|
|
68
|
-
| hasCreate | Boolean |
|
|
69
|
-
| hasAction | Boolean |
|
|
70
|
-
| hasEdit | Boolean/Function |
|
|
71
|
-
| hasDel | Boolean/Function |
|
|
72
|
-
| hasDetail | Boolean/Function |
|
|
73
|
-
| hasDelTips | String/Function |
|
|
74
|
-
| tableConf | Object |
|
|
75
|
-
| tableProps | Object |
|
|
76
|
-
| cardConf | Object |
|
|
77
|
-
| cardProps | Object |
|
|
78
|
-
| fetchOnEdit | Boolean |
|
|
79
|
-
| fetchById | Boolean |
|
|
80
|
-
| modalMode | string |
|
|
81
|
-
| modalConf | Object |
|
|
82
|
-
| modalDetailProps | Object |
|
|
83
|
-
| modalFormProps | Object |
|
|
84
|
-
| modalProps | Object |
|
|
85
|
-
| schemaScope | Object |
|
|
86
|
-
| components | Object |
|
|
87
|
-
| detailComponents | Object |
|
|
88
|
-
| hasPagination | Boolean |
|
|
89
|
-
| paginationConf | Object |
|
|
90
|
-
| formInitialValues | Object |
|
|
91
|
-
| Slots | Object |
|
|
92
|
-
| getFieldListOpt | Object |
|
|
93
|
-
| onGetListEnd | Function |
|
|
94
|
-
| onCreateSuc | Function |
|
|
95
|
-
| onEditSuc | Function |
|
|
96
|
-
| onDelSuc | Function |
|
|
97
|
-
| onFormModalClose | Function |
|
|
98
|
-
| modalFormMount | Function |
|
|
99
|
-
| msgConf | Object |
|
|
100
|
-
| i18n | Object |
|
|
101
|
-
| queryFormInitialValues | Object |
|
|
102
|
-
| queryFormIsExtendModelQuery | Boolean |
|
|
60
|
+
| list | Array | | - | 本地数据源 |
|
|
61
|
+
| closeAutoRequest | Boolean | | false | 是否关闭加载完毕后自动发起请求。true 时组件 didMount 不自动发起请求 |
|
|
62
|
+
| hasQuery | Boolean | | true | 是否包含搜索、筛选框、搜索按钮等 |
|
|
63
|
+
| verticalHeader | Boolean | | false | 搜索项和新增按钮是否处于不同的行等 |
|
|
64
|
+
| search | String | | - | 传入空字符串时,不包含搜索框;传入非空字符串时,显示搜索框,同时传入的字符串作为搜索框的占位符 |
|
|
65
|
+
| filters | Array | | [] | 字符串数组,可以包含要筛选的字段 key 值(schema 中的 name),或者字符串 '$timerange'(时间范围筛选专用) |
|
|
66
|
+
| queryConf | Object | | {} | 设置 query 参数的 key |
|
|
67
|
+
| createText | String/ReactNote | | 新增 | 新增按钮文案 |
|
|
68
|
+
| hasCreate | Boolean | | true | 是否显示新增按钮 |
|
|
69
|
+
| hasAction | Boolean | | true | 是否在表格的最右增加一个“操作”列;hasAction 为 true 时,下面的 hasEdit/hasDel 才会生效 |
|
|
70
|
+
| hasEdit | Boolean/Function | | true | 是否显示编辑按钮,可传入回调控制当前行是否显示 |
|
|
71
|
+
| hasDel | Boolean/Function | | true | 是否显示删除按钮,可传入回调控制当前行是否显示 |
|
|
72
|
+
| hasDetail | Boolean/Function | | true | 是否显示详情按钮,可传入回调控制当前行是否显示 |
|
|
73
|
+
| hasDelTips | String/Function | | "确认删除该项?" | 删除按钮自定义提示,可传入回调根据当前行数据显示对应提示 |
|
|
74
|
+
| tableConf | Object | | {} | Table 相关配置 |
|
|
75
|
+
| tableProps | Object | | {} | 直接传给 Table 的 props,相关 API 可直接参考 antd table 组件 |
|
|
76
|
+
| cardConf | Object | | {} | Card 相关配置 |
|
|
77
|
+
| cardProps | Object | | {} | 直接传给 cardRender 的 props,因内部渲染使用的的是详情组件,相关 API 可直接参考 @hzab/schema-descriptions 组件 |
|
|
78
|
+
| fetchOnEdit | Boolean | | true | 展示编辑弹框时,是否会调用一次详情接口进行回填;若为 false,则会使用表格列表接口返回的 row 数据进行回填 |
|
|
79
|
+
| fetchById | Boolean | | true | 编辑中的详情请求,是否使用 id 作为入参的 key |
|
|
80
|
+
| modalMode | string | | dialog | 新增/编辑表单、详情 展示模式: dialog drawer |
|
|
81
|
+
| modalConf | Object | | {} | modal/Drawer 配置对象 |
|
|
82
|
+
| modalDetailProps | Object | | {} | modal descriptions 配置对象 |
|
|
83
|
+
| modalFormProps | Object | | {} | modal/drawer fromRender 配置对象 |
|
|
84
|
+
| modalProps | Object | | {} | modal/drawer 配置对象 |
|
|
85
|
+
| schemaScope | Object | | {} | formRender schemaScope props |
|
|
86
|
+
| components | Object | | {} | formRender components props 自定义组件 |
|
|
87
|
+
| detailComponents | Object | | {} | descriptions components props 自定义组件 |
|
|
88
|
+
| hasPagination | Boolean | | true | 是否显示分页 |
|
|
89
|
+
| paginationConf | Object | | {} | 可自定义 Pagination props,进行 pagination 相关设置 |
|
|
90
|
+
| formInitialValues | Object | | {} | 给新增、编辑对话框中的表单增加默认值 |
|
|
91
|
+
| Slots | Object | | {} | 组件插槽 |
|
|
92
|
+
| getFieldListOpt | Object | | {} | getFieldList opt 参数 |
|
|
93
|
+
| onGetListEnd | Function | | - | 请求列表成功返回的回调 |
|
|
94
|
+
| onCreateSuc | Function | | - | 新增成功返回的回调 |
|
|
95
|
+
| onEditSuc | Function | | - | 编辑成功返回的回调 |
|
|
96
|
+
| onDelSuc | Function | | - | 删除成功返回的回调 |
|
|
97
|
+
| onFormModalClose | Function | | - | 表单弹窗关闭回调 |
|
|
98
|
+
| modalFormMount | Function | | - | 新增、编辑弹窗 Form 渲染完成回调 |
|
|
99
|
+
| msgConf | Object | | {} | 新增、编辑、删除、列表查询,详情查询的报错 msg 提示设置 |
|
|
100
|
+
| i18n | Object | | {} | 文案配置 |
|
|
101
|
+
| queryFormInitialValues | Object | | {} | 列表上方查询 Form 默认值 |
|
|
102
|
+
| queryFormIsExtendModelQuery | Boolean | | false | 列表上方查询 Form 默认值是否继承 data-model.query 置 |
|
|
103
103
|
| useFormData | boolean | 否 | | 是否使用 form data 提交数据 |
|
|
104
|
+
| appendUrlQuery | boolean | 否 | true | 筛选条件改变时是否将参数(对象形式)设置到url query中 |
|
|
105
|
+
| appendUrlQueryKey | string | 否 | URL_PARAM_NAME = "defaultSearchParams" | 自定义设置url query对象参数的key |
|
|
104
106
|
|
|
105
107
|
- fetchOnEdit 展示编辑弹框时,是否会调用一次详情接口进行回填(某些场景下,列表接口只返回部分部分字段,只有详情接口会返回全部字段);若为 false,则会使用表格列表接口返回的 row 数据进行回填
|
|
106
108
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hzab/list-render",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0-beta1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "webpack serve -c ./config/webpack.config.js --env local",
|
|
8
8
|
"build": "webpack -c ./config/webpack.config.js --env production",
|
|
9
|
+
"publish-beta": "npm publish --beta",
|
|
9
10
|
"publish-patch": "npm version patch && npm publish --access public",
|
|
10
11
|
"publish-minor": "npm version minor && npm publish --access public",
|
|
11
12
|
"publish-major": "npm version major && npm publish --access public"
|
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
2
|
import { getFieldMap } from "./utils";
|
|
3
3
|
import { isRunStr, handleSchemaStrVal, isScopeKey as formIsScopeKey, getScopeKeyVal } from '@hzab/form-render/src/common/schema-handler';
|
|
4
|
+
import { URL_PARAM_NAME } from "./constant";
|
|
5
|
+
|
|
6
|
+
// ===================== 类型定义 =====================
|
|
7
|
+
|
|
8
|
+
type AntdDateComponent = 'DatePicker' | 'DatePicker.RangePicker';
|
|
9
|
+
|
|
10
|
+
interface XComponentProps {
|
|
11
|
+
isSplitTimes?: boolean;
|
|
12
|
+
startKey?: string;
|
|
13
|
+
endKey?: string;
|
|
14
|
+
[k: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface FormilyField {
|
|
18
|
+
type?: string;
|
|
19
|
+
title?: string;
|
|
20
|
+
'x-decorator'?: string;
|
|
21
|
+
'x-component'?: string;
|
|
22
|
+
'x-validator'?: unknown[];
|
|
23
|
+
'x-component-props'?: XComponentProps;
|
|
24
|
+
'x-decorator-props'?: Record<string, unknown>;
|
|
25
|
+
'x-designable-id'?: string;
|
|
26
|
+
'x-index'?: number;
|
|
27
|
+
[k: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface FormilyV1SchemaNode {
|
|
31
|
+
type?: string;
|
|
32
|
+
properties?: Record<string, FormilyField>;
|
|
33
|
+
[k: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface FormilyV1Schema {
|
|
37
|
+
form?: Record<string, unknown>;
|
|
38
|
+
schema: FormilyV1SchemaNode;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type URLQueryObject = Record<string, any> | null | undefined;
|
|
42
|
+
|
|
43
|
+
interface ExtractOptions {
|
|
44
|
+
/** 分拆开关字段名,位于 x-component-props;默认 'isSplitTimes' */
|
|
45
|
+
splitFlag?: string;
|
|
46
|
+
/** 分拆开关的期望值;默认 true */
|
|
47
|
+
splitFlagExpectedValue?: unknown;
|
|
48
|
+
/** 默认开始/结束键名(当 schema 未显式配置时),默认 'startTime' / 'endTime' */
|
|
49
|
+
defaultStartKey?: string;
|
|
50
|
+
defaultEndKey?: string;
|
|
51
|
+
/** 认为是 antd 日期组件的名单,默认 DatePicker / DatePicker.RangePicker */
|
|
52
|
+
antdDateComponents?: readonly AntdDateComponent[];
|
|
53
|
+
/**
|
|
54
|
+
* 命中并成功赋值后,是否从返回对象中删除对应的 startKey / endKey
|
|
55
|
+
* 默认 true(删除)
|
|
56
|
+
*/
|
|
57
|
+
removeMatchedKeys?: boolean;
|
|
58
|
+
}
|
|
4
59
|
|
|
5
60
|
export const handleQuerySchema = (opt) => {
|
|
6
61
|
const { schema, search, filters, onSearch, replaceComList, schemaScope } = opt || {};
|
|
@@ -299,4 +354,174 @@ export const getValByScope = (strKey, schemaScope = {}) => {
|
|
|
299
354
|
}
|
|
300
355
|
};
|
|
301
356
|
|
|
357
|
+
/**
|
|
358
|
+
* 将对象序列化后写入 URL query 中
|
|
359
|
+
* @param obj 要存储的对象(保持原始类型)
|
|
360
|
+
* @param paramName query 参数名
|
|
361
|
+
*/
|
|
362
|
+
export function setURLObjectQueryParam<T extends object>(obj: T, paramName = URL_PARAM_NAME): void {
|
|
363
|
+
try {
|
|
364
|
+
if (typeof window === "undefined") return;
|
|
365
|
+
|
|
366
|
+
const href = window.location.href;
|
|
367
|
+
const [origin, hash = ""] = href.split("#");
|
|
368
|
+
const [path, queryString = ""] = hash.split("?");
|
|
369
|
+
const searchParams = new URLSearchParams(queryString);
|
|
370
|
+
const encoded = encodeURIComponent(JSON.stringify(obj));
|
|
371
|
+
|
|
372
|
+
searchParams.set(paramName, encoded);
|
|
373
|
+
|
|
374
|
+
const newHash = `${path}?${searchParams.toString()}`;
|
|
375
|
+
|
|
376
|
+
window.history.replaceState({}, "", `${origin}#${newHash}`);
|
|
377
|
+
} catch (e) {
|
|
378
|
+
console.error(`[setURLObjectQueryParam] 设置失败:`, e);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* 从当前URL中删除指定的查询参数(不刷新页面)
|
|
384
|
+
* 专门处理哈希路由中的查询参数
|
|
385
|
+
* @param key 要删除的查询参数名称
|
|
386
|
+
*/
|
|
387
|
+
export function removeURLObjectQueryParam(key: string): void {
|
|
388
|
+
if (typeof window === "undefined") return;
|
|
389
|
+
|
|
390
|
+
try {
|
|
391
|
+
const href = window.location.href;
|
|
392
|
+
const [origin, hash = ""] = href.split("#");
|
|
393
|
+
const [hashPath, queryString = ""] = hash.split("?");
|
|
394
|
+
const searchParams = new URLSearchParams(queryString);
|
|
395
|
+
|
|
396
|
+
searchParams.delete(key);
|
|
397
|
+
|
|
398
|
+
// 重建哈希部分
|
|
399
|
+
let newHash = hashPath;
|
|
400
|
+
if (searchParams.toString()) {
|
|
401
|
+
newHash += `?${searchParams.toString()}`;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const newUrl = `${origin}${newHash ? `#${newHash}` : ''}`;
|
|
405
|
+
|
|
406
|
+
window.history.replaceState({}, "", newUrl);
|
|
407
|
+
} catch (e) {
|
|
408
|
+
console.error(`[removeURLObjectQueryParam] 删除失败:`, e);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* 从 URL 中解析序列化的对象
|
|
413
|
+
* @param paramName query 参数名
|
|
414
|
+
* @returns 还原的对象(如果不存在返回 null)
|
|
415
|
+
*/
|
|
416
|
+
export function getURLObjectQueryParam<T = any>(paramName = URL_PARAM_NAME): T | Record<string, any> {
|
|
417
|
+
// 返回空对象是为了防止在合并对象时报错导致页面空白
|
|
418
|
+
if (typeof window === "undefined") return {};
|
|
419
|
+
|
|
420
|
+
const href = window.location.href;
|
|
421
|
+
const [, hash = ""] = href.split("#");
|
|
422
|
+
const [, queryString = ""] = hash.split("?");
|
|
423
|
+
const searchParams = new URLSearchParams(queryString);
|
|
424
|
+
const encoded = searchParams.get(paramName);
|
|
425
|
+
|
|
426
|
+
if (!encoded) return null;
|
|
427
|
+
|
|
428
|
+
try {
|
|
429
|
+
return JSON.parse(decodeURIComponent(encoded)) as T;
|
|
430
|
+
} catch (e) {
|
|
431
|
+
console.error(`[getURLObjectQueryParam] 解析失败:`, e);
|
|
432
|
+
return {};
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
// ===================== 辅助函数 =====================
|
|
438
|
+
|
|
439
|
+
const pickFormilyProperties = (schema: FormilyV1Schema): Record<string, FormilyField> =>
|
|
440
|
+
(schema?.schema?.properties ?? {});
|
|
441
|
+
|
|
442
|
+
const isAntdDateComponent = (comp: unknown, whitelist: readonly string[]) =>
|
|
443
|
+
typeof comp === 'string' && whitelist.includes(comp);
|
|
444
|
+
|
|
445
|
+
const filterKeys = (props: Record<string, FormilyField>, filters: readonly string[]) => {
|
|
446
|
+
const filterSet = new Set(filters);
|
|
447
|
+
return Object.entries(props).filter(([k]) => filterSet.has(k));
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
const matchSplitFlag = (field: FormilyField, splitFlag: string, expected: unknown) =>
|
|
451
|
+
field?.['x-component-props']?.[splitFlag] === expected;
|
|
452
|
+
|
|
453
|
+
/** 两个值都缺失则返回 undefined;否则返回二元组 */
|
|
454
|
+
const getRangeTupleOrUndefined = (
|
|
455
|
+
urlObj: URLQueryObject,
|
|
456
|
+
startKey: string,
|
|
457
|
+
endKey: string
|
|
458
|
+
): [any, any] | undefined => {
|
|
459
|
+
const obj = (urlObj ?? {}) as Record<string, any>;
|
|
460
|
+
const hasStart = Object.prototype.hasOwnProperty.call(obj, startKey);
|
|
461
|
+
const hasEnd = Object.prototype.hasOwnProperty.call(obj, endKey);
|
|
462
|
+
if (!hasStart && !hasEnd) return undefined;
|
|
463
|
+
return [obj[startKey], obj[endKey]];
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
// ===================== 主函数 =====================
|
|
467
|
+
/**
|
|
468
|
+
* 根据formilySchema配置逆解析表单key并将url query赋值
|
|
469
|
+
* 三层筛选:根据filters + splitFlag + antdDateComponents 提取formilySchema配置项然后通过配置的key赋值并返回
|
|
470
|
+
* */
|
|
471
|
+
export function extractSplitDateRanges(
|
|
472
|
+
filters: string[],
|
|
473
|
+
formilySchema: FormilyV1Schema,
|
|
474
|
+
urlObj: URLQueryObject,
|
|
475
|
+
options: ExtractOptions = {}
|
|
476
|
+
): Record<string, any> {
|
|
477
|
+
const {
|
|
478
|
+
splitFlag = 'isSplitTimes',
|
|
479
|
+
splitFlagExpectedValue = true,
|
|
480
|
+
defaultStartKey = 'startTime',
|
|
481
|
+
defaultEndKey = 'endTime',
|
|
482
|
+
antdDateComponents = ['DatePicker', 'DatePicker.RangePicker'],
|
|
483
|
+
removeMatchedKeys = true,
|
|
484
|
+
} = options;
|
|
485
|
+
|
|
486
|
+
const properties = pickFormilyProperties(formilySchema);
|
|
487
|
+
const candidates = filterKeys(properties, filters);
|
|
488
|
+
|
|
489
|
+
// 保持不变性
|
|
490
|
+
const base = _.cloneDeep(urlObj) as Record<string, any>;
|
|
491
|
+
|
|
492
|
+
// 统一延迟删除,避免顺序影响
|
|
493
|
+
const keysToDelete = new Set<string>();
|
|
494
|
+
|
|
495
|
+
for (const [fieldKey, field] of candidates) {
|
|
496
|
+
// 未命中则直接跳过本次循环
|
|
497
|
+
if (!isAntdDateComponent(field?.['x-component'], antdDateComponents)) continue;
|
|
498
|
+
if (!matchSplitFlag(field, splitFlag, splitFlagExpectedValue)) continue;
|
|
499
|
+
|
|
500
|
+
const props = field?.['x-component-props'] ?? {};
|
|
501
|
+
const startKey = (props?.startKey as string) || defaultStartKey;
|
|
502
|
+
const endKey = (props?.endKey as string) || defaultEndKey;
|
|
503
|
+
|
|
504
|
+
const tuple = getRangeTupleOrUndefined(base, startKey, endKey);
|
|
505
|
+
if (!tuple) continue; // 两个值都没有则不赋值、不删除
|
|
506
|
+
|
|
507
|
+
// 命中,给 fieldKey 赋值
|
|
508
|
+
base[fieldKey] = tuple;
|
|
509
|
+
|
|
510
|
+
// 按需记录要删除的键(只删除“命中的”)
|
|
511
|
+
if (removeMatchedKeys) {
|
|
512
|
+
if (Object.prototype.hasOwnProperty.call(base, startKey)) keysToDelete.add(startKey);
|
|
513
|
+
if (Object.prototype.hasOwnProperty.call(base, endKey)) keysToDelete.add(endKey);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// 统一执行删除,保证无顺序副作用
|
|
518
|
+
if (removeMatchedKeys) {
|
|
519
|
+
for (const k of keysToDelete) {
|
|
520
|
+
delete base[k];
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return base;
|
|
525
|
+
}
|
|
526
|
+
|
|
302
527
|
export default handleQuerySchema;
|
package/src/list-render.jsx
CHANGED
|
@@ -15,6 +15,8 @@ import FormModal from "./FormModal";
|
|
|
15
15
|
import DetailModal from "./DetailModal";
|
|
16
16
|
|
|
17
17
|
import { objToFormData } from "./common/utils";
|
|
18
|
+
import { setURLObjectQueryParam, getURLObjectQueryParam, removeURLObjectQueryParam, extractSplitDateRanges } from "./common/handleQuerySchema";
|
|
19
|
+
import { URL_PARAM_NAME } from "./common/constant";
|
|
18
20
|
|
|
19
21
|
import "./index.less";
|
|
20
22
|
|
|
@@ -43,6 +45,16 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
43
45
|
* 表单提交是否使用 FormData 格式
|
|
44
46
|
*/
|
|
45
47
|
useFormData: _useFormData,
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 筛选条件改变时是否将参数(对象形式)设置到url query中
|
|
51
|
+
* */
|
|
52
|
+
appendUrlQuery = true,
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 自定义设置url query对象参数的key
|
|
56
|
+
* */
|
|
57
|
+
appendUrlQueryKey = URL_PARAM_NAME
|
|
46
58
|
} = props;
|
|
47
59
|
const pageSizeOptions = props.paginationConf?.pageSizeOptions || pageSizeOptionMap[props.layout] || [10, 20, 50, 100];
|
|
48
60
|
// const [pageSizeOptions, setPageSizeOptions] = useState(
|
|
@@ -77,7 +89,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
77
89
|
onDel,
|
|
78
90
|
}));
|
|
79
91
|
|
|
80
|
-
const { schema = {}, config = {}, model = {}, msgConf = {} } = props;
|
|
92
|
+
const { schema = {}, config = {}, model = {}, msgConf = {}, filters } = props;
|
|
81
93
|
|
|
82
94
|
// useEffect(() => {
|
|
83
95
|
// const list = props.paginationConf?.pageSizeOptions || pageSizeOptionMap[props.layout] || [10, 20, 50, 100];
|
|
@@ -86,19 +98,34 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
86
98
|
// }, [layout]);
|
|
87
99
|
|
|
88
100
|
useEffect(() => {
|
|
101
|
+
const getUrlQuery = appendUrlQuery ? getURLObjectQueryParam(appendUrlQueryKey) : {};
|
|
102
|
+
|
|
89
103
|
if (model) {
|
|
90
104
|
if (!model.query) {
|
|
91
105
|
model.query = {};
|
|
92
106
|
} else {
|
|
107
|
+
model.query.pageNum = 1;
|
|
108
|
+
|
|
93
109
|
modelQueryRef.current = model?.query;
|
|
94
110
|
paginationQueryRef.current = {
|
|
95
|
-
pageNum: model?.query?.pageNum
|
|
96
|
-
pageSize: model?.query?.pageSize
|
|
111
|
+
pageNum: getUrlQuery?.pageNum || model?.query?.pageNum || paginationQueryRef.current?.pageNum,
|
|
112
|
+
pageSize: getUrlQuery?.pageSize || model?.query?.pageSize || paginationQueryRef.current?.pageSize,
|
|
97
113
|
};
|
|
98
114
|
}
|
|
99
|
-
model.query.pageNum = 1;
|
|
100
115
|
}
|
|
101
|
-
|
|
116
|
+
|
|
117
|
+
// 延迟获取表单实例
|
|
118
|
+
Promise.resolve().then(() => {
|
|
119
|
+
if (queryRef.current && queryRef.current?.formRef?.current.formRender) {
|
|
120
|
+
const extractValues = extractSplitDateRanges(filters, schema, getUrlQuery);
|
|
121
|
+
|
|
122
|
+
queryRef.current.formRef.current.formRender?.setValues(extractValues)
|
|
123
|
+
|
|
124
|
+
formQueryRef.current = _.cloneDeep(getUrlQuery)
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
!props.closeAutoRequest && getList({ ...(modelQueryRef.current || {}), ...getUrlQuery });
|
|
102
129
|
}, []);
|
|
103
130
|
|
|
104
131
|
useEffect(() => {
|
|
@@ -154,8 +181,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
154
181
|
delete mergedQueries.$timerange;
|
|
155
182
|
}
|
|
156
183
|
|
|
157
|
-
model.query = mergedQueries;
|
|
158
|
-
|
|
184
|
+
// model.query = mergedQueries;
|
|
159
185
|
// 取消上一次请求
|
|
160
186
|
getListSourceRef.current?.cancel({ code: 601, message: "取消上一次请求" });
|
|
161
187
|
|
|
@@ -195,11 +221,19 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
195
221
|
// model.query.pageNum = page;
|
|
196
222
|
// model.query.pageSize = size;
|
|
197
223
|
paginationQueryRef.current = { pageNum: page, pageSize: size };
|
|
224
|
+
|
|
225
|
+
if (appendUrlQuery) {
|
|
226
|
+
const getUrlQuery = getURLObjectQueryParam(appendUrlQueryKey);
|
|
227
|
+
setURLObjectQueryParam({ ...getUrlQuery, ...paginationQueryRef.current }, appendUrlQueryKey)
|
|
228
|
+
}
|
|
198
229
|
getList();
|
|
199
230
|
}
|
|
200
231
|
|
|
201
|
-
function onSearch(quer, source) {
|
|
232
|
+
function onSearch(quer, source, isReset = false) {
|
|
202
233
|
const query = source === "queryRender" ? { ...quer } : { ...formQueryRef.current, ...quer };
|
|
234
|
+
// 重置操作时不赋值
|
|
235
|
+
if (source === "queryRender" && !isReset && appendUrlQuery) setURLObjectQueryParam(query, appendUrlQueryKey);
|
|
236
|
+
|
|
203
237
|
if (model && !model.query) {
|
|
204
238
|
model.query = {};
|
|
205
239
|
}
|
|
@@ -214,6 +248,10 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
214
248
|
getList(query);
|
|
215
249
|
}
|
|
216
250
|
|
|
251
|
+
function handleFormReset() {
|
|
252
|
+
appendUrlQuery && removeURLObjectQueryParam(appendUrlQueryKey)
|
|
253
|
+
}
|
|
254
|
+
|
|
217
255
|
function forceUpdate() {
|
|
218
256
|
setList((l) => _.cloneDeep(l));
|
|
219
257
|
}
|
|
@@ -363,15 +401,12 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
363
401
|
search={props.search}
|
|
364
402
|
filters={props.filters}
|
|
365
403
|
config={props.queryConf}
|
|
366
|
-
queryFormInitialValues={
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
...model.query,
|
|
371
|
-
}
|
|
372
|
-
: queryFormInitialValues
|
|
373
|
-
}
|
|
404
|
+
queryFormInitialValues={{
|
|
405
|
+
...queryFormInitialValues,
|
|
406
|
+
...(queryFormIsExtendModelQuery ? model.query : {}),
|
|
407
|
+
}}
|
|
374
408
|
onSearch={onSearch}
|
|
409
|
+
onReset={handleFormReset}
|
|
375
410
|
schemaScope={props.schemaScope}
|
|
376
411
|
components={props.components}
|
|
377
412
|
i18n={i18n}
|
|
@@ -54,9 +54,11 @@ function QueryRender(props, parentRef) {
|
|
|
54
54
|
|
|
55
55
|
function onReset() {
|
|
56
56
|
formRef.current?.formRender?.reset();
|
|
57
|
-
props.
|
|
57
|
+
props.onReset?.();
|
|
58
|
+
props.onSearch && props.onSearch(_.cloneDeep(formRef?.current?.formRender?.values), "queryRender", true);
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
|
|
60
62
|
return (
|
|
61
63
|
<div className="query-render">
|
|
62
64
|
{Object.keys(schema?.schema?.properties || {}).length > 0 ? (
|