@hzab/list-render 1.10.12-beta3 → 1.10.12-beta5
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/package.json +1 -1
- package/src/list-render.jsx +89 -89
- package/src/query-render/index.jsx +1 -2
- package/src/table-render/index.jsx +3 -2
package/package.json
CHANGED
package/src/list-render.jsx
CHANGED
|
@@ -4,7 +4,7 @@ model 不要定义在组件外部,避免出现 query 异常的情况。
|
|
|
4
4
|
*/
|
|
5
5
|
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
6
6
|
import { Button, message } from "antd";
|
|
7
|
-
import _ from "lodash";
|
|
7
|
+
import _, { cloneDeep } from "lodash";
|
|
8
8
|
import axios, { getCancelTokenSource } from "@hzab/data-model/src/axios";
|
|
9
9
|
|
|
10
10
|
import QueryRender from "./query-render";
|
|
@@ -74,8 +74,8 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
74
74
|
const formModalRef = useRef();
|
|
75
75
|
const detailModalRef = useRef();
|
|
76
76
|
const queryRef = useRef();
|
|
77
|
-
|
|
78
|
-
const formQueryRef = useRef({});
|
|
77
|
+
// 缓存 query 表单数据,解决直接 form.values 取值时,form values 改变,即使不触发 onSearch 也会导致列表请求入参变化的问题
|
|
78
|
+
const formQueryRef = useRef({ ...(queryFormInitialValues || {}) });
|
|
79
79
|
const paginationQueryRef = useRef({ pageNum: 1, pageSize: pageSizeOptions[0] });
|
|
80
80
|
const useFormData = _useFormData ?? dialogConf.useFormData ?? modalConf?.useFormData;
|
|
81
81
|
const getListSourceRef = useRef();
|
|
@@ -85,6 +85,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
85
85
|
useImperativeHandle(parentRef, () => ({
|
|
86
86
|
getList,
|
|
87
87
|
onSearch,
|
|
88
|
+
onQueryFormSubmit,
|
|
88
89
|
forceUpdate,
|
|
89
90
|
formModalRef,
|
|
90
91
|
formDialogRef: formModalRef,
|
|
@@ -111,7 +112,6 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
111
112
|
} else {
|
|
112
113
|
model.query.pageNum = 1;
|
|
113
114
|
|
|
114
|
-
modelQueryRef.current = model?.query;
|
|
115
115
|
paginationQueryRef.current = {
|
|
116
116
|
pageNum: getUrlQuery?.pageNum || model?.query?.pageNum || paginationQueryRef.current?.pageNum,
|
|
117
117
|
pageSize: getUrlQuery?.pageSize || model?.query?.pageSize || paginationQueryRef.current?.pageSize,
|
|
@@ -121,25 +121,15 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
121
121
|
|
|
122
122
|
// 延迟获取表单实例
|
|
123
123
|
Promise.resolve().then(() => {
|
|
124
|
-
if (queryRef.current && queryRef.current?.formRef?.current?.formRender) {
|
|
124
|
+
if (queryRef.current && queryRef.current?.formRef?.current?.formRender && appendUrlQuery) {
|
|
125
125
|
const extractValues = extractSplitDateRanges(filters, schema, getUrlQuery);
|
|
126
|
-
|
|
127
126
|
queryRef.current.formRef.current.formRender?.setValues(extractValues);
|
|
128
|
-
|
|
129
|
-
formQueryRef.current = _.cloneDeep(getUrlQuery);
|
|
127
|
+
formQueryRef.current = _.cloneDeep(queryRef.current.formRef.current.formRender?.values);
|
|
130
128
|
}
|
|
129
|
+
!props.closeAutoRequest && getList({});
|
|
131
130
|
});
|
|
132
|
-
|
|
133
|
-
!props.closeAutoRequest && getList({ ...queryFormInitialValues, ...(modelQueryRef.current || {}), ...getUrlQuery });
|
|
134
131
|
}, []);
|
|
135
132
|
|
|
136
|
-
useEffect(() => {
|
|
137
|
-
if (model && !model?.query) {
|
|
138
|
-
model.query = {};
|
|
139
|
-
}
|
|
140
|
-
modelQueryRef.current = model?.query;
|
|
141
|
-
}, [model?.query]);
|
|
142
|
-
|
|
143
133
|
useEffect(() => {
|
|
144
134
|
Array.isArray(props.list) && getList();
|
|
145
135
|
}, [props.list]);
|
|
@@ -152,71 +142,69 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
152
142
|
});
|
|
153
143
|
};
|
|
154
144
|
|
|
155
|
-
function getList(query =
|
|
156
|
-
|
|
145
|
+
function getList(query = {}) {
|
|
146
|
+
// Promise.resolve() 解决 首次加载,表单渲染晚于当前逻辑 导致表单默认值取值失败的问题
|
|
147
|
+
return Promise.resolve().then(() => {
|
|
148
|
+
if (!model?.getList && Array.isArray(props.list)) {
|
|
149
|
+
setListLoading(true);
|
|
150
|
+
const { list } = props;
|
|
151
|
+
const { pageNum = 1, pageSize = pageSizeOptions[0] } = paginationQueryRef.current || {};
|
|
152
|
+
|
|
153
|
+
setList(list.slice(pageSize * (pageNum - 1), pageNum * pageSize));
|
|
154
|
+
setTotal(list.length);
|
|
155
|
+
props.onGetListEnd && props.onGetListEnd({ list, pagination: { pageNum, pageSize } });
|
|
156
|
+
setListLoading(false);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (!model?.getList) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
157
162
|
setListLoading(true);
|
|
158
|
-
const { list } = props;
|
|
159
|
-
const { pageNum = 1, pageSize = pageSizeOptions[0] } = paginationQueryRef.current || {};
|
|
160
|
-
|
|
161
|
-
setList(list.slice(pageSize * (pageNum - 1), pageNum * pageSize));
|
|
162
|
-
setTotal(list.length);
|
|
163
|
-
props.onGetListEnd && props.onGetListEnd({ list, pagination: { pageNum, pageSize } });
|
|
164
|
-
setListLoading(false);
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
if (!model?.getList) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
setListLoading(true);
|
|
171
|
-
|
|
172
|
-
// remove $timerange
|
|
173
|
-
const _q = _.cloneDeep(query);
|
|
174
|
-
const _q1 = _.cloneDeep(modelQueryRef.current);
|
|
175
|
-
const _q2 = _.cloneDeep(formQueryRef.current);
|
|
176
|
-
const _q3 = _.cloneDeep(paginationQueryRef.current);
|
|
177
|
-
|
|
178
|
-
const mergedQueries = {
|
|
179
|
-
..._q,
|
|
180
|
-
..._q1,
|
|
181
|
-
..._q2,
|
|
182
|
-
..._q3,
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
if (mergedQueries.$timerange !== undefined) {
|
|
186
|
-
delete mergedQueries.$timerange;
|
|
187
|
-
}
|
|
188
163
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
mergedQueries
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
164
|
+
// remove $timerange
|
|
165
|
+
|
|
166
|
+
const mergedQueries = {
|
|
167
|
+
...formQueryRef.current,
|
|
168
|
+
...query,
|
|
169
|
+
...paginationQueryRef.current,
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
if (mergedQueries.$timerange !== undefined) {
|
|
173
|
+
delete mergedQueries.$timerange;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// model.query = mergedQueries;
|
|
177
|
+
// 取消上一次请求
|
|
178
|
+
getListSourceRef.current?.cancel({ code: 601, message: "取消上一次请求" });
|
|
179
|
+
|
|
180
|
+
// 重新获取 source
|
|
181
|
+
getListSourceRef.current = getCancelTokenSource();
|
|
182
|
+
|
|
183
|
+
return model
|
|
184
|
+
?.getList(
|
|
185
|
+
cloneDeep(mergedQueries),
|
|
186
|
+
{},
|
|
187
|
+
{
|
|
188
|
+
cancelToken: getListSourceRef.current?.token,
|
|
189
|
+
},
|
|
190
|
+
)
|
|
191
|
+
.then((res) => {
|
|
192
|
+
getListSourceRef.current = null;
|
|
193
|
+
setList(res.list);
|
|
194
|
+
setTotal(res.pagination?.total);
|
|
195
|
+
props.onGetListEnd && props.onGetListEnd(res);
|
|
196
|
+
setListLoading(false);
|
|
197
|
+
})
|
|
198
|
+
.catch((err) => {
|
|
199
|
+
if (axios.isCancel(err)) {
|
|
200
|
+
console.info(`请求已取消:`, "", err.message);
|
|
201
|
+
return Promise.reject(err);
|
|
202
|
+
}
|
|
203
|
+
handleMessage(err?._message);
|
|
204
|
+
setListLoading(false);
|
|
214
205
|
return Promise.reject(err);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
setListLoading(false);
|
|
218
|
-
return Promise.reject(err);
|
|
219
|
-
});
|
|
206
|
+
});
|
|
207
|
+
});
|
|
220
208
|
}
|
|
221
209
|
|
|
222
210
|
function onPageChange(page, size) {
|
|
@@ -234,11 +222,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
234
222
|
getList();
|
|
235
223
|
}
|
|
236
224
|
|
|
237
|
-
function onSearch(
|
|
238
|
-
const query = source === "queryRender" ? { ...quer } : { ...formQueryRef.current, ...quer };
|
|
239
|
-
// 重置操作时不赋值
|
|
240
|
-
if (source === "queryRender" && !isReset && appendUrlQuery) setURLObjectQueryParam(query, appendUrlQueryKey);
|
|
241
|
-
|
|
225
|
+
function onSearch(query, source, isReset = false) {
|
|
242
226
|
if (model && !model.query) {
|
|
243
227
|
model.query = {};
|
|
244
228
|
}
|
|
@@ -248,13 +232,29 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
248
232
|
if (model && model.query && !model.query.pageSize) {
|
|
249
233
|
model.query.pageSize = pageSizeOptions[0];
|
|
250
234
|
}
|
|
251
|
-
formQueryRef.current = query;
|
|
252
235
|
// model.query = Object.assign(model.query, query);
|
|
253
236
|
getList(query);
|
|
254
237
|
}
|
|
255
238
|
|
|
256
|
-
|
|
257
|
-
|
|
239
|
+
/**
|
|
240
|
+
* query 表单提交回调
|
|
241
|
+
* @param {*} values
|
|
242
|
+
* @returns
|
|
243
|
+
*/
|
|
244
|
+
function onQueryFormSubmit(values) {
|
|
245
|
+
formQueryRef.current = values;
|
|
246
|
+
// 重置操作时不赋值
|
|
247
|
+
if (appendUrlQuery) {
|
|
248
|
+
setURLObjectQueryParam(values, appendUrlQueryKey);
|
|
249
|
+
}
|
|
250
|
+
return onSearch(values);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function onReset(values) {
|
|
254
|
+
if (appendUrlQuery) {
|
|
255
|
+
removeURLObjectQueryParam(appendUrlQueryKey, "", true);
|
|
256
|
+
}
|
|
257
|
+
return onSearch(values);
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
function handleFieldValueChange(filed, form) {
|
|
@@ -446,8 +446,8 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
446
446
|
...queryFormInitialValues,
|
|
447
447
|
...(queryFormIsExtendModelQuery ? model.query : {}),
|
|
448
448
|
}}
|
|
449
|
-
onSearch={
|
|
450
|
-
onReset={
|
|
449
|
+
onSearch={onQueryFormSubmit}
|
|
450
|
+
onReset={onReset}
|
|
451
451
|
schemaScope={props.schemaScope}
|
|
452
452
|
components={props.components}
|
|
453
453
|
onFieldValueChange={handleFieldValueChange}
|
|
@@ -55,8 +55,7 @@ function QueryRender(props, parentRef) {
|
|
|
55
55
|
|
|
56
56
|
function onReset() {
|
|
57
57
|
formRef.current?.formRender?.reset();
|
|
58
|
-
props.onReset?.
|
|
59
|
-
props.onSearch && props.onSearch(_.cloneDeep(formRef?.current?.formRender?.values), "queryRender", true);
|
|
58
|
+
props.onReset && props.onReset(_.cloneDeep(formRef?.current?.formRender?.values));
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
return (
|
|
@@ -136,7 +136,7 @@ const TableRender = forwardRef(function (props, tableRef) {
|
|
|
136
136
|
const comName = field["x-component"];
|
|
137
137
|
|
|
138
138
|
const decoratorProps = field["x-decorator-props"] || {};
|
|
139
|
-
let _title = title;
|
|
139
|
+
let _title = isFunction(title) ? title() : title;
|
|
140
140
|
if (decoratorProps.tooltip) {
|
|
141
141
|
_title = (
|
|
142
142
|
<span className="col-title-tooltip-wrap inline-block-max-w">
|
|
@@ -428,9 +428,10 @@ const TableRender = forwardRef(function (props, tableRef) {
|
|
|
428
428
|
<Table {...tableProps} />
|
|
429
429
|
)}
|
|
430
430
|
<FormilyField
|
|
431
|
-
schema={
|
|
431
|
+
schema={props.schema}
|
|
432
432
|
formilyRef={formilyRef}
|
|
433
433
|
components={props.components}
|
|
434
|
+
topProps={topProps}
|
|
434
435
|
schemaScope={{
|
|
435
436
|
...reactionOpts,
|
|
436
437
|
...props.schemaScope,
|