ztxkui 4.2.18-101 → 4.2.18-103

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.
Files changed (59) hide show
  1. package/dist/UI/Form/index.js +1 -0
  2. package/dist/UI/InputNumber/index.d.ts +3 -0
  3. package/dist/UI/InputNumber/index.js +45 -0
  4. package/dist/UI/TreeSelect/index.d.ts +3 -0
  5. package/dist/UI/TreeSelect/index.js +78 -0
  6. package/dist/UI/index.js +9 -1
  7. package/dist/components/Button/button.d.ts +6 -0
  8. package/dist/components/Button/button.js +8 -2
  9. package/dist/components/EnhanceTreeSelect/index.d.ts +5 -1
  10. package/dist/components/EnhanceTreeSelect/index.js +31 -3
  11. package/dist/components/Form/form.d.ts +11 -1
  12. package/dist/components/Form/form.js +5 -3
  13. package/dist/components/ProForm/index.d.ts +3 -0
  14. package/dist/components/ProForm/index.js +78 -11
  15. package/dist/components/ProForm/interface.d.ts +31 -0
  16. package/dist/components/ProForm/item.js +2 -1
  17. package/dist/components/ProForm/record-common-list.d.ts +18 -0
  18. package/dist/components/ProForm/record-common-list.js +83 -0
  19. package/dist/components/ProForm/search-drawer.d.ts +2 -0
  20. package/dist/components/ProForm/search-drawer.js +48 -13
  21. package/dist/components/ProForm/setting.js +6 -7
  22. package/dist/components/ProForm/useCommonSearch.d.ts +35 -0
  23. package/dist/components/ProForm/useCommonSearch.js +352 -0
  24. package/dist/components/Table/table-dynamic.d.ts +1 -0
  25. package/dist/components/Table/table-dynamic.js +191 -30
  26. package/dist/components/Table/table.js +1 -1
  27. package/dist/components/TreeSelect/index.d.ts +4 -0
  28. package/dist/components/TreeSelect/index.js +47 -2
  29. package/dist/components/ZtIcon/index.js +2 -0
  30. package/dist/components/business/SearchContainer/hooks/useDynamic.d.ts +2 -1
  31. package/dist/components/business/SearchContainer/hooks/useDynamic.js +6 -3
  32. package/dist/components/business/SearchContainer/hooks/useToggle.d.ts +1 -1
  33. package/dist/components/business/SearchContainer/hooks/useToggle.js +28 -10
  34. package/dist/components/business/SearchContainer/record-common-item.js +3 -2
  35. package/dist/components/business/SearchContainer/record-common-list.js +41 -10
  36. package/dist/components/business/SearchContainer/search-container.d.ts +9 -0
  37. package/dist/components/business/SearchContainer/search-container.js +53 -19
  38. package/dist/components/business/SearchContainer/search-drawer.js +38 -10
  39. package/dist/components/business/SearchContainer/search-left.d.ts +7 -0
  40. package/dist/components/business/SearchContainer/search-left.js +103 -74
  41. package/dist/components/business/SearchContainer/search-right.d.ts +4 -0
  42. package/dist/components/business/SearchContainer/search-right.js +53 -15
  43. package/dist/components/business/SearchContainer/useRecordCommonInit.d.ts +4 -1
  44. package/dist/components/business/SearchContainer/useRecordCommonInit.js +37 -21
  45. package/dist/components/business/SearchContainer/useRecordCommonSearch.d.ts +1 -0
  46. package/dist/components/business/SearchContainer/useRecordCommonSearch.js +21 -16
  47. package/dist/components/business/SearchContainer/useRecordCommonSearchContext.d.ts +8 -2
  48. package/dist/components/business/SearchContainer/useTemplate.d.ts +20 -0
  49. package/dist/components/business/SearchContainer/useTemplate.js +347 -0
  50. package/dist/components/utils/ZtxkContext.d.ts +8 -0
  51. package/dist/components/utils/ZtxkContext.js +2 -0
  52. package/dist/components/utils/index.d.ts +9 -0
  53. package/dist/components/utils/index.js +11 -0
  54. package/dist/components/utils/useBaseContext.d.ts +14 -1
  55. package/dist/components/utils/useBaseContext.js +23 -2
  56. package/dist/index.css +329 -63
  57. package/dist/index.css.map +1 -1
  58. package/dist/index.js +8 -0
  59. package/package.json +1 -1
