ztxkui 2.3.1 → 2.3.2

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;
@@ -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, restProps = __rest(_a, ["list", "defaultList", "params", "url", "method", "dataKey", "componentKey", "titleKey", "showAll", "isCatch", "onCompleted", "onChange", "request", "remoteSearch", "remoteSearchKey", "remoteSearchDataKey", "isRemoteSearchDataKey", "transformData", "joinKey", "joinStr", "mustHasParams"]);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkui",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "private": false,
5
5
  "description": "React components library",
6
6
  "author": "zt-front-end",