ztxkui 2.2.9 → 2.3.3

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.
@@ -87,6 +87,10 @@ 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[];
90
94
  }
91
95
  /**
92
96
  * 增强下拉框功能组件
@@ -103,6 +107,6 @@ export interface IProps<T> extends Omit<SelectProps<T>, 'onChange'> {
103
107
  * { code: 200, data: { records: [] } } || { status: 200, data: { code: 200, data: { records: [] } } }
104
108
  * 如果数据不能在接口层面满足以上形式,那么组件提供transformData属性,转换接口数据格式
105
109
  */
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;
110
+ 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, ...restProps }: IProps<VT>): JSX.Element;
107
111
  declare const _default: React.MemoExoticComponent<typeof EnhanceSelect>;
108
112
  export default _default;
@@ -39,6 +39,7 @@ import debounce from 'lodash/debounce';
39
39
  var enhanceSelectCatchObj = {};
40
40
  // 获取接口数据
41
41
  function getData(request, options) {
42
+ var _a;
42
43
  if (typeof request === 'function') {
43
44
  if (typeof options.params === 'string') {
44
45
  try {
@@ -48,7 +49,7 @@ function getData(request, options) {
48
49
  console.log(err);
49
50
  }
50
51
  }
51
- if (options.methods.toUpperCase() === 'POST') {
52
+ if (((_a = options === null || options === void 0 ? void 0 : options.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'POST') {
52
53
  options.data = options.params;
53
54
  Reflect.deleteProperty(options, 'params');
54
55
  }
@@ -75,7 +76,7 @@ function getData(request, options) {
75
76
  * 如果数据不能在接口层面满足以上形式,那么组件提供transformData属性,转换接口数据格式
76
77
  */
77
78
  function EnhanceSelect(_a) {
78
- 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, restProps = __rest(_a, ["list", "defaultList", "params", "url", "method", "dataKey", "componentKey", "titleKey", "showAll", "isCatch", "onCompleted", "onChange", "request", "remoteSearch", "remoteSearchKey", "remoteSearchDataKey", "isRemoteSearchDataKey", "transformData", "joinKey", "joinStr", "mustHasParams"]);
79
80
  // 下拉数据源
80
81
  var _g = useFetchState([]), selectList = _g[0], setSelectList = _g[1];
81
82
  // 多选时,自己需要合并的数据
@@ -95,6 +96,30 @@ function EnhanceSelect(_a) {
95
96
  }, [selectList]);
96
97
  // 获取数据,并设置数据
97
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
+ }
98
123
  setLoading(true);
99
124
  // 利用闭包,存到当前请求的id
100
125
  fetchId.current++;
@@ -124,7 +149,7 @@ function EnhanceSelect(_a) {
124
149
  setLoading(false);
125
150
  console.log(err);
126
151
  });
127
- }, [setSelectList, setLoading, transformData]);
152
+ }, [setSelectList, setLoading, transformData, mustHasParams]);
128
153
  // 远程搜索
129
154
  var getRemoteDataHandle = useCallback(function (value, dataKeyValue) {
130
155
  var searchKey = remoteSearchKey ? remoteSearchKey : titleKey;
@@ -268,9 +293,9 @@ function EnhanceSelect(_a) {
268
293
  // console.log('已经通过id访问了');
269
294
  return;
270
295
  }
296
+ // TODO:注释这里的内容
271
297
  // 这种情况不需要启用远程搜索key值
272
298
  if (!isRemoteSearchDataKey) {
273
- getRemoteDataHandle('', '');
274
299
  setFirstLoading(true);
275
300
  return;
276
301
  }
@@ -295,6 +320,24 @@ function EnhanceSelect(_a) {
295
320
  isRemoteSearchDataKey,
296
321
  setFirstLoading,
297
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
+ ]);
298
341
  // 数据合并
299
342
  function concatData(originalData, newData) {
300
343
  if (!newData) {
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkui",
3
- "version": "2.2.9",
3
+ "version": "2.3.3",
4
4
  "private": false,
5
5
  "description": "React components library",
6
6
  "author": "zt-front-end",