@@ -0,0 +1,83 @@
1
+ import i18next from 'ztxkutils/dist/i18next';
2
+ import React from 'react';
3
+ import { Popconfirm } from '../../index';
4
+ import { DeleteOutlined } from '@ant-design/icons';
5
+ import classNames from 'classnames';
6
+ import { DndProvider } from 'react-dnd';
7
+ import { HTML5Backend } from 'react-dnd-html5-backend';
8
+ import RecordCommonItem from '../business/SearchContainer/record-common-item';
9
+ import useMemoizedFn from '../utils/useMemoizedFn';
10
+ import update from 'immutability-helper';
11
+ import { setDynamicKey } from './hooks';
12
+ var RecordCommonList = function (props) {
13
+ var recordCommonList = props.recordCommonList, currentRecordCommonSearchKey = props.currentRecordCommonSearchKey, setCurrentRecordCommonSearchKey = props.setCurrentRecordCommonSearchKey, form = props.form, reTransformData = props.reTransformData, deleteData = props.deleteData, setReplaceData = props.setReplaceData, updateServerData = props.updateServerData, onSearchHandle = props.onSearchHandle, setCurrentDynamicList = props.setCurrentDynamicList, showDynamicKey = props.showDynamicKey;
14
+ var handleClick = function (item) {
15
+ if (currentRecordCommonSearchKey === item.key) {
16
+ setCurrentRecordCommonSearchKey === null || setCurrentRecordCommonSearchKey === void 0 ? void 0 : setCurrentRecordCommonSearchKey('');
17
+ return;
18
+ }
19
+ setCurrentRecordCommonSearchKey === null || setCurrentRecordCommonSearchKey === void 0 ? void 0 : setCurrentRecordCommonSearchKey(item.key);
20
+ // 更新动态列配置
21
+ if (showDynamicKey && item.dynamicList) {
22
+ setCurrentDynamicList === null || setCurrentDynamicList === void 0 ? void 0 : setCurrentDynamicList(item.dynamicList || []);
23
+ setDynamicKey(showDynamicKey, item.dynamicList || '', {
24
+ isNotSaveToServer: true,
25
+ });
26
+ }
27
+ setTimeout(function () {
28
+ // 更新动态列配置
29
+ var formData = reTransformData === null || reTransformData === void 0 ? void 0 : reTransformData(item.value, item.timeKeys);
30
+ item.dynamicList.forEach(function (formItem) {
31
+ if (formItem.show) {
32
+ if (formData.hasOwnProperty(formItem.name)) {
33
+ // 只要 formData 里有这个字段(包括 null 或空字符串),就保留;否则置为 undefined
34
+ formData[formItem.name] = formData[formItem.name];
35
+ }
36
+ else {
37
+ formData[formItem.name] = undefined;
38
+ }
39
+ }
40
+ });
41
+ form === null || form === void 0 ? void 0 : form.setFieldsValue(formData);
42
+ // 触发查询事件
43
+ onSearchHandle === null || onSearchHandle === void 0 ? void 0 : onSearchHandle();
44
+ }, 100);
45
+ };
46
+ var deleteItem = function (index) {
47
+ deleteData === null || deleteData === void 0 ? void 0 : deleteData(index);
48
+ };
49
+ var onMoveItem = useMemoizedFn(function (dragIndex, hoverIndex) {
50
+ // 由于对于固定列,不能进行拖拽排序,所以需要找出所有包含固定列的属性出来
51
+ var dragCard = recordCommonList[dragIndex];
52
+ var currentList = update(recordCommonList, {
53
+ $splice: [
54
+ [dragIndex, 1],
55
+ [hoverIndex, 0, dragCard],
56
+ ],
57
+ });
58
+ setReplaceData === null || setReplaceData === void 0 ? void 0 : setReplaceData(currentList);
59
+ });
60
+ var onMoveEnd = useMemoizedFn(function () {
61
+ updateServerData === null || updateServerData === void 0 ? void 0 : updateServerData();
62
+ });
63
+ return recordCommonList.length > 0 ? (React.createElement("div", { className: "record-common-list--container" },
64
+ React.createElement("div", { className: "record-common-list--title" }, i18next.t('常用搜索')),
65
+ React.createElement("div", { className: "record-common-list--item--container" },
66
+ React.createElement(DndProvider, { backend: HTML5Backend, context: window }, recordCommonList.map(function (item, index) { return (React.createElement(RecordCommonItem, { type: "record-common-item", key: item.key, onMoveItem: onMoveItem, onMoveEnd: onMoveEnd, index: index, className: classNames('record-common-list--item', {
67
+ 'record-common-list--item--active': currentRecordCommonSearchKey === item.key,
68
+ }), onClick: function () {
69
+ handleClick(item);
70
+ } },
71
+ React.createElement("div", { className: "record-common-list--item--title", title: item.title }, item.title),
72
+ React.createElement(Popconfirm, { title: i18next.t('确认删除吗?'), onConfirm: function (e) {
73
+ var _a, _b;
74
+ (_a = e === null || e === void 0 ? void 0 : e.preventDefault) === null || _a === void 0 ? void 0 : _a.call(e);
75
+ (_b = e === null || e === void 0 ? void 0 : e.stopPropagation) === null || _b === void 0 ? void 0 : _b.call(e);
76
+ deleteItem === null || deleteItem === void 0 ? void 0 : deleteItem(index);
77
+ if (item.key === currentRecordCommonSearchKey) {
78
+ setCurrentRecordCommonSearchKey === null || setCurrentRecordCommonSearchKey === void 0 ? void 0 : setCurrentRecordCommonSearchKey('');
79
+ }
80
+ }, onCancel: function (e) { var _a; return (_a = e === null || e === void 0 ? void 0 : e.stopPropagation) === null || _a === void 0 ? void 0 : _a.call(e); } },
81
+ React.createElement(DeleteOutlined, { onClick: function (e) { var _a; return (_a = e === null || e === void 0 ? void 0 : e.stopPropagation) === null || _a === void 0 ? void 0 : _a.call(e); }, className: "record-common-list--delete" })))); }))))) : null;
82
+ };
83
+ export default RecordCommonList;
@@ -7,6 +7,8 @@ interface IProps {
7
7
  onReset: () => void;
8
8
  dynamicList: ISearchLayout[];
9
9
  disabledHideItem?: boolean;
10
+ dynamicStorageKey?: string;
11
+ title?: string;
10
12
  }
