@zat-design/sisyphus-react 3.14.6 → 3.14.7

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/.yarnrc ADDED
@@ -0,0 +1 @@
1
+ --ignore-engines true
@@ -96,10 +96,11 @@ export function useRequestList(service, options, useRequestOptions) {
96
96
  }, [onPageChange]);
97
97
  var onSearch = useCallback(values => {
98
98
  if (!isEqual(searchValues, values)) {
99
- onChange(defaultPage.pageNum, defaultPage.pageSize);
99
+ // 保留当前页码和每页条数
100
+ onChange(page.pageNum, page.pageSize);
100
101
  setSearchValues(values);
101
102
  }
102
- }, [onChange, searchValues]);
103
+ }, [onChange, searchValues, page]);
103
104
 
104
105
  // 重置查询条件
105
106
  var onReset = useCallback(() => {
@@ -21,7 +21,22 @@ import locale from "../locale";
21
21
  import { getSelectList } from "./utils";
22
22
  import "./index.less";
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
- var Option = _Select.Option;
24
+ var Option = _Select.Option,
25
+ OptGroup = _Select.OptGroup;
26
+
27
+ /** 将 selectList(扁平或分组)转为扁平选项列表,用于查找、回显、defaultOne */
28
+ function flattenOptions(list) {
29
+ if (!Array.isArray(list) || !list.length) return [];
30
+ var out = [];
31
+ list.forEach(item => {
32
+ if (Array.isArray(item.options)) {
33
+ out.push(...item.options);
34
+ } else {
35
+ out.push(item);
36
+ }
37
+ });
38
+ return out;
39
+ }
25
40
  export var ProSelect = (props, ref) => {
26
41
  var _selectProps$showCode, _useRequest$options3, _locale$ProSelect;
27
42
  var _ref = useProConfig('ProSelect') || {},
@@ -122,16 +137,17 @@ export var ProSelect = (props, ref) => {
122
137
  }
123
138
  }));
124
139
  var cacheList = useRequest !== null && useRequest !== void 0 && (_useRequest$options3 = useRequest.options) !== null && _useRequest$options3 !== void 0 && _useRequest$options3.cacheKey ? successTransformDataHandle(fetchFunction === null || fetchFunction === void 0 ? void 0 : fetchFunction.data) : [];
140
+ var flatOptions = flattenOptions(selectList);
125
141
  var getValueObject = input => {
126
142
  if (Array.isArray(input) && input.length) {
127
143
  var resArr = [];
128
144
  input.forEach(i => {
129
- var res = selectList.find(item => item[code] === i);
145
+ var res = flatOptions.find(item => item[code] === i);
130
146
  if (res) resArr.push(res);
131
147
  });
132
148
  return resArr;
133
149
  }
134
- return selectList.find(item => item[code] === input);
150
+ return flatOptions.find(item => item[code] === input);
135
151
  };
