@hzab/list-render 1.10.12-beta2 → 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/CHANGELOG.md +1 -0
- package/package.json +1 -1
- package/src/common/formily-utils.jsx +174 -174
- package/src/index.js +5 -5
- package/src/list-render.jsx +87 -86
- package/src/query-render/index.jsx +1 -2
- package/src/table-render/index.jsx +3 -2
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
import { observer } from "@formily/react";
|
|
2
|
-
import { autorun, observable } from "@formily/reactive";
|
|
3
|
-
|
|
4
|
-
export function handleTableProps(field, { scope, value, record }) {
|
|
5
|
-
if (!field) {
|
|
6
|
-
return field;
|
|
7
|
-
}
|
|
8
|
-
const opt = {
|
|
9
|
-
scope: scope,
|
|
10
|
-
$self: field,
|
|
11
|
-
$values: value,
|
|
12
|
-
$deps: record,
|
|
13
|
-
};
|
|
14
|
-
// inTable
|
|
15
|
-
// x-table-props
|
|
16
|
-
if (typeof field.inTable === "string") {
|
|
17
|
-
field.inTable = getStateFunc(field.inTable, opt)(opt);
|
|
18
|
-
}
|
|
19
|
-
const tableProps = field["x-table-props"];
|
|
20
|
-
if (tableProps) {
|
|
21
|
-
if (typeof tableProps === "string") {
|
|
22
|
-
field["x-table-props"] = getStateFunc(field.inTable, opt)(opt);
|
|
23
|
-
} else if (tableProps && typeof tableProps === "object") {
|
|
24
|
-
Object.keys(tableProps).forEach((key) => {
|
|
25
|
-
if (typeof field["x-table-props"][key] === "string") {
|
|
26
|
-
field["x-table-props"][key] = getStateFunc(field["x-table-props"][key], opt)(opt);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return field;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 解决 render 中无法响应数据的情况
|
|
36
|
-
* @param {Function} render
|
|
37
|
-
* @returns
|
|
38
|
-
*/
|
|
39
|
-
export function getColRender(render) {
|
|
40
|
-
return function (...args) {
|
|
41
|
-
const Observer = observer(function () {
|
|
42
|
-
return render(...args);
|
|
43
|
-
});
|
|
44
|
-
return <Observer />;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 根据 formily 函数字符串 {{xxx}},获取变量或可执行函数
|
|
50
|
-
* @param {*} funcStr
|
|
51
|
-
* @param {*} opt
|
|
52
|
-
* @returns
|
|
53
|
-
*/
|
|
54
|
-
export const getScopeVal = function (funcStr = "", opt = {}) {
|
|
55
|
-
if (typeof funcStr !== "string" || !funcStr.startsWith("{{")) {
|
|
56
|
-
return funcStr;
|
|
57
|
-
}
|
|
58
|
-
const stateStr = funcStr.replace(/^\{\{/, "").replace(/\}\}$/, "");
|
|
59
|
-
const res = opt?.scope?.[stateStr];
|
|
60
|
-
// 存在对应变量直接返回
|
|
61
|
-
if (res) {
|
|
62
|
-
return res;
|
|
63
|
-
}
|
|
64
|
-
return getFunc(stateStr, opt);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 根据 formily 函数字符串 {{xxx}},获取可执行函数
|
|
69
|
-
* @param {string} funcStr
|
|
70
|
-
* @param {Object} opt
|
|
71
|
-
* @returns
|
|
72
|
-
*/
|
|
73
|
-
export function getStateFunc(funcStr = "", opt) {
|
|
74
|
-
if (typeof funcStr !== "string" || !funcStr.startsWith("{{")) {
|
|
75
|
-
return funcStr;
|
|
76
|
-
}
|
|
77
|
-
const stateStr = funcStr.replace(/^\{\{/, "").replace(/\}\}$/, "");
|
|
78
|
-
return getFunc(stateStr, opt);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 根据函数字符串,获取可执行函数
|
|
83
|
-
* @param {string} funcStr
|
|
84
|
-
* @param {Object} opt
|
|
85
|
-
* @returns
|
|
86
|
-
*/
|
|
87
|
-
export function getFunc(
|
|
88
|
-
funcStr = "",
|
|
89
|
-
// opt = {"scope", "$self", "$values"},
|
|
90
|
-
opt = {},
|
|
91
|
-
) {
|
|
92
|
-
const _opt = {
|
|
93
|
-
// opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
|
|
94
|
-
$observable: observable,
|
|
95
|
-
$memo: autorun.memo,
|
|
96
|
-
$effect: autorun.effect,
|
|
97
|
-
scope: {},
|
|
98
|
-
...opt,
|
|
99
|
-
};
|
|
100
|
-
const fn = new Function(
|
|
101
|
-
"opt",
|
|
102
|
-
`const { ${Object.keys(_opt).join(", ")} } = opt || {}; const {${Object.keys(_opt.scope || {}).join(
|
|
103
|
-
", ",
|
|
104
|
-
)}} = scope || {}; return ${funcStr}; `,
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
return function (opt) {
|
|
108
|
-
return fn.call(this, {
|
|
109
|
-
// opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
|
|
110
|
-
$observable: observable,
|
|
111
|
-
$memo: autorun.memo,
|
|
112
|
-
$effect: autorun.effect,
|
|
113
|
-
...opt,
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* 根据 formily 函数字符串 {{xxx}},获取可执行的异步函数
|
|
120
|
-
* @param {string} funcStr
|
|
121
|
-
* @param {Object} opt
|
|
122
|
-
* @returns
|
|
123
|
-
*/
|
|
124
|
-
export function getStateSyncFunc(funcStr = "", opt) {
|
|
125
|
-
if (typeof funcStr !== "string" || !funcStr.startsWith("{{")) {
|
|
126
|
-
return funcStr;
|
|
127
|
-
}
|
|
128
|
-
const stateStr = funcStr.replace(/^\{\{/, "").replace(/\}\}$/, "");
|
|
129
|
-
return getFuncSync(stateStr, opt);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* 根据函数字符串,获取可执行的异步函数
|
|
134
|
-
* @param {string} funcStr
|
|
135
|
-
* @param {Object} opt
|
|
136
|
-
* @returns
|
|
137
|
-
*/
|
|
138
|
-
export function getFuncSync(
|
|
139
|
-
funcStr = "",
|
|
140
|
-
// opt = {"scope", "$self", "$values"},
|
|
141
|
-
opt = {},
|
|
142
|
-
) {
|
|
143
|
-
const _opt = {
|
|
144
|
-
// opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
|
|
145
|
-
$observable: observable,
|
|
146
|
-
$memo: autorun.memo,
|
|
147
|
-
$effect: autorun.effect,
|
|
148
|
-
scope: {},
|
|
149
|
-
...opt,
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
// 把 effectFn 字符串转为可执行函数,并传入所需的参数,支持异步
|
|
153
|
-
const getAsyncFunction = new Function(`return Object.getPrototypeOf(async function(){}).constructor;`);
|
|
154
|
-
const AsyncFunction = getAsyncFunction();
|
|
155
|
-
// 只能这样拿到 AsyncFunction
|
|
156
|
-
// 直接写 Object.getPrototypeOf(async function(){}).constructor
|
|
157
|
-
// 会被 babel 转成 Function
|
|
158
|
-
const asyncFunc = new AsyncFunction(
|
|
159
|
-
"opt",
|
|
160
|
-
`try {const {${Object.keys(_opt).join(", ")}} = opt || {}; const {${Object.keys(_opt.scope || {}).join(
|
|
161
|
-
", ",
|
|
162
|
-
)}} = scope || {}; return ${funcStr}; } catch(err) {console.error("Error Formily Reactive Function: ", err);}`,
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
return function (opt) {
|
|
166
|
-
return asyncFunc.call(this, {
|
|
167
|
-
// opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
|
|
168
|
-
$observable: observable,
|
|
169
|
-
$memo: autorun.memo,
|
|
170
|
-
$effect: autorun.effect,
|
|
171
|
-
...opt,
|
|
172
|
-
});
|
|
173
|
-
};
|
|
174
|
-
}
|
|
1
|
+
import { observer } from "@formily/react";
|
|
2
|
+
import { autorun, observable } from "@formily/reactive";
|
|
3
|
+
|
|
4
|
+
export function handleTableProps(field, { scope, value, record }) {
|
|
5
|
+
if (!field) {
|
|
6
|
+
return field;
|
|
7
|
+
}
|
|
8
|
+
const opt = {
|
|
9
|
+
scope: scope,
|
|
10
|
+
$self: field,
|
|
11
|
+
$values: value,
|
|
12
|
+
$deps: record,
|
|
13
|
+
};
|
|
14
|
+
// inTable
|
|
15
|
+
// x-table-props
|
|
16
|
+
if (typeof field.inTable === "string") {
|
|
17
|
+
field.inTable = getStateFunc(field.inTable, opt)(opt);
|
|
18
|
+
}
|
|
19
|
+
const tableProps = field["x-table-props"];
|
|
20
|
+
if (tableProps) {
|
|
21
|
+
if (typeof tableProps === "string") {
|
|
22
|
+
field["x-table-props"] = getStateFunc(field.inTable, opt)(opt);
|
|
23
|
+
} else if (tableProps && typeof tableProps === "object") {
|
|
24
|
+
Object.keys(tableProps).forEach((key) => {
|
|
25
|
+
if (typeof field["x-table-props"][key] === "string") {
|
|
26
|
+
field["x-table-props"][key] = getStateFunc(field["x-table-props"][key], opt)(opt);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return field;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 解决 render 中无法响应数据的情况
|
|
36
|
+
* @param {Function} render
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
export function getColRender(render) {
|
|
40
|
+
return function (...args) {
|
|
41
|
+
const Observer = observer(function () {
|
|
42
|
+
return render(...args);
|
|
43
|
+
});
|
|
44
|
+
return <Observer />;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 根据 formily 函数字符串 {{xxx}},获取变量或可执行函数
|
|
50
|
+
* @param {*} funcStr
|
|
51
|
+
* @param {*} opt
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
export const getScopeVal = function (funcStr = "", opt = {}) {
|
|
55
|
+
if (typeof funcStr !== "string" || !funcStr.startsWith("{{")) {
|
|
56
|
+
return funcStr;
|
|
57
|
+
}
|
|
58
|
+
const stateStr = funcStr.replace(/^\{\{/, "").replace(/\}\}$/, "");
|
|
59
|
+
const res = opt?.scope?.[stateStr];
|
|
60
|
+
// 存在对应变量直接返回
|
|
61
|
+
if (res) {
|
|
62
|
+
return res;
|
|
63
|
+
}
|
|
64
|
+
return getFunc(stateStr, opt);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 根据 formily 函数字符串 {{xxx}},获取可执行函数
|
|
69
|
+
* @param {string} funcStr
|
|
70
|
+
* @param {Object} opt
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
export function getStateFunc(funcStr = "", opt) {
|
|
74
|
+
if (typeof funcStr !== "string" || !funcStr.startsWith("{{")) {
|
|
75
|
+
return funcStr;
|
|
76
|
+
}
|
|
77
|
+
const stateStr = funcStr.replace(/^\{\{/, "").replace(/\}\}$/, "");
|
|
78
|
+
return getFunc(stateStr, opt);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 根据函数字符串,获取可执行函数
|
|
83
|
+
* @param {string} funcStr
|
|
84
|
+
* @param {Object} opt
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
export function getFunc(
|
|
88
|
+
funcStr = "",
|
|
89
|
+
// opt = {"scope", "$self", "$values"},
|
|
90
|
+
opt = {},
|
|
91
|
+
) {
|
|
92
|
+
const _opt = {
|
|
93
|
+
// opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
|
|
94
|
+
$observable: observable,
|
|
95
|
+
$memo: autorun.memo,
|
|
96
|
+
$effect: autorun.effect,
|
|
97
|
+
scope: {},
|
|
98
|
+
...opt,
|
|
99
|
+
};
|
|
100
|
+
const fn = new Function(
|
|
101
|
+
"opt",
|
|
102
|
+
`const { ${Object.keys(_opt).join(", ")} } = opt || {}; const {${Object.keys(_opt.scope || {}).join(
|
|
103
|
+
", ",
|
|
104
|
+
)}} = scope || {}; return ${funcStr}; `,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return function (opt) {
|
|
108
|
+
return fn.call(this, {
|
|
109
|
+
// opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
|
|
110
|
+
$observable: observable,
|
|
111
|
+
$memo: autorun.memo,
|
|
112
|
+
$effect: autorun.effect,
|
|
113
|
+
...opt,
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 根据 formily 函数字符串 {{xxx}},获取可执行的异步函数
|
|
120
|
+
* @param {string} funcStr
|
|
121
|
+
* @param {Object} opt
|
|
122
|
+
* @returns
|
|
123
|
+
*/
|
|
124
|
+
export function getStateSyncFunc(funcStr = "", opt) {
|
|
125
|
+
if (typeof funcStr !== "string" || !funcStr.startsWith("{{")) {
|
|
126
|
+
return funcStr;
|
|
127
|
+
}
|
|
128
|
+
const stateStr = funcStr.replace(/^\{\{/, "").replace(/\}\}$/, "");
|
|
129
|
+
return getFuncSync(stateStr, opt);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 根据函数字符串,获取可执行的异步函数
|
|
134
|
+
* @param {string} funcStr
|
|
135
|
+
* @param {Object} opt
|
|
136
|
+
* @returns
|
|
137
|
+
*/
|
|
138
|
+
export function getFuncSync(
|
|
139
|
+
funcStr = "",
|
|
140
|
+
// opt = {"scope", "$self", "$values"},
|
|
141
|
+
opt = {},
|
|
142
|
+
) {
|
|
143
|
+
const _opt = {
|
|
144
|
+
// opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
|
|
145
|
+
$observable: observable,
|
|
146
|
+
$memo: autorun.memo,
|
|
147
|
+
$effect: autorun.effect,
|
|
148
|
+
scope: {},
|
|
149
|
+
...opt,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// 把 effectFn 字符串转为可执行函数,并传入所需的参数,支持异步
|
|
153
|
+
const getAsyncFunction = new Function(`return Object.getPrototypeOf(async function(){}).constructor;`);
|
|
154
|
+
const AsyncFunction = getAsyncFunction();
|
|
155
|
+
// 只能这样拿到 AsyncFunction
|
|
156
|
+
// 直接写 Object.getPrototypeOf(async function(){}).constructor
|
|
157
|
+
// 会被 babel 转成 Function
|
|
158
|
+
const asyncFunc = new AsyncFunction(
|
|
159
|
+
"opt",
|
|
160
|
+
`try {const {${Object.keys(_opt).join(", ")}} = opt || {}; const {${Object.keys(_opt.scope || {}).join(
|
|
161
|
+
", ",
|
|
162
|
+
)}} = scope || {}; return ${funcStr}; } catch(err) {console.error("Error Formily Reactive Function: ", err);}`,
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
return function (opt) {
|
|
166
|
+
return asyncFunc.call(this, {
|
|
167
|
+
// opt = ["scope", "$self", "$deps", "$values", "$observable", "$memo", "$effect"],
|
|
168
|
+
$observable: observable,
|
|
169
|
+
$memo: autorun.memo,
|
|
170
|
+
$effect: autorun.effect,
|
|
171
|
+
...opt,
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import ListRender from "./list-render.jsx";
|
|
2
|
-
|
|
3
|
-
export * from "@hzab/data-model";
|
|
4
|
-
|
|
5
|
-
export default ListRender;
|
|
1
|
+
import ListRender from "./list-render.jsx";
|
|
2
|
+
|
|
3
|
+
export * from "@hzab/data-model";
|
|
4
|
+
|
|
5
|
+
export default ListRender;
|
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({ ...(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,
|