zmdms-webui 2.9.9 → 3.0.0
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/dist/es/config/utils.js
CHANGED
|
@@ -8,6 +8,30 @@
|
|
|
8
8
|
*/
|
|
9
9
|
function getFinalValue(globalDefault, componentValue) {
|
|
10
10
|
return componentValue !== null && componentValue !== void 0 ? componentValue : globalDefault;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 访问对象值 path可能是数组或字符串。
|
|
14
|
+
* @param obj 目标对象
|
|
15
|
+
* @param path 访问路径
|
|
16
|
+
* @returns 访问到的值
|
|
17
|
+
* @example
|
|
18
|
+
* accessObjValue({ a: { b: { c: 1 } } }, "a.b.c"); // 1
|
|
19
|
+
* accessObjValue({ a: { b: { c: 1 } } }, ["a", "b", "c"]); // 1
|
|
20
|
+
*/
|
|
21
|
+
function accessObjValue(obj, path) {
|
|
22
|
+
if (!obj) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
var pathArr = Array.isArray(path) ? path : path.split(".");
|
|
26
|
+
var result = obj;
|
|
27
|
+
for (var _i = 0, pathArr_1 = pathArr; _i < pathArr_1.length; _i++) {
|
|
28
|
+
var key = pathArr_1[_i];
|
|
29
|
+
result = result[key];
|
|
30
|
+
if (!result) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
11
35
|
}
|
|
12
36
|
|
|
13
|
-
export { getFinalValue };
|
|
37
|
+
export { accessObjValue, getFinalValue };
|
package/dist/es/form/form.js
CHANGED
|
@@ -76,13 +76,16 @@ var Form = function (props, ref) {
|
|
|
76
76
|
if (items) {
|
|
77
77
|
for (var i = 0; i < items.length; i++) {
|
|
78
78
|
var item = items[i];
|
|
79
|
-
if (typeof item.name === "string" &&
|
|
79
|
+
if ((typeof item.name === "string" || Array.isArray(item.name)) &&
|
|
80
80
|
item.shouldUpdateNames &&
|
|
81
81
|
item.shouldUpdateClear) {
|
|
82
82
|
var keys = typeof item.shouldUpdateClear === "boolean"
|
|
83
83
|
? item.shouldUpdateNames
|
|
84
84
|
: item.shouldUpdateClear;
|
|
85
|
-
|
|
85
|
+
var nameKey = Array.isArray(item.name)
|
|
86
|
+
? item.name.join(".")
|
|
87
|
+
: item.name;
|
|
88
|
+
result[nameKey] = {
|
|
86
89
|
keys: keys,
|
|
87
90
|
isDisplay: item.isDisplay,
|
|
88
91
|
};
|
|
@@ -96,6 +99,42 @@ var Form = function (props, ref) {
|
|
|
96
99
|
if (changedValues) {
|
|
97
100
|
var keys = Object.keys(changedValues);
|
|
98
101
|
var nameKeys_1 = Object.keys(itemsShouldUpdate);
|
|
102
|
+
// 支持name传入数组的情况。
|
|
103
|
+
// 如果清空状态里面,有数组的话,可以继续查找
|
|
104
|
+
var isInClear_1 = function (shouldUpdateClear, key) {
|
|
105
|
+
// 遍历name,查找changedValues是否跟key匹配
|
|
106
|
+
var isFindName = function (name, obj, firstKey) {
|
|
107
|
+
var formNameKey = firstKey.split(".");
|
|
108
|
+
if (formNameKey.length > 1) {
|
|
109
|
+
return name.join(".") === firstKey;
|
|
110
|
+
}
|
|
111
|
+
var currentObj = obj;
|
|
112
|
+
var isFind = true;
|
|
113
|
+
for (var i = 0; i < name.length; i++) {
|
|
114
|
+
var nameKey = name[i];
|
|
115
|
+
if (i === 0 && nameKey !== firstKey) {
|
|
116
|
+
isFind = false;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
if (!currentObj.hasOwnProperty(nameKey)) {
|
|
120
|
+
isFind = false;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
currentObj = currentObj[nameKey];
|
|
124
|
+
}
|
|
125
|
+
return isFind;
|
|
126
|
+
};
|
|
127
|
+
for (var i = 0; i < shouldUpdateClear.length; i++) {
|
|
128
|
+
var name_1 = shouldUpdateClear[i];
|
|
129
|
+
if (typeof name_1 === "string" && name_1 === key) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
if (Array.isArray(name_1) && isFindName(name_1, changedValues, key)) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
};
|
|
99
138
|
var changeKeys_1 = [];
|
|
100
139
|
var clearHandler_1 = function (keys) {
|
|
101
140
|
changeKeys_1 = [];
|
|
@@ -105,13 +144,15 @@ var Form = function (props, ref) {
|
|
|
105
144
|
var shouldUpdateClear = itemsShouldUpdate[nameKey]
|
|
106
145
|
? (_a = itemsShouldUpdate[nameKey]) === null || _a === void 0 ? void 0 : _a.keys
|
|
107
146
|
: [];
|
|
108
|
-
if (keys.find(
|
|
147
|
+
// if (keys.find((key) => shouldUpdateClear.includes(key))) {
|
|
148
|
+
if (keys.find(function (key) { return isInClear_1(shouldUpdateClear, key); })) {
|
|
109
149
|
// 这里用undefined当清空值得话,会有点问题。
|
|
110
150
|
// https://github.com/react-component/select/commit/305b3dcfe627482686055a1ec9c34705623d807f
|
|
111
151
|
// 对于下拉框来说 会报这个警告 `label` of `value` is not same as `label` in Select options.
|
|
112
152
|
// 暂时不知道如何消除这个警告 用 null 和 "" 都可以
|
|
113
153
|
// TODO: 暂时改成null
|
|
114
|
-
|
|
154
|
+
var formNameKey = nameKey.split(".");
|
|
155
|
+
(_b = form === null || form === void 0 ? void 0 : form.setFieldValue) === null || _b === void 0 ? void 0 : _b.call(form, formNameKey.length === 1 ? nameKey : formNameKey, null);
|
|
115
156
|
changeKeys_1.push(nameKey);
|
|
116
157
|
// form?.setFieldsValue?.({
|
|
117
158
|
// [nameKey]: undefined,
|
|
@@ -120,6 +161,7 @@ var Form = function (props, ref) {
|
|
|
120
161
|
});
|
|
121
162
|
}
|
|
122
163
|
// 增加递归逻辑,可能字段之间有依赖联系
|
|
164
|
+
// B字段依赖A字段,C字段依赖B字段。那么清空A字段时,需要判断是否清空B字段和C字段
|
|
123
165
|
if (changeKeys_1.length > 0) {
|
|
124
166
|
clearHandler_1(changeKeys_1);
|
|
125
167
|
}
|
|
@@ -71,11 +71,11 @@ interface IFormItem extends Omit<FormItemProps, "label"> {
|
|
|
71
71
|
/**
|
|
72
72
|
* 控制依赖关系
|
|
73
73
|
*/
|
|
74
|
-
shouldUpdateNames?: string[];
|
|
74
|
+
shouldUpdateNames?: (string[] | string)[];
|
|
75
75
|
/**
|
|
76
76
|
* 依赖关系发生改变是否需要清空 当前item
|
|
77
77
|
*/
|
|
78
|
-
shouldUpdateClear?: boolean | string[];
|
|
78
|
+
shouldUpdateClear?: boolean | (string[] | string)[];
|
|
79
79
|
/**
|
|
80
80
|
* 是否需要外部参数判断是否渲染组件,编写高性能表单时,可能会用到这个配置
|
|
81
81
|
* 什么场景下需要开启这个配置:
|
|
@@ -6,6 +6,7 @@ import classNames from '../node_modules/classnames/index.js';
|
|
|
6
6
|
import '../config/ZtxkContext.js';
|
|
7
7
|
import isEqual from '../config/isEqual.js';
|
|
8
8
|
import '../config/MyStorage.js';
|
|
9
|
+
import { accessObjValue } from '../config/utils.js';
|
|
9
10
|
import QuestionCircleOutlined from '../node_modules/@ant-design/icons/es/icons/QuestionCircleOutlined.js';
|
|
10
11
|
|
|
11
12
|
var hiddenLabelCol = { span: 0 };
|
|
@@ -93,7 +94,8 @@ var FormItem = function (props) {
|
|
|
93
94
|
? function (prevValues, curValues, info) {
|
|
94
95
|
for (var i = 0; i < shouldUpdateNames.length; i++) {
|
|
95
96
|
var shouldUpdateName = shouldUpdateNames[i];
|
|
96
|
-
if (prevValues
|
|
97
|
+
if (accessObjValue(prevValues, shouldUpdateName) !==
|
|
98
|
+
accessObjValue(curValues, shouldUpdateName)) {
|
|
97
99
|
return true;
|
|
98
100
|
}
|
|
99
101
|
}
|