136
152
  useImperativeHandle(ref, () => ({
137
153
  getValueObject,
@@ -176,11 +192,11 @@ export var ProSelect = (props, ref) => {
176
192
  });
177
193
  }
178
194
  var transToLabel = value => {
179
- if (!Array.isArray(selectList) || !selectList.length) {
195
+ if (!flatOptions.length) {
180
196
  return viewEmpty;
181
197
  }
182
198
  var labelList = value.map(v => {
183
- var option = selectList.find(item => {
199
+ var option = flatOptions.find(item => {
184
200
  if (labelInValue) {
185
201
  return item[code] === v[code];
186
202
  }
@@ -192,7 +208,7 @@ export var ProSelect = (props, ref) => {
192
208
  return '-';
193
209
  });
194
210
  var record = value.map(v => {
195
- return selectList.find(item => {
211
+ return flatOptions.find(item => {
196
212
  if (labelInValue) {
197
213
  return item[code] === v[code];
198
214
  }
@@ -291,8 +307,7 @@ export var ProSelect = (props, ref) => {
291
307
  return undefined;
292
308
  }
293
309
  if (defaultOne && !value && !isDefaultOne) {
294
- var option = selectList === null || selectList === void 0 ? void 0 : selectList[0];
295
- // selectList 可能是异步回来的值
310
+ var option = flatOptions[0];
296
311
  if (option) {
297
312
  setIsDefaultOne(true);
298
313
  onChange === null || onChange === void 0 || onChange(option === null || option === void 0 ? void 0 : option[code], option);
@@ -328,6 +343,7 @@ export var ProSelect = (props, ref) => {
328
343
  showSearch: true,
329
344
  filterOption: isFunction(_onSearch) ? false : (input, option) => {
330
345
  var _option$children;
346
+ if ((option === null || option === void 0 ? void 0 : option.value) == null) return false;
331
347
  var value = isString(option === null || option === void 0 ? void 0 : option.children) ? option === null || option === void 0 ? void 0 : option.children : option === null || option === void 0 || (_option$children = option.children) === null || _option$children === void 0 || (_option$children = _option$children.props) === null || _option$children === void 0 ? void 0 : _option$children.title;
332
348
  return value.toLowerCase().includes(input.toLowerCase());
333
349
  },
@@ -339,7 +355,28 @@ export var ProSelect = (props, ref) => {
339
355
  }
340
356
  }, omit(_objectSpread({}, selectProps), ['isView', 'showCodeName', 'form', 'name', 'style', 'onFieldChange'])), {}, {
341
357
  value: transformValue(),
342
- children: Array.isArray(newSelectList) && newSelectList.map(item => {
358
+ children: Array.isArray(newSelectList) && newSelectList.map((item, idx) => {
359
+ var groupOpts = item.options;
360
+ if (Array.isArray(groupOpts)) {
361
+ var _item$label;
362
+ return /*#__PURE__*/_jsx(OptGroup, {
363
+ label: item[label],
364
+ children: groupOpts.map(opt => /*#__PURE__*/_jsx(Option, {
365
+ label: opt[label],
366
+ value: opt[code],
367
+ record: opt,
368
+ disabled: !!opt.disabled,
369
+ children: /*#__PURE__*/_jsx(TooltipOption, {
370
+ title: OptionRender ? OptionRender(opt) : selectProps.showCodeName ? `${opt[code]}-${opt[label]}` : opt[label],
371
+ children: OptionRender ? /*#__PURE__*/_jsx("span", {
372
+ children: OptionRender(opt)
373
+ }) : /*#__PURE__*/_jsx("span", {
374
+ children: selectProps.showCodeName ? `${opt[code]}-${opt[label]}` : opt[label]
375
+ })
376
+ })
377
+ }, opt[code]))
378
+ }, (_item$label = item[label]) !== null && _item$label !== void 0 ? _item$label : `group-${idx}`);
379
+ }
343
380
  return /*#__PURE__*/_jsx(Option, {
344
381
  label: item[label],
345
382
  value: item[code],
@@ -105,10 +105,11 @@ function useRequestList(service, options, useRequestOptions) {
105
105
  }, [onPageChange]);
106
106
  var onSearch = (0, _react.useCallback)(values => {
107
107
  if (!(0, _lodash.isEqual)(searchValues, values)) {
108
- onChange(defaultPage.pageNum, defaultPage.pageSize);
108
+ // 保留当前页码和每页条数
109
+ onChange(page.pageNum, page.pageSize);
109
110
  setSearchValues(values);
110
111
  }
111
- }, [onChange, searchValues]);
112
+ }, [onChange, searchValues, page]);
112
113
 
113
114
  // 重置查询条件
114
115
  var onReset = (0, _react.useCallback)(() => {
@@ -29,7 +29,22 @@ var _utils = require("./utils");
29
29
  require("./index.less");
30
30
  var _jsxRuntime = require("react/jsx-runtime");
31
31
  var _excluded = ["dataSource", "defaultDisableValue", "useRequest", "fieldNames", "tooltip", "otherProps", "labelInValue", "filterInList", "scrollFollowParent", "defaultOne", "onSearch", "optionRender", "onChange", "updateDataSource", "transformResponse", "getValueProps", "isView"];
32
- var Option = _select.default.Option;
32
+ var Option = _select.default.Option,
33
+ OptGroup = _select.default.OptGroup;
34
+
35
+ /** 将 selectList(扁平或分组)转为扁平选项列表,用于查找、回显、defaultOne */
36
+ function flattenOptions(list) {
37
+ if (!Array.isArray(list) || !list.length) return [];
38
+ var out = [];
39
+ list.forEach(item => {
40
+ if (Array.isArray(item.options)) {
41
+ out.push(...item.options);
42
+ } else {
43
+ out.push(item);
44
+ }
45
+ });
46
+ return out;
47
+ }
33
48
  var ProSelect = (props, ref) => {
34
49
  var _selectProps$showCode, _useRequest$options3, _locale$ProSelect;
35
50
  var _ref = (0, _ProConfigProvider.useProConfig)('ProSelect') || {},
@@ -130,16 +145,17 @@ var ProSelect = (props, ref) => {
130
145
  }
131
146
  }));
132
147
  var cacheList = useRequest !== null && useRequest !== void 0 && (_useRequest$options3 = useRequest.options) !== null && _useRequest$options3 !== void 0 && _useRequest$options3.cacheKey ? successTransformDataHandle(fetchFunction === null || fetchFunction === void 0 ? void 0 : fetchFunction.data) : [];
148
+ var flatOptions = flattenOptions(selectList);
133
149
  var getValueObject = input => {
134
150
  if (Array.isArray(input) && input.length) {
135
151
  var resArr = [];
136
152
  input.forEach(i => {
137
- var res = selectList.find(item => item[code] === i);
153
+ var res = flatOptions.find(item => item[code] === i);
138
154
  if (res) resArr.push(res);
139
155
  });
140
156
  return resArr;
141
157
  }
142
- return selectList.find(item => item[code] === input);
158
+ return flatOptions.find(item => item[code] === input);
143
159
  };
144
160
  (0, _react.useImperativeHandle)(ref, () => ({
145
161
  getValueObject,
@@ -184,11 +200,11 @@ var ProSelect = (props, ref) => {
184
200
  });
185
201
  }
186
202
  var transToLabel = value => {
187
- if (!Array.isArray(selectList) || !selectList.length) {
203
+ if (!flatOptions.length) {
188
204
  return viewEmpty;
189
205
  }
190
206
  var labelList = value.map(v => {
191
- var option = selectList.find(item => {
207
+ var option = flatOptions.find(item => {
192
208
  if (labelInValue) {
193
209
  return item[code] === v[code];
194
210
  }
@@ -200,7 +216,7 @@ var ProSelect = (props, ref) => {
200
216
  return '-';
201
217
  });
202
218
  var record = value.map(v => {
203
- return selectList.find(item => {
219
+ return flatOptions.find(item => {
204
220
  if (labelInValue) {
205
221
  return item[code] === v[code];
206
222
  }
@@ -299,8 +315,7 @@ var ProSelect = (props, ref) => {
299
315
  return undefined;
300
316
  }
301
317
  if (defaultOne && !value && !isDefaultOne) {
302
- var option = selectList === null || selectList === void 0 ? void 0 : selectList[0];
303
- // selectList 可能是异步回来的值
318
+ var option = flatOptions[0];
304
319
  if (option) {
305
320
  setIsDefaultOne(true);
306
321
  onChange === null || onChange === void 0 || onChange(option === null || option === void 0 ? void 0 : option[code], option);
@@ -336,6 +351,7 @@ var ProSelect = (props, ref) => {
336
351
  showSearch: true,
337
352
  filterOption: (0, _lodash.isFunction)(_onSearch) ? false : (input, option) => {
338
353
  var _option$children;
354
+ if ((option === null || option === void 0 ? void 0 : option.value) == null) return false;
339
355
  var value = (0, _lodash.isString)(option === null || option === void 0 ? void 0 : option.children) ? option === null || option === void 0 ? void 0 : option.children : option === null || option === void 0 || (_option$children = option.children) === null || _option$children === void 0 || (_option$children = _option$children.props) === null || _option$children === void 0 ? void 0 : _option$children.title;
340
356
  return value.toLowerCase().includes(input.toLowerCase());
341
357
  },
@@ -347,7 +363,28 @@ var ProSelect = (props, ref) => {
347
363
  }
348
364
  }, (0, _lodash.omit)((0, _objectSpread2.default)({}, selectProps), ['isView', 'showCodeName', 'form', 'name', 'style', 'onFieldChange'])), {}, {
349
365
  value: transformValue(),
350
- children: Array.isArray(newSelectList) && newSelectList.map(item => {
366
+ children: Array.isArray(newSelectList) && newSelectList.map((item, idx) => {
367
+ var groupOpts = item.options;
368
+ if (Array.isArray(groupOpts)) {
369
+ var _item$label;
370
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(OptGroup, {
371
+ label: item[label],
372
+ children: groupOpts.map(opt => /*#__PURE__*/(0, _jsxRuntime.jsx)(Option, {
373
+ label: opt[label],
374
+ value: opt[code],
375
+ record: opt,
376
+ disabled: !!opt.disabled,
377
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(TooltipOption, {
378
+ title: OptionRender ? OptionRender(opt) : selectProps.showCodeName ? `${opt[code]}-${opt[label]}` : opt[label],
379
+ children: OptionRender ? /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
380
+ children: OptionRender(opt)
381
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
382
+ children: selectProps.showCodeName ? `${opt[code]}-${opt[label]}` : opt[label]
383
+ })
384
+ })
385
+ }, opt[code]))
386
+ }, (_item$label = item[label]) !== null && _item$label !== void 0 ? _item$label : `group-${idx}`);
387
+ }
351
388
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Option, {
352
389
  label: item[label],
353
390
  value: item[code],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "3.14.6",
3
+ "version": "3.14.7",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": ">=18.19.0"
@@ -55,12 +55,14 @@
55
55
  "overrides": {
56
56
  "react-resizable": {
57
57
  "react-draggable": "4.4.3"
58
- }
58
+ },
59
+ "minimatch": "^9.0.0"
59
60
  },
60
61
  "resolutions": {
61
62
  "@types/react": "^17.0.53",
62
63
  "mockjs/commander": "9.2.0",
63
- "react-draggable": "4.4.3"
64
+ "react-draggable": "4.4.3",
65
+ "minimatch": "^9.0.0"
64
66
  },
65
67
  "dependencies": {
66
68
  "@ant-design/icons": "^4.2.2",