ztxkui 2.3.0 → 2.3.4
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/Demo.js
CHANGED
|
@@ -6,7 +6,7 @@ var selectStyle = { width: '200px' };
|
|
|
6
6
|
function request(options) {
|
|
7
7
|
return fetch(options.url + "?" + stringify(options.params), {
|
|
8
8
|
headers: {
|
|
9
|
-
'Zmdms-Auth': 'bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
|
|
9
|
+
'Zmdms-Auth': 'bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOiIwMDAwMDAiLCJtZW1iZXJfdHlwZSI6MSwiaGFuZGxlX2hyX3Bob25lIjpudWxsLCJyZXN1bWVfZGF0ZSI6bnVsbCwidXNlcl9uYW1lIjoiY2hlbnl4IiwiZW1wX25hbWUiOiLpmYjkuprpm4QiLCJlbXBfbnVtYmVyIjoiWUcyMTA3MDA4IiwiaW10X2lkIjpudWxsLCJyZWFsX25hbWUiOiLpmYjkuprpm4QiLCJjbGllbnRfdHlwZSI6IndlYiIsImRhdGFfcm9sZV9pZCI6IjEzNDU5Nzg1MDUzMDIwNTY5NjIsMTQxMjYxNDExMDY0NzM4NjExNCwxNDEyNjE1Njc3MTE5MjY2ODE3LDE0NDgxMjEwODY1MDQzMDA1NDYsMTQ1MjgyMDI5MzgwMjcxMzA5MCwxNDUzOTI1MDAxNTMxNDc4MDE3LDE0NTg3MTIwODIwODIzNTcyNTAsMTQ1ODgyNjIzODE4NTg4OTc5NCwxNDU4ODI3NzAxMDEyMzI0MzUzLDE0NTg4MjgzNjA4MDE1MDkzNzcsMTQ2MDA4OTI2MjAxMjAzMDk3NywxNDYxMTM3Nzg4NjQ1MTI2MTQ2IiwiY2xpZW50X2lkIjoic3dvcmQiLCJ1c2VyX3R5cGUiOiJ3ZWIiLCJyb2xlX2lkIjoiMTQxMjYwODc0Mjk1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giLCJkZXB0X2lkIjoiMTM5NzA4MTkzMDMyODQyNDQ0OSIsImhhbmRsZV9ocl9uYW1lIjpudWxsLCJhY2NvdW50IjoiY2hlbnl4IiwicmVzdW1lX2lkIjpudWxsfQ.FzJkqhtmGgkSsDZd6RBylQEGxBsJRslLDtX9DXgfW-M',
|
|
10
10
|
},
|
|
11
11
|
method: options.method,
|
|
12
12
|
}).then(function (response) { return response.json(); });
|
|
@@ -87,6 +87,14 @@ export interface IProps<T> extends Omit<SelectProps<T>, 'onChange'> {
|
|
|
87
87
|
* 接口数据格式转换
|
|
88
88
|
*/
|
|
89
89
|
transformData?: (res: any) => any;
|
|
90
|
+
/**
|
|
91
|
+
* 增加必传参数组
|
|
92
|
+
*/
|
|
93
|
+
mustHasParams?: string | string[];
|
|
94
|
+
/**
|
|
95
|
+
* 增加需要禁用的选项
|
|
96
|
+
*/
|
|
97
|
+
disabledValues?: any[];
|
|
90
98
|
}
|
|
91
99
|
/**
|
|
92
100
|
* 增强下拉框功能组件
|
|
@@ -103,6 +111,6 @@ export interface IProps<T> extends Omit<SelectProps<T>, 'onChange'> {
|
|
|
103
111
|
* { code: 200, data: { records: [] } } || { status: 200, data: { code: 200, data: { records: [] } } }
|
|
104
112
|
* 如果数据不能在接口层面满足以上形式,那么组件提供transformData属性,转换接口数据格式
|
|
105
113
|
*/
|
|
106
|
-
declare function EnhanceSelect<VT extends SelectValue = SelectValue>({ list, defaultList, params, url, method, dataKey, componentKey, titleKey, showAll, isCatch, onCompleted, onChange, request, remoteSearch, remoteSearchKey, remoteSearchDataKey, isRemoteSearchDataKey, transformData, joinKey, joinStr, ...restProps }: IProps<VT>): JSX.Element;
|
|
114
|
+
declare function EnhanceSelect<VT extends SelectValue = SelectValue>({ list, defaultList, params, url, method, dataKey, componentKey, titleKey, showAll, isCatch, onCompleted, onChange, request, remoteSearch, remoteSearchKey, remoteSearchDataKey, isRemoteSearchDataKey, transformData, joinKey, joinStr, mustHasParams, disabledValues, ...restProps }: IProps<VT>): JSX.Element;
|
|
107
115
|
declare const _default: React.MemoExoticComponent<typeof EnhanceSelect>;
|
|
108
116
|
export default _default;
|
|
@@ -76,7 +76,7 @@ function getData(request, options) {
|
|
|
76
76
|
* 如果数据不能在接口层面满足以上形式,那么组件提供transformData属性,转换接口数据格式
|
|
77
77
|
*/
|
|
78
78
|
function EnhanceSelect(_a) {
|
|
79
|
-
var list = _a.list, defaultList = _a.defaultList, params = _a.params, url = _a.url, _b = _a.method, method = _b === void 0 ? 'GET' : _b, _c = _a.dataKey, dataKey = _c === void 0 ? 'id' : _c, componentKey = _a.componentKey, _d = _a.titleKey, titleKey = _d === void 0 ? 'name' : _d, showAll = _a.showAll, isCatch = _a.isCatch, onCompleted = _a.onCompleted, onChange = _a.onChange, request = _a.request, remoteSearch = _a.remoteSearch, remoteSearchKey = _a.remoteSearchKey, remoteSearchDataKey = _a.remoteSearchDataKey, _e = _a.isRemoteSearchDataKey, isRemoteSearchDataKey = _e === void 0 ? true : _e, transformData = _a.transformData, joinKey = _a.joinKey, _f = _a.joinStr, joinStr = _f === void 0 ? '-' : _f, restProps = __rest(_a, ["list", "defaultList", "params", "url", "method", "dataKey", "componentKey", "titleKey", "showAll", "isCatch", "onCompleted", "onChange", "request", "remoteSearch", "remoteSearchKey", "remoteSearchDataKey", "isRemoteSearchDataKey", "transformData", "joinKey", "joinStr"]);
|
|
79
|
+
var list = _a.list, defaultList = _a.defaultList, params = _a.params, url = _a.url, _b = _a.method, method = _b === void 0 ? 'GET' : _b, _c = _a.dataKey, dataKey = _c === void 0 ? 'id' : _c, componentKey = _a.componentKey, _d = _a.titleKey, titleKey = _d === void 0 ? 'name' : _d, showAll = _a.showAll, isCatch = _a.isCatch, onCompleted = _a.onCompleted, onChange = _a.onChange, request = _a.request, remoteSearch = _a.remoteSearch, remoteSearchKey = _a.remoteSearchKey, remoteSearchDataKey = _a.remoteSearchDataKey, _e = _a.isRemoteSearchDataKey, isRemoteSearchDataKey = _e === void 0 ? true : _e, transformData = _a.transformData, joinKey = _a.joinKey, _f = _a.joinStr, joinStr = _f === void 0 ? '-' : _f, mustHasParams = _a.mustHasParams, disabledValues = _a.disabledValues, restProps = __rest(_a, ["list", "defaultList", "params", "url", "method", "dataKey", "componentKey", "titleKey", "showAll", "isCatch", "onCompleted", "onChange", "request", "remoteSearch", "remoteSearchKey", "remoteSearchDataKey", "isRemoteSearchDataKey", "transformData", "joinKey", "joinStr", "mustHasParams", "disabledValues"]);
|
|
80
80
|
// 下拉数据源
|
|
81
81
|
var _g = useFetchState([]), selectList = _g[0], setSelectList = _g[1];
|
|
82
82
|
// 多选时,自己需要合并的数据
|
|
@@ -96,6 +96,30 @@ function EnhanceSelect(_a) {
|
|
|
96
96
|
}, [selectList]);
|
|
97
97
|
// 获取数据,并设置数据
|
|
98
98
|
var getDataHandle = useCallback(function (request, options, appointObj) {
|
|
99
|
+
var _a;
|
|
100
|
+
if (mustHasParams) {
|
|
101
|
+
var _params_1;
|
|
102
|
+
if (typeof options.params === 'string') {
|
|
103
|
+
try {
|
|
104
|
+
_params_1 = JSON.parse(options.params);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
console.log(err);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (((_a = options === null || options === void 0 ? void 0 : options.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'POST') {
|
|
111
|
+
_params_1 = options.params;
|
|
112
|
+
}
|
|
113
|
+
// 如果必传参数不存在
|
|
114
|
+
if (typeof mustHasParams === 'string' &&
|
|
115
|
+
_params_1[mustHasParams] == null) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (Array.isArray(mustHasParams) &&
|
|
119
|
+
mustHasParams.find(function (key) { return _params_1[key] == null; })) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
99
123
|
setLoading(true);
|
|
100
124
|
// 利用闭包,存到当前请求的id
|
|
101
125
|
fetchId.current++;
|
|
@@ -125,7 +149,7 @@ function EnhanceSelect(_a) {
|
|
|
125
149
|
setLoading(false);
|
|
126
150
|
console.log(err);
|
|
127
151
|
});
|
|
128
|
-
}, [setSelectList, setLoading, transformData]);
|
|
152
|
+
}, [setSelectList, setLoading, transformData, mustHasParams]);
|
|
129
153
|
// 远程搜索
|
|
130
154
|
var getRemoteDataHandle = useCallback(function (value, dataKeyValue) {
|
|
131
155
|
var searchKey = remoteSearchKey ? remoteSearchKey : titleKey;
|
|
@@ -269,9 +293,9 @@ function EnhanceSelect(_a) {
|
|
|
269
293
|
// console.log('已经通过id访问了');
|
|
270
294
|
return;
|
|
271
295
|
}
|
|
296
|
+
// TODO:注释这里的内容
|
|
272
297
|
// 这种情况不需要启用远程搜索key值
|
|
273
298
|
if (!isRemoteSearchDataKey) {
|
|
274
|
-
getRemoteDataHandle('', '');
|
|
275
299
|
setFirstLoading(true);
|
|
276
300
|
return;
|
|
277
301
|
}
|
|
@@ -296,6 +320,24 @@ function EnhanceSelect(_a) {
|
|
|
296
320
|
isRemoteSearchDataKey,
|
|
297
321
|
setFirstLoading,
|
|
298
322
|
]);
|
|
323
|
+
useEffect(function () {
|
|
324
|
+
if (!url || !remoteSearch) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
// console.log('TEST: 远程搜索');
|
|
328
|
+
// 这种情况不需要启用远程搜索key值
|
|
329
|
+
if (!isRemoteSearchDataKey) {
|
|
330
|
+
getRemoteDataHandle('', '');
|
|
331
|
+
setFirstLoading(true);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
}, [
|
|
335
|
+
url,
|
|
336
|
+
remoteSearch,
|
|
337
|
+
setFirstLoading,
|
|
338
|
+
getRemoteDataHandle,
|
|
339
|
+
isRemoteSearchDataKey,
|
|
340
|
+
]);
|
|
299
341
|
// 数据合并
|
|
300
342
|
function concatData(originalData, newData) {
|
|
301
343
|
if (!newData) {
|
|
@@ -339,7 +381,12 @@ function EnhanceSelect(_a) {
|
|
|
339
381
|
else {
|
|
340
382
|
joinTitle = [title];
|
|
341
383
|
}
|
|
342
|
-
|
|
384
|
+
var disabled = item === null || item === void 0 ? void 0 : item.disabled;
|
|
385
|
+
if (Array.isArray(disabledValues) &&
|
|
386
|
+
disabledValues.includes(value)) {
|
|
387
|
+
disabled = true;
|
|
388
|
+
}
|
|
389
|
+
return (React.createElement(Select.Option, { key: key, value: value, title: title, disabled: disabled }, Array.isArray(joinTitle) ? joinTitle === null || joinTitle === void 0 ? void 0 : joinTitle.join(joinStr) : ''));
|
|
343
390
|
})));
|
|
344
391
|
}
|
|
345
392
|
// 本地搜索
|
|
@@ -105,7 +105,7 @@ var TableEnhanceCell = memo(function (_a) {
|
|
|
105
105
|
}
|
|
106
106
|
} })));
|
|
107
107
|
}
|
|
108
|
-
var type = editableConfig.type, data = editableConfig.data, keyValue = editableConfig.keyValue, maxHandle = editableConfig.maxHandle, minHandle = editableConfig.minHandle, editableProps = __rest(editableConfig, ["type", "data", "keyValue", "maxHandle", "minHandle"]);
|
|
108
|
+
var type = editableConfig.type, data = editableConfig.data, keyValue = editableConfig.keyValue, maxHandle = editableConfig.maxHandle, minHandle = editableConfig.minHandle, disabledHandle = editableConfig.disabledHandle, editableProps = __rest(editableConfig, ["type", "data", "keyValue", "maxHandle", "minHandle", "disabledHandle"]);
|
|
109
109
|
var selectData = data; // 下拉框使用到得数据
|
|
110
110
|
// 下拉框键值对对象
|
|
111
111
|
var selectKeyValue = keyValue || {
|
|
@@ -113,6 +113,7 @@ var TableEnhanceCell = memo(function (_a) {
|
|
|
113
113
|
label: 'dictValue',
|
|
114
114
|
};
|
|
115
115
|
var inputNumMaxMin = {}; // 数字input框最大最小值
|
|
116
|
+
var disabledResult = editableProps === null || editableProps === void 0 ? void 0 : editableProps.disabled;
|
|
116
117
|
if (data && data instanceof Function) {
|
|
117
118
|
selectData = data();
|
|
118
119
|
}
|
|
@@ -122,19 +123,22 @@ var TableEnhanceCell = memo(function (_a) {
|
|
|
122
123
|
if (minHandle && minHandle instanceof Function) {
|
|
123
124
|
inputNumMaxMin.min = minHandle(record);
|
|
124
125
|
}
|
|
126
|
+
if (disabledHandle && disabledHandle instanceof Function) {
|
|
127
|
+
disabledResult = disabledHandle(record);
|
|
128
|
+
}
|
|
125
129
|
// 处理各种类型
|
|
126
130
|
if (type === 'select') {
|
|
127
131
|
return (React.createElement(Form.Item, { className: "zt-table__enhance-cell", name: dataIndex },
|
|
128
|
-
React.createElement(Select, __assign({ allowClear: true }, editableProps, { onChange: save }), Array.isArray(selectData) &&
|
|
132
|
+
React.createElement(Select, __assign({ allowClear: true }, editableProps, { disabled: disabledResult, onChange: save }), Array.isArray(selectData) &&
|
|
129
133
|
selectData.map(function (item) { return (React.createElement(Select.Option, { key: item[selectKeyValue.key] + '', value: item[selectKeyValue === null || selectKeyValue === void 0 ? void 0 : selectKeyValue.key] }, item[selectKeyValue === null || selectKeyValue === void 0 ? void 0 : selectKeyValue.label])); }))));
|
|
130
134
|
}
|
|
131
135
|
else if (type === 'inputNumber') {
|
|
132
136
|
return (React.createElement(Form.Item, { className: "zt-table__enhance-cell", name: dataIndex },
|
|
133
|
-
React.createElement(InputNumber, __assign({ autoComplete: "new-password", maxLength: 50 }, inputNumMaxMin, editableProps, { onPressEnter: save, onBlur: save }))));
|
|
137
|
+
React.createElement(InputNumber, __assign({ autoComplete: "new-password", maxLength: 50 }, inputNumMaxMin, editableProps, { disabled: disabledResult, onPressEnter: save, onBlur: save }))));
|
|
134
138
|
}
|
|
135
139
|
else if (type === 'textArea') {
|
|
136
140
|
return (React.createElement(Form.Item, { className: "zt-table__enhance-cell", name: dataIndex },
|
|
137
|
-
React.createElement(Input.TextArea, __assign({ autoComplete: "new-password", maxLength: 200, autoSize: { maxRows: 3 } }, editableProps, { onPressEnter: save, onBlur: save, onChange: function (e) {
|
|
141
|
+
React.createElement(Input.TextArea, __assign({ autoComplete: "new-password", maxLength: 200, autoSize: { maxRows: 3 } }, editableProps, { disabled: disabledResult, onPressEnter: save, onBlur: save, onChange: function (e) {
|
|
138
142
|
if (!e.target.value) {
|
|
139
143
|
e.target.focus();
|
|
140
144
|
}
|
|
@@ -142,7 +146,7 @@ var TableEnhanceCell = memo(function (_a) {
|
|
|
142
146
|
}
|
|
143
147
|
else {
|
|
144
148
|
return (React.createElement(Form.Item, { className: "zt-table__enhance-cell", name: dataIndex },
|
|
145
|
-
React.createElement(Input, __assign({ autoComplete: "new-password", maxLength: 50 }, editableProps, { onPressEnter: save, onBlur: save, allowClear: true, onChange: function (e) {
|
|
149
|
+
React.createElement(Input, __assign({ autoComplete: "new-password", maxLength: 50 }, editableProps, { disabled: disabledResult, onPressEnter: save, onBlur: save, allowClear: true, onChange: function (e) {
|
|
146
150
|
if (!e.target.value) {
|
|
147
151
|
e.target.focus();
|
|
148
152
|
}
|