@arim-aisdc/public-components 2.3.21 → 2.3.23

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.
@@ -42,7 +42,7 @@ var CenterModal = function CenterModal(_ref) {
42
42
  _ref$confirmLoading = _ref.confirmLoading,
43
43
  confirmLoading = _ref$confirmLoading === void 0 ? false : _ref$confirmLoading,
44
44
  _ref$maskClosable = _ref.maskClosable,
45
- maskClosable = _ref$maskClosable === void 0 ? true : _ref$maskClosable,
45
+ maskClosable = _ref$maskClosable === void 0 ? false : _ref$maskClosable,
46
46
  _ref$bodyStyle = _ref.bodyStyle,
47
47
  bodyStyle = _ref$bodyStyle === void 0 ? {
48
48
  position: 'relative'
@@ -57,6 +57,23 @@ var Filter = function Filter(_ref) {
57
57
  setColumnFilterValue(newValue);
58
58
  column.setFilterValue(newValue);
59
59
  };
60
+ // 修改表格SingleSelect 筛选参数
61
+ var handleChangeSelectFilterValue = function handleChangeSelectFilterValue(value, inputSearchValue) {
62
+ var newValue = value;
63
+ if (value === null || Array.isArray(value) && value.length === 0) {
64
+ // 值为null或空数组时,清除过滤条件。
65
+ newValue = undefined;
66
+ }
67
+ // console.log('handleChangeFilterValue :>> ', newValue);
68
+ setColumnFilterValue(!value ? undefined : {
69
+ filterValue: newValue,
70
+ optionsParam: inputSearchValue
71
+ });
72
+ column.setFilterValue(!value ? undefined : {
73
+ filterValue: newValue,
74
+ optionsParam: inputSearchValue
75
+ });
76
+ };
60
77
 
61
78
  // 修改表格筛选参数(防抖)
62
79
  var changeFilterValueWithDebounce = useCallback(debounce(function (value) {
@@ -148,7 +165,9 @@ var Filter = function Filter(_ref) {
148
165
  useEffect(function () {
149
166
  if ([FilterType.MultiSelect, FilterType.SingleSelect].includes(filterType)) {
150
167
  // 打开后自动获取可选值
151
- fetchOptions('');
168
+ var _ref3 = columnFilterValue || {},
169
+ optionsParam = _ref3.optionsParam;
170
+ fetchOptions(optionsParam);
152
171
  }
153
172
  }, []);
154
173
  var filterComponent = function filterComponent(type) {
@@ -252,7 +271,7 @@ var Filter = function Filter(_ref) {
252
271
  case FilterType.SingleSelect:
253
272
  return /*#__PURE__*/_jsx(SingleSelect, {
254
273
  value: columnFilterValue,
255
- onChange: handleChangeFilterValue,
274
+ onChange: handleChangeSelectFilterValue,
256
275
  onSearch: onSearch,
257
276
  options: options,
258
277
  isFrontSearch: isFilterOptionsFrontSearch,
@@ -92,7 +92,8 @@ var MultipleSelect = function MultipleSelect(_ref) {
92
92
  className: "tableMax-filter-multipleSelect-header",
93
93
  children: /*#__PURE__*/_jsx(Input, {
94
94
  placeholder: t('global.placeholder.input'),
95
- onChange: handleInputChange
95
+ onChange: handleInputChange,
96
+ allowClear: true
96
97
  })
97
98
  }), /*#__PURE__*/_jsx("div", {
98
99
  className: "tableMax-filter-multipleSelect-body",
@@ -1,8 +1,11 @@
1
1
  import './index.less';
2
2
  interface IProps {
3
- value: string | number | undefined;
3
+ value: {
4
+ filterValue?: string;
5
+ optionsParam?: string;
6
+ } | undefined;
4
7
  options: any[];
5
- onChange: (value: string | number | undefined) => void;
8
+ onChange: (value: string | number | undefined, inputValue?: string) => void;
6
9
  onSearch: (value: string) => void;
7
10
  isFrontSearch: boolean;
8
11
  loading: boolean;
@@ -5,9 +5,8 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
5
5
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import { useTranslation } from "../../../../../hooks/useTranslation";
8
- import { useUpdateEffect } from 'ahooks';
9
8
  import { Button, Input, Spin } from 'antd';
10
- import { useMemo, useState } from 'react';
9
+ import { useEffect, useMemo, useRef, useState } from 'react';
11
10
  import "./index.less";
12
11
  import { jsx as _jsx } from "react/jsx-runtime";
13
12
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -20,64 +19,104 @@ var SingleSelect = function SingleSelect(_ref) {
20
19
  isFrontSearch = _ref.isFrontSearch,
21
20
  loading = _ref.loading,
22
21
  onCloseFilterPanel = _ref.onCloseFilterPanel;
23
- // 内部state
24
- var _useState = useState(value),
25
- _useState2 = _slicedToArray(_useState, 2),
26
- innerValue = _useState2[0],
27
- setInnerValue = _useState2[1];
28
22
  var _useTranslation = useTranslation(),
29
23
  _useTranslation2 = _slicedToArray(_useTranslation, 1),
30
24
  t = _useTranslation2[0];
31
-
32
- // 前端搜索输入值
33
- var _useState3 = useState(''),
25
+ var _ref2 = value || {},
26
+ filterValue = _ref2.filterValue,
27
+ optionsParam = _ref2.optionsParam;
28
+ // 列筛选 最终筛选值
29
+ var _useState = useState(filterValue),
30
+ _useState2 = _slicedToArray(_useState, 2),
31
+ innerValue = _useState2[0],
32
+ setInnerValue = _useState2[1];
33
+ // 列筛选可选值列表的筛选参数
34
+ var _useState3 = useState(optionsParam),
34
35
  _useState4 = _slicedToArray(_useState3, 2),
35
- frontendSearchValue = _useState4[0],
36
- setFrontendSearchValue = _useState4[1];
36
+ inputSearchValue = _useState4[0],
37
+ setInputSearchValue = _useState4[1];
38
+ // 列筛选-前端筛选可选值列表
39
+ var _useState5 = useState([]),
40
+ _useState6 = _slicedToArray(_useState5, 2),
41
+ frontendOptions = _useState6[0],
42
+ setFrontendOptions = _useState6[1];
43
+ var isFirstScroll = useRef(true);
37
44
  var handleClick = function handleClick(changedValue) {
38
45
  console.log('changedValue :>> ', changedValue);
39
46
  setInnerValue(changedValue);
40
47
  };
41
48
  var handleConfirm = function handleConfirm() {
42
- onChange(innerValue);
49
+ onChange(innerValue, inputSearchValue);
43
50
  onCloseFilterPanel();
44
51
  };
45
52
  var handleReset = function handleReset() {
46
53
  setInnerValue(undefined);
47
- onChange(undefined);
54
+ setInputSearchValue(undefined);
55
+ onChange(undefined, undefined);
48
56
  };
49
- useUpdateEffect(function () {
50
- // console.log('value :>> ', value);
51
- setInnerValue(value);
57
+ useEffect(function () {
58
+ console.log('value :>> ', value);
59
+ var _ref3 = value || {},
60
+ filterValue = _ref3.filterValue,
61
+ optionsParam = _ref3.optionsParam;
62
+ setInnerValue(filterValue);
63
+ setInputSearchValue(optionsParam);
64
+ if (!isFrontSearch) {
65
+ onSearch(optionsParam);
66
+ }
52
67
  }, [value]);
53
68
  var handleInputChange = function handleInputChange(e) {
54
69
  var value = e.target.value;
70
+ setInputSearchValue(value);
55
71
  if (!isFrontSearch) {
56
72
  onSearch(value);
57
- } else {
58
- setFrontendSearchValue(value);
59
73
  }
60
74
  };
75
+ // 首次加载,已选item滚动到可视区
76
+ useEffect(function () {
77
+ if (!value || !value.filterValue || !options || Array.isArray(options) && options.length === 0 || !isFirstScroll.current) return;
78
+ // 滚动到选中的项目
79
+ function scrollToSelectedItem() {
80
+ var selectedElement = document.querySelector(".item[data-id=".concat(value.filterValue, "]"));
81
+ if (!selectedElement) return;
82
+ isFirstScroll.current = false;
83
+ if (selectedElement) {
84
+ selectedElement.scrollIntoView({
85
+ behavior: 'smooth',
86
+ block: 'center'
87
+ });
88
+ }
89
+ }
90
+ var timer = setTimeout(function () {
91
+ return scrollToSelectedItem();
92
+ }, 100);
93
+ return function () {
94
+ clearTimeout(timer);
95
+ };
96
+ }, [options, value]);
61
97
 
62
98
  // 最终的可选值
63
99
  var finalOptions = useMemo(function () {
64
100
  if (!isFrontSearch) {
65
101
  return options;
66
102
  }
67
- var input = (frontendSearchValue !== null && frontendSearchValue !== void 0 ? frontendSearchValue : '').toUpperCase().trim();
103
+ var input = (inputSearchValue !== null && inputSearchValue !== void 0 ? inputSearchValue : '').toUpperCase().trim();
68
104
  return options.filter(function (option) {
69
105
  var _option$label;
70
106
  var optionFilterString = ('' + ((_option$label = option.label) !== null && _option$label !== void 0 ? _option$label : option.children)).toUpperCase().trim();
71
107
  return optionFilterString.indexOf(input) !== -1;
72
108
  });
73
- }, [options, frontendSearchValue]);
109
+ }, [options, inputSearchValue]);
74
110
  return /*#__PURE__*/_jsxs("div", {
75
111
  className: "tableMax-filter-singleSelect",
76
112
  children: [/*#__PURE__*/_jsx("div", {
77
113
  className: "tableMax-filter-singleSelect-header",
78
114
  children: /*#__PURE__*/_jsx(Input, {
115
+ defaultValue: inputSearchValue,
116
+ value: inputSearchValue,
79
117
  placeholder: t('global.placeholder.input'),
80
- onChange: handleInputChange
118
+ onChange: handleInputChange,
119
+ allowClear: true
81
120
  })
82
121
  }), /*#__PURE__*/_jsx("div", {
83
122
  className: "tableMax-filter-singleSelect-body",
@@ -87,6 +126,7 @@ var SingleSelect = function SingleSelect(_ref) {
87
126
  }) : finalOptions.map(function (option) {
88
127
  var _option$label2;
89
128
  return /*#__PURE__*/_jsx("div", {
129
+ "data-id": option.value,
90
130
  className: "item ".concat(innerValue === option.value ? 'selected' : ''),
91
131
  onClick: function onClick() {
92
132
  return handleClick(option.value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arim-aisdc/public-components",
3
- "version": "2.3.21",
3
+ "version": "2.3.23",
4
4
  "description": "前端组件库",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",