@arim-aisdc/public-components 0.0.37 → 0.0.39
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/dist/components/TableMax/TableMax.js +5 -4
- package/dist/components/TableMax/components/ColumnFilter/index.js +41 -19
- package/dist/components/TableMax/type.d.ts +3 -1
- package/dist/components/TableMax/utils.d.ts +5 -1
- package/dist/components/TableMax/utils.js +20 -0
- package/dist/hooks/useEventBus.d.ts +14 -0
- package/dist/hooks/useEventBus.js +93 -0
- package/dist/hooks/{usePageCacheState/index.d.ts → usePageCacheState.d.ts} +2 -4
- package/dist/hooks/{usePageCacheState/index.js → usePageCacheState.js} +4 -8
- package/dist/index.d.ts +3 -0
- package/dist/index.js +9 -1
- package/package.json +2 -3
- package/dist/hooks/usePageCacheState/config.d.ts +0 -5
- package/dist/hooks/usePageCacheState/config.js +0 -1
- package/dist/hooks/usePageCacheState/tableDemoConfig.d.ts +0 -3
- package/dist/hooks/usePageCacheState/tableDemoConfig.js +0 -5
|
@@ -43,7 +43,7 @@ import customFilterFns from "./components/ColumnFilter/customFilterFns";
|
|
|
43
43
|
import ColumnSetting from "./components/ColumnSetting";
|
|
44
44
|
import customSortFns, { setDefaultSortFn } from "./components/ColumnSort/customSortFns";
|
|
45
45
|
import "./tableMax.less";
|
|
46
|
-
import { getFormatFilters, getSizeInfo, setInitColumnsSize, setRemainColumnsWidth } from "./utils";
|
|
46
|
+
import { getFormatFilters, getFormatSorting, getSizeInfo, setInitColumnsSize, setRemainColumnsWidth } from "./utils";
|
|
47
47
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
48
48
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
49
49
|
export var ColumnType = /*#__PURE__*/function (ColumnType) {
|
|
@@ -641,9 +641,10 @@ var TableMax = function TableMax(_ref) {
|
|
|
641
641
|
|
|
642
642
|
// 排序回调
|
|
643
643
|
useEffect(function () {
|
|
644
|
+
var formatSorting = getFormatSorting(columns, sorting);
|
|
644
645
|
var sortingParameters = [];
|
|
645
|
-
if ((
|
|
646
|
-
sortingParameters =
|
|
646
|
+
if ((formatSorting === null || formatSorting === void 0 ? void 0 : formatSorting.length) > 0) {
|
|
647
|
+
sortingParameters = formatSorting === null || formatSorting === void 0 ? void 0 : formatSorting.map(function (item) {
|
|
647
648
|
return "".concat(item.id, " ").concat(item.desc ? 'DESC' : 'ASC');
|
|
648
649
|
});
|
|
649
650
|
}
|
|
@@ -655,7 +656,7 @@ var TableMax = function TableMax(_ref) {
|
|
|
655
656
|
manualSortingChange(sorting, sortingParameters.join(';'), sortedData, sortedRowModel);
|
|
656
657
|
}
|
|
657
658
|
if (canSorting && onSortingChange) {
|
|
658
|
-
onSortingChange(
|
|
659
|
+
onSortingChange(formatSorting, sortingParameters.join(','), sortedData, sortedRowModel);
|
|
659
660
|
}
|
|
660
661
|
}, [JSON.stringify(sorting), canSorting, manualSorting]);
|
|
661
662
|
useEffect(function () {
|
|
@@ -75,13 +75,22 @@ export function Filter(_ref) {
|
|
|
75
75
|
getFilterOptionsFn = columnDef.getFilterOptionsFn;
|
|
76
76
|
|
|
77
77
|
// 获取最新的筛选值
|
|
78
|
-
|
|
78
|
+
// const columnFilterValue: any = column.getFilterValue();
|
|
79
|
+
var _useState = useState(column.getFilterValue()),
|
|
80
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
81
|
+
columnFilterValue = _useState2[0],
|
|
82
|
+
setColumnFilterValue = _useState2[1];
|
|
83
|
+
useEffect(function () {
|
|
84
|
+
if (JSON.stringify(column.getFilterValue()) !== JSON.stringify(columnFilterValue)) {
|
|
85
|
+
setColumnFilterValue(column.getFilterValue());
|
|
86
|
+
}
|
|
87
|
+
}, [JSON.stringify(column.getFilterValue())]);
|
|
79
88
|
|
|
80
89
|
// 接口可选值
|
|
81
|
-
var
|
|
82
|
-
|
|
83
|
-
apiOptions =
|
|
84
|
-
setApiOptions =
|
|
90
|
+
var _useState3 = useState([]),
|
|
91
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
92
|
+
apiOptions = _useState4[0],
|
|
93
|
+
setApiOptions = _useState4[1];
|
|
85
94
|
// 调用接口获取可选值
|
|
86
95
|
var fetchOptions = /*#__PURE__*/function () {
|
|
87
96
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(inputValue) {
|
|
@@ -154,6 +163,25 @@ export function Filter(_ref) {
|
|
|
154
163
|
};
|
|
155
164
|
});
|
|
156
165
|
}, [column.getFacetedUniqueValues(), filterOptions, manualFiltering, apiOptions]);
|
|
166
|
+
|
|
167
|
+
// 修改表格筛选参数(防抖)
|
|
168
|
+
var changeFilterValueWithDebounce = useCallback(debounce(function (value) {
|
|
169
|
+
var newValue = value;
|
|
170
|
+
if (value === null || Array.isArray(value) && value.length === 0) {
|
|
171
|
+
// 值为null或空数组时,清除过滤条件。
|
|
172
|
+
newValue = undefined;
|
|
173
|
+
}
|
|
174
|
+
console.log('handleChangeFilterValue with debounce :>> ', newValue);
|
|
175
|
+
column.setFilterValue(newValue);
|
|
176
|
+
}, 500), [column]);
|
|
177
|
+
|
|
178
|
+
// 修改表格筛选参数(防抖)
|
|
179
|
+
var handleChangeFilterValueWithDebounce = function handleChangeFilterValueWithDebounce(value) {
|
|
180
|
+
changeFilterValueWithDebounce(value);
|
|
181
|
+
setColumnFilterValue(value);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// 修改表格筛选参数
|
|
157
185
|
var handleChangeFilterValue = function handleChangeFilterValue(value) {
|
|
158
186
|
var newValue = value;
|
|
159
187
|
if (value === null || Array.isArray(value) && value.length === 0) {
|
|
@@ -161,11 +189,9 @@ export function Filter(_ref) {
|
|
|
161
189
|
newValue = undefined;
|
|
162
190
|
}
|
|
163
191
|
console.log('handleChangeFilterValue :>> ', newValue);
|
|
192
|
+
setColumnFilterValue(newValue);
|
|
164
193
|
column.setFilterValue(newValue);
|
|
165
194
|
};
|
|
166
|
-
var handleInputChange = function handleInputChange(e) {
|
|
167
|
-
handleChangeFilterValue(e.target.value);
|
|
168
|
-
};
|
|
169
195
|
var filterComponent = function filterComponent(type) {
|
|
170
196
|
var _columnDef$filterComP, _columnDef$filterComP2, _columnDef$filterComP3, _column$getFacetedMin, _column$getFacetedMin2, _columnDef$cell, _column$getFacetedMin3, _column$getFacetedMin4, _columnDef$cell2;
|
|
171
197
|
switch (type) {
|
|
@@ -196,14 +222,11 @@ export function Filter(_ref) {
|
|
|
196
222
|
},
|
|
197
223
|
children: [/*#__PURE__*/_jsx("div", {
|
|
198
224
|
children: /*#__PURE__*/_jsx(_InputNumber, {
|
|
199
|
-
// min={Number(column.getFacetedMinMaxValues()?.[0] ?? '')}
|
|
200
|
-
// max={Number(column.getFacetedMinMaxValues()?.[1] ?? '')}
|
|
201
|
-
// value={(columnFilterValue as [number, number])?.[0] ?? ''}
|
|
202
225
|
placeholder: "".concat((_column$getFacetedMin = column.getFacetedMinMaxValues()) !== null && _column$getFacetedMin !== void 0 && _column$getFacetedMin[0] ? "(".concat((_column$getFacetedMin2 = column.getFacetedMinMaxValues()) === null || _column$getFacetedMin2 === void 0 ? void 0 : _column$getFacetedMin2[0], ")") : ''),
|
|
203
226
|
controls: false,
|
|
204
227
|
onChange: function onChange(value) {
|
|
205
228
|
var min = columnDef.unitsChangeFn && typeof value === 'number' ? columnDef.unitsChangeFn(value) : value;
|
|
206
|
-
|
|
229
|
+
handleChangeFilterValueWithDebounce(function (old) {
|
|
207
230
|
if (noValue(min) && noValue(old === null || old === void 0 ? void 0 : old[1])) {
|
|
208
231
|
return undefined;
|
|
209
232
|
}
|
|
@@ -218,14 +241,11 @@ export function Filter(_ref) {
|
|
|
218
241
|
})
|
|
219
242
|
}), /*#__PURE__*/_jsx("div", {
|
|
220
243
|
children: /*#__PURE__*/_jsx(_InputNumber, {
|
|
221
|
-
// min={Number(column.getFacetedMinMaxValues()?.[0] ?? '')}
|
|
222
|
-
// max={Number(column.getFacetedMinMaxValues()?.[1] ?? '')}
|
|
223
|
-
// value={(columnFilterValue as [number, number])?.[1] ?? ''}
|
|
224
244
|
placeholder: "".concat((_column$getFacetedMin3 = column.getFacetedMinMaxValues()) !== null && _column$getFacetedMin3 !== void 0 && _column$getFacetedMin3[1] ? "(".concat((_column$getFacetedMin4 = column.getFacetedMinMaxValues()) === null || _column$getFacetedMin4 === void 0 ? void 0 : _column$getFacetedMin4[1], ")") : ''),
|
|
225
245
|
controls: false,
|
|
226
246
|
onChange: function onChange(value) {
|
|
227
247
|
var max = columnDef.unitsChangeFn && typeof value === 'number' ? columnDef.unitsChangeFn(value) : value;
|
|
228
|
-
|
|
248
|
+
handleChangeFilterValueWithDebounce(function (old) {
|
|
229
249
|
if (noValue(old === null || old === void 0 ? void 0 : old[0]) && noValue(max)) {
|
|
230
250
|
return undefined;
|
|
231
251
|
}
|
|
@@ -250,7 +270,7 @@ export function Filter(_ref) {
|
|
|
250
270
|
},
|
|
251
271
|
onChange: function onChange(value) {
|
|
252
272
|
var res = columnDef.unitsChangeFn ? columnDef.unitsChangeFn(value) : value;
|
|
253
|
-
|
|
273
|
+
handleChangeFilterValueWithDebounce(res);
|
|
254
274
|
},
|
|
255
275
|
value: columnDef.unitsChangeFn && columnDef.cell ? columnDef.cell({
|
|
256
276
|
getValue: function getValue() {
|
|
@@ -270,7 +290,7 @@ export function Filter(_ref) {
|
|
|
270
290
|
return ((_optionStringValue$to = optionStringValue.toUpperCase()) === null || _optionStringValue$to === void 0 ? void 0 : _optionStringValue$to.indexOf(inputStringValue.toUpperCase().trim())) !== -1;
|
|
271
291
|
},
|
|
272
292
|
onSearch: onSearch,
|
|
273
|
-
onChange:
|
|
293
|
+
onChange: handleChangeFilterValueWithDebounce,
|
|
274
294
|
style: {
|
|
275
295
|
width: '100%',
|
|
276
296
|
borderRadius: '2px',
|
|
@@ -281,7 +301,9 @@ export function Filter(_ref) {
|
|
|
281
301
|
});
|
|
282
302
|
case FilterType.Input:
|
|
283
303
|
return /*#__PURE__*/_jsx(_Input, {
|
|
284
|
-
onChange:
|
|
304
|
+
onChange: function onChange(e) {
|
|
305
|
+
return handleChangeFilterValueWithDebounce(e.target.value);
|
|
306
|
+
},
|
|
285
307
|
style: {
|
|
286
308
|
borderRadius: '2px'
|
|
287
309
|
},
|
|
@@ -113,7 +113,7 @@ export type TableMaxProps = {
|
|
|
113
113
|
* 筛选参数变化时触发的函数
|
|
114
114
|
*/
|
|
115
115
|
getColumnFiltersData?: (columnFilters: ColumnFiltersState, tableId: string, filteredData: any[], filteredRowModel: RowModel<any>) => void;
|
|
116
|
-
|
|
116
|
+
/**筛选参数变化时触发的函数,前端筛选、后端筛选时都会触发(修改参数时加了防抖) */
|
|
117
117
|
onFilteringChange?: (params: {
|
|
118
118
|
tableId: string;
|
|
119
119
|
filteredData: any[];
|
|
@@ -297,4 +297,6 @@ export interface TableMaxColumnType {
|
|
|
297
297
|
sortingFn?: SortFnType | ((rowA: any, rowB: any, columnId: string) => 1 | -1 | 0);
|
|
298
298
|
/**排序时,对undefined值如何处理 */
|
|
299
299
|
sortUndefined?: false | 1 | -1;
|
|
300
|
+
/**自定义当前列排序时所使用的key,默认为当前列的id */
|
|
301
|
+
sortingKey?: string;
|
|
300
302
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColumnFiltersState } from '@tanstack/react-table';
|
|
1
|
+
import { ColumnFiltersState, SortingState } from '@tanstack/react-table';
|
|
2
2
|
import { TableMaxColumnType } from './type';
|
|
3
3
|
export declare const getSizeInfo: (columns: TableMaxColumnType[]) => {
|
|
4
4
|
allCount: number;
|
|
@@ -17,4 +17,8 @@ export declare const setInitColumnsSize: (tableColumns: any, columnsMap: any) =>
|
|
|
17
17
|
tableColumns: any;
|
|
18
18
|
};
|
|
19
19
|
export declare const getFormatFilters: (columns: TableMaxColumnType[], originFilters: ColumnFiltersState) => {};
|
|
20
|
+
export declare const getFormatSorting: (columns: TableMaxColumnType[], originSorting: SortingState) => {
|
|
21
|
+
id: string;
|
|
22
|
+
desc: boolean;
|
|
23
|
+
}[];
|
|
20
24
|
export declare const noValue: (value: any) => boolean;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1
7
|
import { cloneDeep } from 'lodash';
|
|
2
8
|
import moment from 'moment';
|
|
3
9
|
import { FilterType, defaultDateFormat } from "./components/ColumnFilter";
|
|
@@ -117,6 +123,20 @@ export var getFormatFilters = function getFormatFilters(columns, originFilters)
|
|
|
117
123
|
});
|
|
118
124
|
return formatFilters;
|
|
119
125
|
};
|
|
126
|
+
export var getFormatSorting = function getFormatSorting(columns, originSorting) {
|
|
127
|
+
return originSorting.map(function (sort) {
|
|
128
|
+
var curColumn = columns.find(function (item) {
|
|
129
|
+
return item.id === sort.id;
|
|
130
|
+
});
|
|
131
|
+
var _ref4 = curColumn || {},
|
|
132
|
+
sortingKey = _ref4.sortingKey;
|
|
133
|
+
// 优先取formattedFilterKey作为key
|
|
134
|
+
var formatKey = sortingKey || sort.id;
|
|
135
|
+
return _objectSpread(_objectSpread({}, sort), {}, {
|
|
136
|
+
id: formatKey
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
};
|
|
120
140
|
export var noValue = function noValue(value) {
|
|
121
141
|
return value === undefined || value === null || value === '';
|
|
122
142
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type EventHandler<E = any> = (e: E) => void;
|
|
2
|
+
declare class EventEmitter<E = any> {
|
|
3
|
+
private _events;
|
|
4
|
+
constructor();
|
|
5
|
+
private _getFns;
|
|
6
|
+
on<T = E>(event: string, cb: EventHandler<T>): void;
|
|
7
|
+
off(event: string, cb?: EventHandler<E>): void;
|
|
8
|
+
once<T = E>(event: string, cb: EventHandler<T>): void;
|
|
9
|
+
emit<T = E>(event: string, param?: T): void;
|
|
10
|
+
invoke<T = E>(event: string, param?: T): Promise<any>;
|
|
11
|
+
}
|
|
12
|
+
export declare const events: EventEmitter<any>;
|
|
13
|
+
export default function useEventBus<T = any>(event: string, cb: EventHandler<T>): void;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
import { pull } from 'lodash';
|
|
9
|
+
import { useEffect } from 'react';
|
|
10
|
+
/*事件的原型*/
|
|
11
|
+
var EventEmitter = /*#__PURE__*/function () {
|
|
12
|
+
function EventEmitter() {
|
|
13
|
+
_classCallCheck(this, EventEmitter);
|
|
14
|
+
_defineProperty(this, "_events", void 0);
|
|
15
|
+
this._events = {};
|
|
16
|
+
}
|
|
17
|
+
_createClass(EventEmitter, [{
|
|
18
|
+
key: "_getFns",
|
|
19
|
+
value: function _getFns(event) {
|
|
20
|
+
return this._events[event] || (this._events[event] = []);
|
|
21
|
+
}
|
|
22
|
+
}, {
|
|
23
|
+
key: "on",
|
|
24
|
+
value: function on(event, cb) {
|
|
25
|
+
var fns = this._getFns(event);
|
|
26
|
+
fns.push(cb);
|
|
27
|
+
}
|
|
28
|
+
}, {
|
|
29
|
+
key: "off",
|
|
30
|
+
value: function off(event, cb) {
|
|
31
|
+
if (cb) {
|
|
32
|
+
var fns = this._getFns(event);
|
|
33
|
+
pull(fns, cb);
|
|
34
|
+
} else {
|
|
35
|
+
delete this._events[event];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
key: "once",
|
|
40
|
+
value: function once(event, cb) {
|
|
41
|
+
var _this = this;
|
|
42
|
+
var fn2 = function fn2(e) {
|
|
43
|
+
_this.off(event, fn2);
|
|
44
|
+
cb(e);
|
|
45
|
+
};
|
|
46
|
+
this.on(event, fn2);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* 同步调用 */
|
|
50
|
+
}, {
|
|
51
|
+
key: "emit",
|
|
52
|
+
value: function emit(event, param) {
|
|
53
|
+
var fns = this._getFns(event);
|
|
54
|
+
for (var i = 0; i < fns.length; i++) {
|
|
55
|
+
var fn = fns[i];
|
|
56
|
+
fn(param);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* 可以异步调用,返回一个Promise */
|
|
61
|
+
}, {
|
|
62
|
+
key: "invoke",
|
|
63
|
+
value: function invoke(event, param) {
|
|
64
|
+
var fns = this._getFns(event);
|
|
65
|
+
var _loop = function _loop() {
|
|
66
|
+
var fn = fns[i];
|
|
67
|
+
return {
|
|
68
|
+
v: new Promise(function (resolve) {
|
|
69
|
+
resolve(fn(param));
|
|
70
|
+
})
|
|
71
|
+
};
|
|
72
|
+
return 0; // break flag
|
|
73
|
+
},
|
|
74
|
+
_ret;
|
|
75
|
+
flag: for (var i = 0; i < fns.length; i++) {
|
|
76
|
+
_ret = _loop();
|
|
77
|
+
if (_ret === 0) break flag;
|
|
78
|
+
if (_ret) return _ret.v;
|
|
79
|
+
}
|
|
80
|
+
return Promise.reject();
|
|
81
|
+
}
|
|
82
|
+
}]);
|
|
83
|
+
return EventEmitter;
|
|
84
|
+
}();
|
|
85
|
+
export var events = new EventEmitter();
|
|
86
|
+
export default function useEventBus(event, cb) {
|
|
87
|
+
useEffect(function () {
|
|
88
|
+
events.on(event, cb);
|
|
89
|
+
return function () {
|
|
90
|
+
events.off(event, cb);
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { CacheKeyEnums } from './config';
|
|
2
|
-
export * from './config';
|
|
3
|
-
export * from './tableDemoConfig';
|
|
4
1
|
/**
|
|
5
2
|
* 替代useState,初始化时会自动读取storage作为默认值,修改数据时会自动同步到storage中;
|
|
6
3
|
* params:
|
|
@@ -19,7 +16,8 @@ export * from './tableDemoConfig';
|
|
|
19
16
|
* initState, // 初始化状态函数
|
|
20
17
|
* ]
|
|
21
18
|
*/
|
|
22
|
-
|
|
19
|
+
declare function usePageCacheState<T extends object>(originStateCacheKey: string, defaultConfig: T | {
|
|
23
20
|
defaultValue: T;
|
|
24
21
|
noCacheFields?: string[];
|
|
25
22
|
}, deps?: any[]): [T, (customData: Partial<T>) => void, (newDeps: any[]) => void];
|
|
23
|
+
export default usePageCacheState;
|
|
@@ -14,10 +14,6 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
14
14
|
import { useMemoizedFn, useUpdateEffect } from 'ahooks';
|
|
15
15
|
import { cloneDeep, mergeWith } from 'lodash';
|
|
16
16
|
import { useState } from 'react';
|
|
17
|
-
import { useLocation } from 'umi'; // TODO: 优化:去掉umi
|
|
18
|
-
|
|
19
|
-
export * from "./config";
|
|
20
|
-
export * from "./tableDemoConfig";
|
|
21
17
|
|
|
22
18
|
// 缓存数据使用的key
|
|
23
19
|
var PAGE_CACHE_KEY = 'HBIS_PAGE_CACHE';
|
|
@@ -141,13 +137,12 @@ function customMerger(defaultValue, cacheValue) {
|
|
|
141
137
|
* initState, // 初始化状态函数
|
|
142
138
|
* ]
|
|
143
139
|
*/
|
|
144
|
-
|
|
140
|
+
function usePageCacheState(originStateCacheKey, defaultConfig, deps) {
|
|
145
141
|
// @ts-ignore
|
|
146
142
|
var defaultValue = _typeof(defaultConfig.defaultValue) === 'object' ? defaultConfig.defaultValue : defaultConfig;
|
|
147
143
|
// @ts-ignore
|
|
148
144
|
var noCacheFields = defaultConfig.noCacheFields;
|
|
149
|
-
var
|
|
150
|
-
var pathname = location.pathname;
|
|
145
|
+
var pathname = window.location.pathname;
|
|
151
146
|
var getStateCacheKey = function getStateCacheKey(newDeps) {
|
|
152
147
|
var curDeps = newDeps || deps;
|
|
153
148
|
return curDeps && curDeps.length ? "".concat(originStateCacheKey, "_").concat(curDeps === null || curDeps === void 0 ? void 0 : curDeps.join('_')) : originStateCacheKey;
|
|
@@ -207,4 +202,5 @@ export function usePageCacheState(originStateCacheKey, defaultConfig, deps) {
|
|
|
207
202
|
setState(initData);
|
|
208
203
|
};
|
|
209
204
|
return [state, useMemoizedFn(customSetState), initState];
|
|
210
|
-
}
|
|
205
|
+
}
|
|
206
|
+
export default usePageCacheState;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,3 +10,6 @@ export * from './components/TableMax';
|
|
|
10
10
|
export { default as TableMax } from './components/TableMax';
|
|
11
11
|
export * from './components/ThemeProvider';
|
|
12
12
|
export { default as ThemeProvider } from './components/ThemeProvider';
|
|
13
|
+
export * from './hooks/useEventBus';
|
|
14
|
+
export { default as useEventBus } from './hooks/useEventBus';
|
|
15
|
+
export { default as usePageCacheState } from './hooks/usePageCacheState';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// components
|
|
1
2
|
export * from "./components/CenterModal";
|
|
2
3
|
export { default as CenterModal } from "./components/CenterModal";
|
|
3
4
|
export * from "./components/CustomForm";
|
|
@@ -9,4 +10,11 @@ export { default as SplitPane } from "./components/SplitPane";
|
|
|
9
10
|
export * from "./components/TableMax";
|
|
10
11
|
export { default as TableMax } from "./components/TableMax";
|
|
11
12
|
export * from "./components/ThemeProvider";
|
|
12
|
-
export { default as ThemeProvider } from "./components/ThemeProvider";
|
|
13
|
+
export { default as ThemeProvider } from "./components/ThemeProvider";
|
|
14
|
+
|
|
15
|
+
// hooks
|
|
16
|
+
export * from "./hooks/useEventBus";
|
|
17
|
+
export { default as useEventBus } from "./hooks/useEventBus";
|
|
18
|
+
export { default as usePageCacheState } from "./hooks/usePageCacheState";
|
|
19
|
+
|
|
20
|
+
// utils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arim-aisdc/public-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.39",
|
|
4
4
|
"description": "前端组件库",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -83,8 +83,7 @@
|
|
|
83
83
|
"peerDependencies": {
|
|
84
84
|
"moment": ">=2.29.4",
|
|
85
85
|
"react": ">=17.0.1",
|
|
86
|
-
"react-dom": ">=17.0.1"
|
|
87
|
-
"umi": ">=4.0.87"
|
|
86
|
+
"react-dom": ">=17.0.1"
|
|
88
87
|
},
|
|
89
88
|
"publishConfig": {
|
|
90
89
|
"access": "public"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|