11
13
  declare const _default: React.NamedExoticComponent<IProps>;
12
14
  export default _default;
@@ -15,16 +15,18 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
15
15
  return to;
16
16
  };
17
17
  import i18next from 'ztxkutils/dist/i18next';
18
- import React, { memo, useCallback, useMemo, useState, useEffect } from 'react';
18
+ import React, { memo, useCallback, useMemo, useState, useEffect, useRef, } from 'react';
19
19
  import { SettingOutlined } from '@ant-design/icons';
20
20
  import { Drawer, Button, Sortable, Checkbox, SortableCancel, Input, message, } from '../../index';
21
21
  import { DndProvider, useDrop } from 'react-dnd';
22
22
  import { HTML5Backend } from 'react-dnd-html5-backend';
23
23
  import update from 'immutability-helper';
24
+ import throttle from 'lodash/throttle';
24
25
  var typeSymbol = Symbol('search-drawer');
25
26
  var SearchDrawer = function (_a) {
26
- var visible = _a.visible, onClose = _a.onClose, onReset = _a.onReset, onSure = _a.onSure, dynamicList = _a.dynamicList, disabledHideItem = _a.disabledHideItem;
27
- var _b = useState(dynamicList), innerDynamicList = _b[0], setInnerDynamicList = _b[1];
27
+ var _b;
28
+ var visible = _a.visible, onClose = _a.onClose, onReset = _a.onReset, onSure = _a.onSure, dynamicList = _a.dynamicList, disabledHideItem = _a.disabledHideItem, dynamicStorageKey = _a.dynamicStorageKey, title = _a.title;
29
+ var _c = useState(dynamicList), innerDynamicList = _c[0], setInnerDynamicList = _c[1];
28
30
  useEffect(function () {
29
31
  setInnerDynamicList(dynamicList);
30
32
  }, [dynamicList]);
@@ -37,8 +39,8 @@ var SearchDrawer = function (_a) {
37
39
  });
38
40
  return _checkedValues;
39
41
  }, [innerDynamicList]);
