@hzab/list-render 1.10.12-beta3 → 1.10.12-beta4
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 +87 -86
- 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,
|
|
@@ -123,23 +123,14 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
123
123
|
Promise.resolve().then(() => {
|
|
124
124
|
if (queryRef.current && queryRef.current?.formRef?.current?.formRender) {
|
|
125
125
|
const extractValues = extractSplitDateRanges(filters, schema, getUrlQuery);
|
|
126
|
-
|
|
127
126
|
queryRef.current.formRef.current.formRender?.setValues(extractValues);
|
|
128
127
|
|
|
129
128
|
formQueryRef.current = _.cloneDeep(getUrlQuery);
|
|
130
129
|
}
|
|
130
|
+
!props.closeAutoRequest && getList({});
|
|
131
131
|
});
|
|
132
|
-
|
|
133
|
-
!props.closeAutoRequest && getList({ ...queryFormInitialValues, ...(modelQueryRef.current || {}), ...getUrlQuery });
|
|
134
132
|
}, []);
|
|
135
133
|
|
|
136
|
-
useEffect(() => {
|
|
137
|
-
if (model && !model?.query) {
|
|
138
|
-
model.query = {};
|
|
139
|
-
}
|
|
140
|
-
modelQueryRef.current = model?.query;
|
|
141
|
-
}, [model?.query]);
|
|
142
|
-
|
|
143
134
|
useEffect(() => {
|
|
144
135
|
Array.isArray(props.list) && getList();
|
|
145
136
|
}, [props.list]);
|
|
@@ -152,71 +143,69 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
152
143
|
});
|
|
153
144
|
};
|
|
154
145
|
|
|
155
|
-
function getList(query =
|
|
156
|
-
|
|
146
|
+
function getList(query = {}) {
|
|
147
|
+
// Promise.resolve() 解决 首次加载,表单渲染晚于当前逻辑 导致表单默认值取值失败的问题
|
|
148
|
+
return Promise.resolve().then(() => {
|
|
149
|
+
if (!model?.getList && Array.isArray(props.list)) {
|
|
150
|
+
setListLoading(true);
|
|
151
|
+
const { list } = props;
|
|
152
|
+
const { pageNum = 1, pageSize = pageSizeOptions[0] } = paginationQueryRef.current || {};
|
|
153
|
+
|
|
154
|
+
setList(list.slice(pageSize * (pageNum - 1), pageNum * pageSize));
|
|
155
|
+
setTotal(list.length);
|
|
156
|
+
props.onGetListEnd && props.onGetListEnd({ list, pagination: { pageNum, pageSize } });
|
|
157
|
+
setListLoading(false);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (!model?.getList) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
157
163
|
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
164
|
|
|
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
|
-
|
|
165
|
+
// remove $timerange
|
|
166
|
+
|
|
167
|
+
const mergedQueries = {
|
|
168
|
+
...formQueryRef.current,
|
|
169
|
+
...query,
|
|
170
|
+
...paginationQueryRef.current,
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
if (mergedQueries.$timerange !== undefined) {
|
|
174
|
+
delete mergedQueries.$timerange;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// model.query = mergedQueries;
|
|
178
|
+
// 取消上一次请求
|
|
179
|
+
getListSourceRef.current?.cancel({ code: 601, message: "取消上一次请求" });
|
|
180
|
+
|
|
181
|
+
// 重新获取 source
|
|
182
|
+
getListSourceRef.current = getCancelTokenSource();
|
|
183
|
+
|
|
184
|
+
return model
|
|
185
|
+
?.getList(
|
|
186
|
+
cloneDeep(mergedQueries),
|
|
187
|
+
{},
|
|
188
|
+
{
|
|
189
|
+
cancelToken: getListSourceRef.current?.token,
|
|
190
|
+
},
|
|
191
|
+
)
|
|
192
|
+
.then((res) => {
|
|
193
|
+
getListSourceRef.current = null;
|
|
194
|
+
setList(res.list);
|
|
195
|
+
setTotal(res.pagination?.total);
|
|
196
|
+
props.onGetListEnd && props.onGetListEnd(res);
|
|
197
|
+
setListLoading(false);
|
|
198
|
+
})
|
|
199
|
+
.catch((err) => {
|
|
200
|
+
if (axios.isCancel(err)) {
|
|
201
|
+
console.info(`请求已取消:`, "", err.message);
|
|
202
|
+
return Promise.reject(err);
|
|
203
|
+
}
|
|
204
|
+
handleMessage(err?._message);
|
|
205
|
+
setListLoading(false);
|
|
214
206
|
return Promise.reject(err);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
setListLoading(false);
|
|
218
|
-
return Promise.reject(err);
|
|
219
|
-
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
220
209
|
}
|
|
221
210
|
|
|
222
211
|
function onPageChange(page, size) {
|
|
@@ -234,11 +223,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
234
223
|
getList();
|
|
235
224
|
}
|
|
236
225
|
|
|
237
|
-
function onSearch(
|
|
238
|
-
const query = source === "queryRender" ? { ...quer } : { ...formQueryRef.current, ...quer };
|
|
239
|
-
// 重置操作时不赋值
|
|
240
|
-
if (source === "queryRender" && !isReset && appendUrlQuery) setURLObjectQueryParam(query, appendUrlQueryKey);
|
|
241
|
-
|
|
226
|
+
function onSearch(query, source, isReset = false) {
|
|
242
227
|
if (model && !model.query) {
|
|
243
228
|
model.query = {};
|
|
244
229
|
}
|
|
@@ -248,13 +233,29 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
248
233
|
if (model && model.query && !model.query.pageSize) {
|
|
249
234
|
model.query.pageSize = pageSizeOptions[0];
|
|
250
235
|
}
|
|
251
|
-
formQueryRef.current = query;
|
|
252
236
|
// model.query = Object.assign(model.query, query);
|
|
253
237
|
getList(query);
|
|
254
238
|
}
|
|
255
239
|
|
|
256
|
-
|
|
257
|
-
|
|
240
|
+
/**
|
|
241
|
+
* query 表单提交回调
|
|
242
|
+
* @param {*} values
|
|
243
|
+
* @returns
|
|
244
|
+
*/
|
|
245
|
+
function onQueryFormSubmit(values) {
|
|
246
|
+
formQueryRef.current = values;
|
|
247
|
+
// 重置操作时不赋值
|
|
248
|
+
if (appendUrlQuery) {
|
|
249
|
+
setURLObjectQueryParam(values, appendUrlQueryKey);
|
|
250
|
+
}
|
|
251
|
+
return onSearch(values);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function onReset(values) {
|
|
255
|
+
if (appendUrlQuery) {
|
|
256
|
+
removeURLObjectQueryParam(appendUrlQueryKey, "", true);
|
|
257
|
+
}
|
|
258
|
+
return onSearch(values);
|
|
258
259
|
}
|
|
259
260
|
|
|
260
261
|
function handleFieldValueChange(filed, form) {
|
|
@@ -446,8 +447,8 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
446
447
|
...queryFormInitialValues,
|
|
447
448
|
...(queryFormIsExtendModelQuery ? model.query : {}),
|
|
448
449
|
}}
|
|
449
|
-
onSearch={
|
|
450
|
-
onReset={
|
|
450
|
+
onSearch={onQueryFormSubmit}
|
|
451
|
+
onReset={onReset}
|
|
451
452
|
schemaScope={props.schemaScope}
|
|
452
453
|
components={props.components}
|
|
453
454
|
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,
|