@hzab/list-render 1.9.0 → 1.9.2-beta
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 +8 -0
- package/package.json +3 -3
- package/src/FormModal/index.tsx +6 -6
- package/src/list-render.jsx +19 -1
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hzab/list-render",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2-beta",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src",
|
|
6
6
|
"scripts": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@ant-design/icons": "^4.8.1",
|
|
23
|
-
"@hzab/data-model": "^1.
|
|
23
|
+
"@hzab/data-model": "^1.7.2",
|
|
24
24
|
"@hzab/form-render": "^1.1.5",
|
|
25
25
|
"@hzab/schema-descriptions": "^1.0.0",
|
|
26
26
|
"@hzab/webpack-config": "^0.7.2",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@formily/core": "2.3.1",
|
|
41
41
|
"@formily/react": "2.3.1",
|
|
42
42
|
"@formily/reactive-react": "2.3.1",
|
|
43
|
-
"@hzab/data-model": ">=1.
|
|
43
|
+
"@hzab/data-model": ">=1.7.2",
|
|
44
44
|
"@hzab/form-render": ">=1.0.0",
|
|
45
45
|
"@hzab/schema-descriptions": ">=1.0.0",
|
|
46
46
|
"antd": "4.x",
|
package/src/FormModal/index.tsx
CHANGED
|
@@ -29,15 +29,15 @@ export function FormModal(props, parentRef) {
|
|
|
29
29
|
const { modalMode, Slots = {}, modalConf = {}, modalProps = {} } = props;
|
|
30
30
|
const [loading, setLoading] = useState(false);
|
|
31
31
|
const [title, setTitle] = useState("新增");
|
|
32
|
-
const [scenario, setScenario] = useState("create");
|
|
33
32
|
const [open, setOpen] = useState(false);
|
|
34
33
|
const formRef = useRef<IFormRef>();
|
|
34
|
+
const scenarioRef = useRef<string>("create");
|
|
35
35
|
|
|
36
36
|
const FormSlot = useMemo(() => props.Slots?.FormSlot, [props.Slots?.FormSlot]);
|
|
37
37
|
|
|
38
38
|
function show(formData = props.formInitialValues, title, scenario = "create") {
|
|
39
|
+
scenarioRef.current = scenario || "create";
|
|
39
40
|
setOpen(true);
|
|
40
|
-
setScenario(scenario || "create");
|
|
41
41
|
// 处理 formRef.current 为 undefined 的问题
|
|
42
42
|
if (formRef.current?.formRender?.setValues) {
|
|
43
43
|
formRef.current?.formRender?.setValues(formData);
|
|
@@ -69,7 +69,7 @@ export function FormModal(props, parentRef) {
|
|
|
69
69
|
const isContinue = await modalConf.beforeSubmit(submitForm, {
|
|
70
70
|
cancel: close,
|
|
71
71
|
formRef,
|
|
72
|
-
scenario,
|
|
72
|
+
scenario: scenarioRef.current,
|
|
73
73
|
});
|
|
74
74
|
if (isContinue === false) {
|
|
75
75
|
return;
|
|
@@ -113,7 +113,7 @@ export function FormModal(props, parentRef) {
|
|
|
113
113
|
close,
|
|
114
114
|
form: formRef.current?.formRender,
|
|
115
115
|
validate,
|
|
116
|
-
scenario,
|
|
116
|
+
scenario: scenarioRef.current,
|
|
117
117
|
};
|
|
118
118
|
if (modalConf?.footer) {
|
|
119
119
|
footer = typeof modalConf?.footer === "function" ? modalConf.footer({ ...options, options }) : modalConf?.footer;
|
|
@@ -177,14 +177,14 @@ export function FormModal(props, parentRef) {
|
|
|
177
177
|
return (
|
|
178
178
|
<CModal {..._modalProps}>
|
|
179
179
|
{FormSlot ? (
|
|
180
|
-
<FormSlot {...props} formRef={formRef} scenario={
|
|
180
|
+
<FormSlot {...props} formRef={formRef} scenario={scenarioRef.current} schema={props.schema?.schema} />
|
|
181
181
|
) : (
|
|
182
182
|
<FormRender
|
|
183
183
|
{...props.formProps}
|
|
184
184
|
ref={formRef}
|
|
185
185
|
schema={props.schema}
|
|
186
186
|
schemaScope={{
|
|
187
|
-
scenario:
|
|
187
|
+
scenario: scenarioRef.current,
|
|
188
188
|
...(props.schemaScope || {}),
|
|
189
189
|
}}
|
|
190
190
|
components={props.components}
|
package/src/list-render.jsx
CHANGED
|
@@ -5,6 +5,7 @@ model 不要定义在组件外部,避免出现 query 异常的情况。
|
|
|
5
5
|
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
6
6
|
import { Button, message } from "antd";
|
|
7
7
|
import _ from "lodash";
|
|
8
|
+
import { getCancelTokenSource } from "@hzab/data-model/src/axios";
|
|
8
9
|
|
|
9
10
|
import QueryRender from "./query-render";
|
|
10
11
|
import Pagination from "./pagination-render";
|
|
@@ -48,6 +49,7 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
48
49
|
const formQueryRef = useRef({});
|
|
49
50
|
const paginationQueryRef = useRef({ pageNum: 1, pageSize: 10 });
|
|
50
51
|
const useFormData = _useFormData ?? dialogConf.useFormData ?? modalConf?.useFormData;
|
|
52
|
+
const getListSourceRef = useRef();
|
|
51
53
|
|
|
52
54
|
useImperativeHandle(parentRef, () => ({
|
|
53
55
|
getList,
|
|
@@ -129,8 +131,20 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
129
131
|
|
|
130
132
|
model.query = mergedQueries;
|
|
131
133
|
|
|
134
|
+
// 取消上一次请求
|
|
135
|
+
getListSourceRef.current?.cancel("取消上一次请求");
|
|
136
|
+
|
|
137
|
+
// 重新获取 source
|
|
138
|
+
getListSourceRef.current = getCancelTokenSource();
|
|
139
|
+
|
|
132
140
|
model
|
|
133
|
-
?.getList(
|
|
141
|
+
?.getList(
|
|
142
|
+
mergedQueries,
|
|
143
|
+
{},
|
|
144
|
+
{
|
|
145
|
+
cancelToken: getListSourceRef.current?.token,
|
|
146
|
+
},
|
|
147
|
+
)
|
|
134
148
|
.then((res) => {
|
|
135
149
|
setList(res.list);
|
|
136
150
|
setTotal(res.pagination?.total);
|
|
@@ -138,6 +152,10 @@ const ListRender = forwardRef(function (props, parentRef) {
|
|
|
138
152
|
setListLoading(false);
|
|
139
153
|
})
|
|
140
154
|
.catch((err) => {
|
|
155
|
+
if (axios.isCancel(error)) {
|
|
156
|
+
console.log("请求已取消:", error.message);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
141
159
|
console.error(err);
|
|
142
160
|
handleMessage(err._message);
|
|
143
161
|
setListLoading(false);
|