40
- var _c = useState(null), filterDynamicColumns = _c[0], setFilterDynamicColumns = _c[1];
41
- var _d = useState([]), filterCheckedValues = _d[0], setFilterCheckedValues = _d[1];
42
+ var _d = useState(null), filterDynamicColumns = _d[0], setFilterDynamicColumns = _d[1];
43
+ var _e = useState([]), filterCheckedValues = _e[0], setFilterCheckedValues = _e[1];
42
44
  var onFindItemHandle = useCallback(function (id) {
43
45
  var dragItem = innerDynamicList === null || innerDynamicList === void 0 ? void 0 : innerDynamicList.filter(function (c) { return "" + c.name === id; })[0];
44
46
  return {
@@ -176,26 +178,59 @@ var SearchDrawer = function (_a) {
176
178
  setFilterCheckedValues(checkedValues.filter(function (key) { return !filterColumns.find(function (column) { return column.name === key; }); }));
177
179
  setFilterDynamicColumns(filterColumns);
178
180
  };
181
+ var onSearchHandleThrottle = useCallback(throttle(function (e) {
182
+ onSearchHandle(e.target.value);
183
+ }, 500, { trailing: true }), [onSearchHandle]);
179
184
  return (React.createElement(Drawer, { className: "search-drawer", title: React.createElement("div", null,
180
185
  React.createElement(SettingOutlined, { style: { fontSize: 16 } }),
181
186
  React.createElement("span", { className: "search-drawer--title-text" },
182
- i18next.t('查询条件自定义'),
187
+ title ? title : i18next.t('查询条件自定义'),
183
188
  React.createElement("span", null, i18next.t('(拖拽排序)')))), width: 290, placement: "right", visible: visible, closable: false, maskClosable: false, footer: renderFooter() },
184
- React.createElement(DndProvider, { backend: HTML5Backend, context: window }, disabledHideItem ? (React.createElement(React.Fragment, null, innerDynamicList.map(function (item, index) { return (React.createElement(Sortable, { key: item.name, type: "search-drawer", index: index, onMoveItem: onMoveItem },
185
- React.createElement("div", null, item.label || item.name))); }))) : (React.createElement("div", { className: "search-drawer--filter" },
189
+ React.createElement(DndProvider, { backend: HTML5Backend, context: window }, disabledHideItem ? (React.createElement(React.Fragment, null, innerDynamicList.map(function (item, index) {
190
+ var isActive = filterDynamicColumns === null || filterDynamicColumns === void 0 ? void 0 : filterDynamicColumns.find(function (column) { return column.name === item.name; });
191
+ return (React.createElement(Sortable, { className: isActive ? 'active' : '', key: item.name, type: "search-drawer", index: index, onMoveItem: onMoveItem },
192
+ React.createElement("div", null, item.label || item.name)));
193
+ }))) : (React.createElement("div", { className: "search-drawer--filter" },
186
194
  React.createElement("div", { className: "search-drawer--filter-input" },
187
- React.createElement(Input.Search, { placeholder: i18next.t('搜索'), onSearch: onSearchHandle }),
195
+ React.createElement(Input.Search, { placeholder: i18next.t('搜索'), onChange: onSearchHandleThrottle, onSearch: onSearchHandle }),
188
196
  React.createElement(Button, { type: "default", className: "selector-all", loading: false, onClick: function () { return onCheckBtn('all'); } }, i18next.t('全选')),
189
197
  React.createElement(Button, { type: "default", className: "selector-inverse", loading: false, onClick: function () { return onCheckBtn('inverse'); } }, i18next.t('反选'))),
198
+ React.createElement("div", { className: "search-drawer--filter-count" }, filterDynamicColumns !== null
199
+ ? i18next.t('共 {{total}} 项,命中 {{count}} 项', {
200
+ total: innerDynamicList.length,
201
+ count: (_b = filterDynamicColumns === null || filterDynamicColumns === void 0 ? void 0 : filterDynamicColumns.length) !== null && _b !== void 0 ? _b : 0,
202
+ })
203
+ : i18next.t('共 {{total}} 项', {
204
+ total: innerDynamicList.length,
205
+ })),
190
206
  React.createElement(Checkbox.Group, { value: checkedValues, onChange: onCheckboxChange },
191
- React.createElement(Container, { dynamicColumns: filterDynamicColumns || innerDynamicList, onFindItemHandle: onFindItemHandle, onMoveItemHandle: onMoveItemHandle })))))));
207
+ React.createElement(Container
208
+ // dynamicColumns={filterDynamicColumns || innerDynamicList}
209
+ , {
210
+ // dynamicColumns={filterDynamicColumns || innerDynamicList}
211
+ dynamicColumns: innerDynamicList, filterDynamicColumns: filterDynamicColumns, onFindItemHandle: onFindItemHandle, onMoveItemHandle: onMoveItemHandle })))))));
192
212
  };
