ztxkui 2.0.3 → 2.0.8

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.
@@ -79,6 +79,10 @@ export interface IProps<T> extends Omit<SelectProps<T>, 'onChange'> {
79
79
  * 远程搜索主键Key值
80
80
  */
81
81
  remoteSearchDataKey?: string;
82
+ /**
83
+ * 是否启用远程搜索主键Key值
84
+ */
85
+ isRemoteSearchDataKey?: boolean;
82
86
  /**
83
87
  * 接口数据格式转换
84
88
  */
@@ -99,6 +103,6 @@ export interface IProps<T> extends Omit<SelectProps<T>, 'onChange'> {
99
103
  * { code: 200, data: { records: [] } } || { status: 200, data: { code: 200, data: { records: [] } } }
100
104
  * 如果数据不能在接口层面满足以上形式,那么组件提供transformData属性,转换接口数据格式
101
105
  */
102
- declare function EnhanceSelect<VT extends SelectValue = SelectValue>({ list, defaultList, params, url, method, dataKey, componentKey, titleKey, showAll, isCatch, onCompleted, onChange, request, remoteSearch, remoteSearchKey, remoteSearchDataKey, transformData, joinKey, joinStr, ...restProps }: IProps<VT>): JSX.Element;
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;
103
107
  declare const _default: React.MemoExoticComponent<typeof EnhanceSelect>;
104
108
  export default _default;
@@ -71,14 +71,15 @@ function getData(request, options) {
71
71
  * 如果数据不能在接口层面满足以上形式,那么组件提供transformData属性,转换接口数据格式
72
72
  */
73
73
  function EnhanceSelect(_a) {
74
- 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, transformData = _a.transformData, joinKey = _a.joinKey, _e = _a.joinStr, joinStr = _e === void 0 ? '-' : _e, restProps = __rest(_a, ["list", "defaultList", "params", "url", "method", "dataKey", "componentKey", "titleKey", "showAll", "isCatch", "onCompleted", "onChange", "request", "remoteSearch", "remoteSearchKey", "remoteSearchDataKey", "transformData", "joinKey", "joinStr"]);
74
+ 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"]);
75
75
  // 下拉数据源
76
- var _f = useFetchState([]), selectList = _f[0], setSelectList = _f[1];
76
+ var _g = useFetchState([]), selectList = _g[0], setSelectList = _g[1];
77
77
  // 多选时,自己需要合并的数据
78
- var _g = useFetchState([]), multipleList = _g[0], setMultipleList = _g[1];
79
- var _h = useFetchState(false), loading = _h[0], setLoading = _h[1];
78
+ var _h = useFetchState([]), multipleList = _h[0], setMultipleList = _h[1];
79
+ var _j = useFetchState(false), loading = _j[0], setLoading = _j[1];
80
80
  var fetchId = useRef(0); // 请求Id,每次请求都会加1
81
- var _j = useFetchState(false), firstLoading = _j[0], setFirstLoading = _j[1];
81
+ // 是否使用过远程搜索主键key
82
+ var _k = useFetchState(false), firstLoading = _k[0], setFirstLoading = _k[1];
82
83
  // 如果selectList 发生改变,那么触发onCompleted事件
83
84
  useEffect(function () {
84
85
  if (Array.isArray(selectList) && onCompleted) {
@@ -183,9 +184,9 @@ function EnhanceSelect(_a) {
183
184
  ]);
184
185
  var searchHandle = function (value) {
185
186
  // 当value有值时才进行搜索
186
- if (value) {
187
- getRemoteDataHandle(value, '');
188
- }
187
+ // if (value) {
188
+ getRemoteDataHandle(value, '');
189
+ // }
189
190
  };
190
191
  var onSearchHandle = debounce(searchHandle, 300);
191
192
  // 1、如果传入list的话,那么直接使用list数据
@@ -241,16 +242,26 @@ function EnhanceSelect(_a) {
241
242
  if (!url || !remoteSearch) {
242
243
  return;
243
244
  }
245
+ debugger;
244
246
  // console.log('TEST: 远程搜索');
245
- if (!firstLoading) {
246
- if (!restProps.value) {
247
- getRemoteDataHandle('', '');
248
- }
249
- else {
250
- if (typeof restProps.value === 'string') {
251
- setFirstLoading(true);
252
- getRemoteDataHandle('', restProps.value);
253
- }
247
+ // 如果初始化请求已经做过了,那么这个副作用直接返回
248
+ if (firstLoading) {
249
+ return;
250
+ }
251
+ // 这种情况不需要启用远程搜索key值
252
+ if (!isRemoteSearchDataKey) {
253
+ getRemoteDataHandle('', '');
254
+ setFirstLoading(true);
255
+ return;
256
+ }
257
+ if (!restProps.value) {
258
+ getRemoteDataHandle('', '');
259
+ }
260
+ else {
261
+ if (typeof restProps.value === 'string' ||
262
+ Array.isArray(restProps.value)) {
263
+ setFirstLoading(true);
264
+ getRemoteDataHandle('', restProps.value);
254
265
  }
255
266
  }
256
267
  }, [
@@ -259,6 +270,7 @@ function EnhanceSelect(_a) {
259
270
  getRemoteDataHandle,
260
271
  restProps.value,
261
272
  firstLoading,
273
+ isRemoteSearchDataKey,
262
274
  setFirstLoading,
263
275
  ]);
264
276
  // 数据合并
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkui",
3
- "version": "2.0.3",
3
+ "version": "2.0.8",
4
4
  "private": false,
5
5
  "description": "React components library",
6
6
  "author": "zt-front-end",