193
213
  function Container(_a) {
194
- var dynamicColumns = _a.dynamicColumns, onFindItemHandle = _a.onFindItemHandle, onMoveItemHandle = _a.onMoveItemHandle;
214
+ var dynamicColumns = _a.dynamicColumns, filterDynamicColumns = _a.filterDynamicColumns, onFindItemHandle = _a.onFindItemHandle, onMoveItemHandle = _a.onMoveItemHandle;
195
215
  var _b = useDrop(function () { return ({ accept: typeSymbol }); }), drop = _b[1];
196
- return (React.createElement("div", { ref: drop }, Array.isArray(dynamicColumns) &&
216
+ var containerRef = useRef(null);
217
+ // 搜索过滤变化时,滚动到第一个命中项
218
+ useEffect(function () {
219
+ if (filterDynamicColumns && filterDynamicColumns.length > 0) {
220
+ requestAnimationFrame(function () {
221
+ var _a;
222
+ var firstActive = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.zt-sortable.active');
223
+ firstActive === null || firstActive === void 0 ? void 0 : firstActive.scrollIntoView({ behavior: 'smooth', block: 'center' });
224
+ });
225
+ }
226
+ }, [filterDynamicColumns]);
227
+ return (React.createElement("div", { ref: function (node) {
228
+ drop(node);
229
+ containerRef.current = node;
230
+ } }, Array.isArray(dynamicColumns) &&
197
231
  dynamicColumns.map(function (item, index) {
198
- return item.name ? (React.createElement(SortableCancel, { type: typeSymbol, key: item.name, id: item.name, onFindItem: onFindItemHandle, onMoveItem: onMoveItemHandle, tipTitle: item.label || item.hiddenLabelName || item.name },
232
+ var isActive = filterDynamicColumns === null || filterDynamicColumns === void 0 ? void 0 : filterDynamicColumns.find(function (column) { return column.name === item.name; });
233
+ return item.name ? (React.createElement(SortableCancel, { className: isActive ? 'active' : '', type: typeSymbol, key: item.name, id: item.name, onFindItem: onFindItemHandle, onMoveItem: onMoveItemHandle, tipTitle: item.label || item.hiddenLabelName || item.name },
199
234
  React.createElement(Checkbox, { value: item.name, disabled: item.disabled || item.dynamicDisabled }, item.label || item.hiddenLabelName || item.name))) : null;
200
235
  })));
201
236
  }
@@ -1,13 +1,12 @@
1
- import React, { memo } from 'react';
2
- import { SettingOutlined } from '@ant-design/icons';
1
+ import React, { memo, useImperativeHandle } from 'react';
3
2
  import { useDrawer } from './hooks';
4
3
  import SearchDrawer from './search-drawer';
5
4
  function Setting(props) {
6
- var list = props.list, initList = props.initList, showDynamicKey = props.showDynamicKey, setCurrentDynamicList = props.setCurrentDynamicList;
5
+ var list = props.list, initList = props.initList, showDynamicKey = props.showDynamicKey, setCurrentDynamicList = props.setCurrentDynamicList, disabledHideItem = props.disabledHideItem, handleRef = props.handleRef, hideTemplateSetting = props.hideTemplateSetting, title = props.title;
7
6
  var _a = useDrawer(initList, setCurrentDynamicList, showDynamicKey), visible = _a.visible, setVisible = _a.setVisible, onClose = _a.onClose, onReset = _a.onReset, onSure = _a.onSure;
8
- return (React.createElement("div", { className: "pro-form__middle" },
9
- Array.isArray(list) && list.length ? (React.createElement("div", { className: "pro-form__middle--setting", onClick: function () { return setVisible(true); } },
10
- React.createElement(SettingOutlined, { style: { fontSize: 18, color: '#768696' } }))) : null,
11
- Array.isArray(list) && list.length ? (React.createElement(SearchDrawer, { visible: visible, onClose: onClose, onSure: onSure, onReset: onReset, dynamicList: list })) : null));
7
+ useImperativeHandle(handleRef, function () { return ({
8
+ open: function () { return setVisible(true); },
9
+ }); });
10
+ return (React.createElement(React.Fragment, null, Array.isArray(list) && list.length ? (React.createElement(SearchDrawer, { visible: visible, onClose: onClose, onSure: onSure, onReset: onReset, dynamicList: list, disabledHideItem: disabledHideItem, dynamicStorageKey: showDynamicKey, initDynamicArr: initList, hideTemplateSetting: hideTemplateSetting, title: title })) : null));
12
11
  }
13
12
  export default memo(Setting);
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { ISearchLayout } from './interface';
3
+ export declare const COMMON_SEARCH_KEY = "ztxk_form_common_record_search_key";
4
+ interface ICommonSearch {
5
+ /**
6
+ * 当前表单用哪个key来存储数据
7
+ */
8
+ commonSearchKey: string;
9
+ isCommonSearchEnabled?: boolean;
10
+ }
11
+ export declare function useCommonSearch(options: ICommonSearch): {
12
+ commonSearchList: any[];
13
+ setCommonSearchList: React.Dispatch<React.SetStateAction<any[]>>;
14
+ currentCommonSearchKey: string;
15
+ setCurrentCommonSearchKey: React.Dispatch<React.SetStateAction<string>>;
16
+ reTransformData: (data: any, timeKeys?: any) => any;
17
+ setData: (data: any) => Promise<void>;
18
+ deleteData: (localIndex: number) => Promise<void>;
19
+ setReplaceData: (data: any) => Promise<any>;
20
+ updateServerData: () => Promise<void>;
21
+ };
22
+ interface ICommonSearchModal {
23
+ commonSearchList?: any[];
24
+ currentCommonSearchKey?: string;
25
+ setCurrentCommonSearchKey?: any;
26
+ form?: any;
27
+ setData?: any;
28
+ isCommonSearchEnabled?: boolean;
29
+ currentDynamicList?: ISearchLayout[];
30
+ setCurrentDynamicList?: (list: ISearchLayout[]) => void;
31
+ }
32
+ export declare function useCommonSearchModal(options: ICommonSearchModal): {
33
+ onCommonSearchHandle: () => void;
34
+ };
35
+ export {};
@@ -0,0 +1,352 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (_) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import i18next from 'ztxkutils/dist/i18next';
49
+ import React, { useRef, useState, useEffect, forwardRef, useImperativeHandle, } from 'react';
50
+ import { Modal, message, Input } from '../../index';
51
+ import MyStorage from '../utils/MyStorage';
52
+ import dayjs from 'dayjs';
53
+ import { catchHandle } from '../utils/fetch';
54
+ export var COMMON_SEARCH_KEY = 'ztxk_form_common_record_search_key';
55
+ // 常用搜索hooks
56
+ export function useCommonSearch(options) {
57
+ var _this = this;
58
+ var commonSearchKey = options.commonSearchKey, isCommonSearchEnabled = options.isCommonSearchEnabled;
59
+ // 常用搜索列表存储实例
60
+ var storageRef = useRef(isCommonSearchEnabled
61
+ ? new MyStorage({ tableKey: COMMON_SEARCH_KEY })
62
+ : null);
63
+ // 常用搜索列表
64
+ var _a = useState([]), commonSearchList = _a[0], setCommonSearchList = _a[1];
65
+ // 当前选中的常用搜索key值
66
+ var _b = useState(''), currentCommonSearchKey = _b[0], setCurrentCommonSearchKey = _b[1];
67
+ // 初始化常用搜索列表
68
+ useEffect(function () {
69
+ if (commonSearchKey && storageRef.current) {
70
+ storageRef.current
71
+ .getItem(commonSearchKey)
72
+ .then(function (res) { return setCommonSearchList(res || []); });
73
+ }
74
+ }, []);
75
+ /**
76
+ * description: 数据转换。主要是将时间对象转成字符串
77
+ */
78
+ var transformData = function (data) {
79
+ // 处理数据,将数据中的时间对象做一下转换
80
+ var dataValue = data;
81
+ var newDataValue = {}; // 为了不影响之前的数据
82
+ var timeKeys = [];
83
+ if (dataValue) {
84
+ Object.keys(dataValue).forEach(function (key) {
85
+ var value = dataValue[key];
86
+ if (Array.isArray(value)) {
87
+ newDataValue[key] = [];
88
+ value.forEach(function (item) {
89
+ if (dayjs.isDayjs(item)) {
90
+ timeKeys.push(key);
91
+ newDataValue[key].push(dayjs(item).format('YYYY-MM-DD HH:mm:ss'));
92
+ }
93
+ else {
94
+ newDataValue[key].push(item);
95
+ }
96
+ });
97
+ }
98
+ else {
99
+ var itemIsDayjs = dayjs.isDayjs(value);
100
+ if (itemIsDayjs) {
101
+ timeKeys.push(key);
102
+ }
103
+ newDataValue[key] = itemIsDayjs
104
+ ? dayjs(value).format('YYYY-MM-DD HH:mm:ss')
105
+ : value;
106
+ }
107
+ });
108
+ }
109
+ return {
110
+ newDataValue: newDataValue,
111
+ timeKeys: timeKeys,
112
+ };
113
+ };
114
+ /**
115
+ * @description: 数据转换。主要是将时间字符串转成时间对象。
116
+ */
117
+ var reTransformData = function (data, timeKeys) {
118
+ if (timeKeys === void 0) { timeKeys = []; }
119
+ // 处理数据,将数据中的时间对象做一下转换
120
+ var dataValue = data;
121
+ var newDataValue = {}; // 为了不影响之前的数据
122
+ if (dataValue) {
123
+ Object.keys(dataValue).forEach(function (key) {
124
+ var value = dataValue[key];
125
+ if (Array.isArray(value)) {
126
+ newDataValue[key] = [];
127
+ value.forEach(function (item) {
128
+ if (timeKeys.includes(key)) {
129
+ newDataValue[key].push(dayjs(item));
130
+ }
131
+ else {
132
+ newDataValue[key].push(item);
133
+ }
134
+ });
135
+ }
136
+ else {
137
+ newDataValue[key] = timeKeys.includes(key) ? dayjs(value) : value;
138
+ }
139
+ });
140
+ }
141
+ return newDataValue;
142
+ };
143
+ /**
144
+ * description: 存储数据
145
+ * @param {*} data 常用搜索数据
146
+ * @param {*} localIndex 本地存储索引 如果传了索引 就是修改
147
+ */
148
+ var setData = function (data) { return __awaiter(_this, void 0, void 0, function () {
149
+ var localKey, _a, newDataValue, timeKeys, saveData;
150
+ var _b;
151
+ return __generator(this, function (_c) {
152
+ localKey = commonSearchKey;
153
+ _a = transformData(data.value), newDataValue = _a.newDataValue, timeKeys = _a.timeKeys;
154
+ saveData = __assign(__assign({}, data), { value: newDataValue, timeKeys: timeKeys });
155
+ return [2 /*return*/, (_b = storageRef === null || storageRef === void 0 ? void 0 : storageRef.current) === null || _b === void 0 ? void 0 : _b.getItem(localKey).then(function (res) {
156
+ var _a, _b;
157
+ // 处理数据,将数据中的时间对象做一下转换
158
+ var result = res;
159
+ if (!result) {
160
+ result = [saveData];
161
+ }
162
+ else if (Array.isArray(result)) {
163
+ var index = result.findIndex(function (item) { return item.key === saveData.key; });
164
+ if (index !== -1) {
165
+ result[index] = saveData;
166
+ }
167
+ else {
168
+ result.unshift(saveData);
169
+ }
170
+ }
171
+ setCommonSearchList(result);
172
+ return (_b = (_a = storageRef === null || storageRef === void 0 ? void 0 : storageRef.current) === null || _a === void 0 ? void 0 : _a.setItem(localKey, result)) === null || _b === void 0 ? void 0 : _b.then(function () {
173
+ return updateServerData();
174
+ });
175
+ })];
176
+ });
177
+ }); };
178
+ /**
179
+ * description: 删除数据
180
+ * @param {*} localIndex 本地存储索引
181
+ */
182
+ var deleteData = function (localIndex) { return __awaiter(_this, void 0, void 0, function () {
183
+ var localKey;
184
+ var _a;
185
+ return __generator(this, function (_b) {
186
+ localKey = commonSearchKey;
187
+ return [2 /*return*/, (_a = storageRef === null || storageRef === void 0 ? void 0 : storageRef.current) === null || _a === void 0 ? void 0 : _a.getItem(localKey).then(function (res) {
188
+ var _a, _b;
189
+ if (Array.isArray(res)) {
190
+ res.splice(localIndex, 1);
191
+ (_b = (_a = storageRef === null || storageRef === void 0 ? void 0 : storageRef.current) === null || _a === void 0 ? void 0 : _a.setItem(localKey, res)) === null || _b === void 0 ? void 0 : _b.then(function () {
192
+ return updateServerData();
193
+ });
194
+ setCommonSearchList(res);
195
+ }
196
+ })];
197
+ });
198
+ }); };
199
+ /**
200
+ * description: 直接替换原有数据
201
+ * @param {*} data 常用搜索数据
202
+ */
203
+ var setReplaceData = function (data) { return __awaiter(_this, void 0, void 0, function () {
204
+ var localKey;
205
+ var _a;
206
+ return __generator(this, function (_b) {
207
+ localKey = commonSearchKey;
208
+ setCommonSearchList(data);
209
+ return [2 /*return*/, (_a = storageRef === null || storageRef === void 0 ? void 0 : storageRef.current) === null || _a === void 0 ? void 0 : _a.setItem(localKey, data)];
210
+ });
211
+ }); };
212
+ /**
213
+ * 直接更新服务器数据
214
+ */
215
+ var updateServerData = function () { return __awaiter(_this, void 0, void 0, function () {
216
+ var _this = this;
217
+ var _a, _b;
218
+ return __generator(this, function (_c) {
219
+ return [2 /*return*/, (_b = (_a = storageRef.current) === null || _a === void 0 ? void 0 : _a.getAllItems()) === null || _b === void 0 ? void 0 : _b.then(function (res) { return __awaiter(_this, void 0, void 0, function () {
220
+ var error_1;
221
+ return __generator(this, function (_a) {
222
+ switch (_a.label) {
223
+ case 0:
224
+ _a.trys.push([0, 2, , 3]);
225
+ return [4 /*yield*/, (catchHandle === null || catchHandle === void 0 ? void 0 : catchHandle({
226
+ customKey: COMMON_SEARCH_KEY,
227
+ customValue: JSON.stringify(res),
228
+ mark: i18next.t('常用搜索用户配置'),
229
+ }))];
230
+ case 1:
231
+ _a.sent();
232
+ return [3 /*break*/, 3];
233
+ case 2:
234
+ error_1 = _a.sent();
235
+ console.error(i18next.t('更新服务器数据失败!'), error_1);
236
+ return [3 /*break*/, 3];
237
+ case 3: return [2 /*return*/];
238
+ }
239
+ });
240
+ }); })];
241
+ });
242
+ }); };
243
+ return {
244
+ commonSearchList: commonSearchList,
245
+ setCommonSearchList: setCommonSearchList,
246
+ currentCommonSearchKey: currentCommonSearchKey,
247
+ setCurrentCommonSearchKey: setCurrentCommonSearchKey,
248
+ reTransformData: reTransformData,
249
+ setData: setData,
250
+ deleteData: deleteData,
251
+ setReplaceData: setReplaceData,
252
+ updateServerData: updateServerData,
253
+ };
254
+ }
255
+ export function useCommonSearchModal(options) {
256
+ var commonSearchList = options.commonSearchList, currentCommonSearchKey = options.currentCommonSearchKey, form = options.form, setData = options.setData, isCommonSearchEnabled = options.isCommonSearchEnabled, setCurrentCommonSearchKey = options.setCurrentCommonSearchKey, currentDynamicList = options.currentDynamicList;
257
+ var iptRef = useRef(null);
258
+ useEffect(function () {
259
+ var _a;
260
+ if (!isCommonSearchEnabled) {
261
+ return;
262
+ }
263
+ if (!(commonSearchList === null || commonSearchList === void 0 ? void 0 : commonSearchList.length)) {
264
+ return;
265
+ }
266
+ var currentCommon = commonSearchList.find(function (item) { return item.key === currentCommonSearchKey; });
267
+ if (currentCommon) {
268
+ (_a = iptRef.current) === null || _a === void 0 ? void 0 : _a.setValue(currentCommon.title);
269
+ }
270
+ }, [currentCommonSearchKey, commonSearchList, isCommonSearchEnabled]);
271
+ /**
272
+ * 保存为常用搜索事件
273
+ */
274
+ var onCommonSearchHandle = function () {
275
+ if (!form) {
276
+ message.info(i18next.t('组件需要接受表单实例form'));
277
+ return;
278
+ }
279
+ Modal.confirm({
280
+ icon: null,
281
+ // title: currentCommonSearchKey ? "更新常用搜索" : "保存为常用搜索",
282
+ title: i18next.t('保存为常用搜索'),
283
+ content: React.createElement(MyInput, { ref: iptRef }),
284
+ onOk: function () {
285
+ var _a, _b;
286
+ return __awaiter(this, void 0, void 0, function () {
287
+ var currentCommonName, currentData, data, err_1;
288
+ return __generator(this, function (_c) {
289
+ switch (_c.label) {
290
+ case 0:
291
+ currentCommonName = (_a = iptRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
292
+ if (!currentCommonName) {
293
+ message.info(i18next.t('请输入常用搜索名称!'));
294
+ return [2 /*return*/, Promise.reject(new Error(i18next.t('请输入常用搜索名称!')))];
295
+ }
296
+ currentData = form.getFieldsValue();
297
+ console.log(i18next.t('当前表单数据'), currentData);
298
+ data = {
299
+ title: currentCommonName,
300
+ value: currentData,
301
+ // key: currentCommonSearchKey || Date.now(),
302
+ key: Date.now(),
303
+ dynamicList: currentDynamicList,
304
+ };
305
+ _c.label = 1;
306
+ case 1:
307
+ _c.trys.push([1, 3, , 4]);
308
+ return [4 /*yield*/, (setData === null || setData === void 0 ? void 0 : setData(data))];
309
+ case 2:
310
+ _c.sent();
311
+ setCurrentCommonSearchKey === null || setCurrentCommonSearchKey === void 0 ? void 0 : setCurrentCommonSearchKey(data.key);
312
+ message.info(i18next.t('保存成功!'));
313
+ (_b = iptRef.current) === null || _b === void 0 ? void 0 : _b.setValue('');
314
+ return [3 /*break*/, 4];
315
+ case 3:
316
+ err_1 = _c.sent();
317
+ message.info(i18next.t('保存常用搜索失败!'));
318
+ return [2 /*return*/, Promise.reject(new Error(i18next.t('保存常用搜索失败!')))];
319
+ case 4: return [2 /*return*/];
320
+ }
321
+ });
322
+ });
323
+ },
324
+ onCancel: function () {
325
+ console.log('Cancel');
326
+ },
327
+ });
328
+ setTimeout(function () {
329
+ if (!(commonSearchList === null || commonSearchList === void 0 ? void 0 : commonSearchList.length)) {
330
+ return;
331
+ }
332
+ var currentCommon = commonSearchList.find(function (item) { return item.key === currentCommonSearchKey; });
333
+ if (currentCommon) {
334
+ // iptRef.current?.setValue(currentCommon.title);
335
+ }
336
+ }, 0);
337
+ };
338
+ return {
339
+ onCommonSearchHandle: onCommonSearchHandle,
340
+ };
341
+ }
342
+ var MyInput = forwardRef(function (props, ref) {
343
+ var _a = useState(''), value = _a[0], setValue = _a[1];
344
+ var onChange = function (e) {
345
+ setValue(e.target.value);
346
+ };
347
+ useImperativeHandle(ref, function () { return ({
348
+ getValue: function () { return value; },
349
+ setValue: setValue,
350
+ }); });
351
+ return (React.createElement(Input, { placeholder: i18next.t('请输入常用搜索名称!'), value: value, onChange: onChange }));
352
+ });
@@ -6,6 +6,7 @@ interface IProps<RecordType> {
6
6
  onReset?: () => void;
7
7
  onSave?: (columns: ColumnsType<RecordType> | undefined) => void;
8
8
  columns?: ColumnsType<RecordType>;
9
+ dynamicStorageKey?: string;
9
10
  }
10
11
  declare function TableDynamic<RecordType>(props: IProps<RecordType>): JSX.Element;
11
12
  declare const _default: React.MemoExoticComponent<typeof TableDynamic>;