xmirror-components 1.0.32 → 1.0.34-alpha.1

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.
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.decodeParams = exports.encodeParams = void 0;
15
+ var lodash_es_1 = require("lodash-es");
16
+ var typeFlags = {
17
+ Array: 'a',
18
+ Boolean: 'b',
19
+ Number: 'n',
20
+ String: 's',
21
+ Undefined: 'u',
22
+ Null: 'N'
23
+ };
24
+ var pack = function (value, array) {
25
+ var type = Object.prototype.toString.call(value).slice(8, -1);
26
+ if (type === 'Array') {
27
+ if (value.length) {
28
+ return "".concat(typeFlags[type]).concat(pack(value[0], value));
29
+ }
30
+ else {
31
+ return 'u_u';
32
+ }
33
+ }
34
+ var v = array || [value];
35
+ if (type === 'Boolean') {
36
+ return "".concat(typeFlags[type], "_").concat(v.map(function (item) { return (item ? 1 : 0); }).join());
37
+ }
38
+ if (type === 'String') {
39
+ return "".concat(typeFlags[type], "_").concat(v.join());
40
+ }
41
+ if (type === 'Null') {
42
+ return "".concat(typeFlags[type], "_").concat(v.map(function () { return 'n'; }).join());
43
+ }
44
+ if (type === 'Number') {
45
+ return "".concat(typeFlags[type], "_").concat(v.join());
46
+ }
47
+ return "u_".concat(v.map(function () { return 'u'; }).join());
48
+ };
49
+ var unpack = function (value) {
50
+ value = decodeURIComponent(value);
51
+ var _isArray = value.slice(0, 1) === 'a';
52
+ var type = _isArray ? value.slice(1, 2) : value.slice(0, 1);
53
+ var _value = _isArray ? value.slice(3).split(',') : value.slice(2);
54
+ if (type === 'b') {
55
+ return (0, lodash_es_1.isArray)(_value) ? _value.map(function (item) { return item === '1'; }) : _value === '1';
56
+ }
57
+ if (type === 's') {
58
+ return _value;
59
+ }
60
+ if (type === 'n') {
61
+ return (0, lodash_es_1.isArray)(_value) ? _value.map(function (item) { return (0, lodash_es_1.toNumber)(item); }) : (0, lodash_es_1.toNumber)(_value);
62
+ }
63
+ if (type === 'u') {
64
+ return (0, lodash_es_1.isArray)(_value) ? _value.map(function () { return undefined; }) : undefined;
65
+ }
66
+ if (type === 'N') {
67
+ return (0, lodash_es_1.isArray)(_value) ? _value.map(function () { return null; }) : null;
68
+ }
69
+ return _value;
70
+ };
71
+ /**
72
+ * 加密
73
+ * @param params
74
+ */
75
+ var encodeParams = function (params) {
76
+ return Object.entries(__assign({}, params)).reduce(function (previousValue, _a) {
77
+ var key = _a[0], value = _a[1];
78
+ previousValue[key] = pack(value);
79
+ return previousValue;
80
+ }, {});
81
+ };
82
+ exports.encodeParams = encodeParams;
83
+ /**
84
+ * 解密
85
+ * @param params
86
+ */
87
+ var decodeParams = function (params) {
88
+ return Object.entries(__assign({}, params)).reduce(function (previousValue, _a) {
89
+ var key = _a[0], value = _a[1];
90
+ previousValue[key] = unpack(value);
91
+ return previousValue;
92
+ }, {});
93
+ };
94
+ exports.decodeParams = decodeParams;
@@ -235,9 +235,28 @@ function useTable(request, options) {
235
235
  /**
236
236
  * 刷新
237
237
  */
238
- var refresh = (0, react_1.useCallback)(function () {
239
- initList(paginationRef.current.current, paginationRef.current.pageSize);
240
- }, [initList]);
238
+ var refresh = (0, react_1.useCallback)(function (searchData) {
239
+ if (searchData) {
240
+ var _searchParams = {
241
+ column: searchParams.column,
242
+ order: searchParams.order
243
+ };
244
+ if (searchData === null || searchData === void 0 ? void 0 : searchData.pageSize) {
245
+ setPagination(__assign(__assign({}, pagination), { pageSize: searchData.pageSize }));
246
+ }
247
+ if (searchData === null || searchData === void 0 ? void 0 : searchData.pageNum) {
248
+ setPagination(__assign(__assign({}, pagination), { current: searchData.pageNum }));
249
+ }
250
+ for (var key in searchParams) {
251
+ delete searchParams[key];
252
+ }
253
+ Object.assign(searchParams, _searchParams, searchData);
254
+ initList((searchData === null || searchData === void 0 ? void 0 : searchData.pageNum) || pagination.current, (searchData === null || searchData === void 0 ? void 0 : searchData.pageSize) || pagination.pageSize);
255
+ }
256
+ else {
257
+ initList(pagination.current, pagination.pageSize);
258
+ }
259
+ }, [initList, pagination, searchParams]);
241
260
  /**
242
261
  * 列表上的筛选排序执行
243
262
  * @param pagination 分页信息
@@ -125,6 +125,7 @@ declare interface ConfigContextProps {
125
125
  iconButton: IconButtonConfig;
126
126
  iconFont: IconFontConfig;
127
127
  locale: MessagesKeys;
128
+ useSearchParams: UseSearchParamsOptions;
128
129
  }
129
130
 
130
131
  export declare function ConfigProvider({ children, config }: ConfigProviderProps): default_2.JSX.Element;
@@ -279,7 +280,7 @@ declare interface OptionsProps<T = AnyObject> {
279
280
  * 响应时回调
280
281
  * @param response 响应数据
281
282
  */
282
- onAfterRequest?: <R = T>(response: ResponseType_2<R>) => Promise<ResponseType_2<R> | undefined> | R[] | undefined;
283
+ onAfterRequest?: <R = T>(response: ResponseJSON) => Promise<ResponseType_2<R> | undefined> | R[] | undefined;
283
284
  }
284
285
 
285
286
  declare interface PaginationResponse<T> {
@@ -343,7 +344,7 @@ declare interface ReturnData<T = AnyObject> {
343
344
  /**
344
345
  * 刷新页面
345
346
  */
346
- refresh: () => void;
347
+ refresh: (searchData?: Record<string, unknown>) => void;
347
348
  };
348
349
  /**
349
350
  * 多选条件
@@ -448,6 +449,17 @@ declare interface ToggleButtonProps {
448
449
 
449
450
  export declare function useRequest<TData, TParams extends unknown[]>(service: Service<TData, TParams>, options?: Options<TData, TParams>, plugins?: Array<Plugin_2<TData, TParams>>): WrappedResult<TData, TParams>;
450
451
 
452
+ declare interface UseSearchParamsOptions {
453
+ /**
454
+ * 存储方式:url 参数或路由 state
455
+ */
456
+ storage?: 'url' | 'state';
457
+ /**
458
+ * 路由 state 模式下存储的 key
459
+ */
460
+ stateKey?: string;
461
+ }
462
+
451
463
  export declare function useTable<T = AnyObject, P = RequestParams>(request: RequestFunction<T, P>, options?: OptionsProps<T>): ReturnData<T>;
452
464
 
453
465
  declare interface WrappedResult<TData, TParams extends unknown[]> extends Omit<Result<TData, TParams>, 'data'> {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xmirror-components",
3
- "version": "1.0.32",
3
+ "version": "1.0.34-alpha.1",
4
4
  "type": "module",
5
5
  "main": "build/lib/index.js",
6
6
  "module": "build/es/index.js",
@@ -29,20 +29,23 @@
29
29
  "lodash-es": ">=4.17.0",
30
30
  "react": ">=18.0.0",
31
31
  "react-dom": ">=18.0.0",
32
- "react-intl": ">=7.0.0",
33
- "react-transition-group": ">=4.4.0"
32
+ "react-intl": "^7.1.14",
33
+ "react-transition-group": ">=4.4.0",
34
+ "@ahooksjs/use-url-state": "^3.5.1",
35
+ "react-router-dom": "^6.30.2"
34
36
  },
35
37
  "dependencies": {
36
38
  "@emotion/react": "^11.14.0",
37
39
  "@emotion/styled": "^11.14.1",
38
40
  "@types/react-resizable": "^3.0.8",
41
+ "classnames": "^2.5.1",
39
42
  "react-resizable": "^3.0.5"
40
43
  },
41
44
  "devDependencies": {
42
45
  "@types/lodash-es": "^4.17.12",
43
46
  "@types/node": "^22.13.10",
44
- "@types/react": "^19.0.10",
45
- "@types/react-dom": "^19.0.4",
47
+ "@types/react": "^18.2.0",
48
+ "@types/react-dom": "^18.2.0",
46
49
  "@types/react-transition-group": "^4.4.12",
47
50
  "@vitejs/plugin-react-swc": "^3.8.0",
48
51
  "eslint": "^9.21.0",
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import { IconButtonProps } from "../IconButton";
3
3
  import { IconFontProps } from "../IconFont";
4
+ import { UseSearchParamsOptions } from "../../hooks/useSearchParams/types";
4
5
  import { type MessagesKeys } from "../../locale";
5
6
  type IconButtonConfig = Pick<IconButtonProps, 'size' | 'className' | 'style'> & {
6
7
  render: (props: IconButtonProps & {
@@ -12,6 +13,7 @@ export interface ConfigContextProps {
12
13
  iconButton: IconButtonConfig;
13
14
  iconFont: IconFontConfig;
14
15
  locale: MessagesKeys;
16
+ useSearchParams: UseSearchParamsOptions;
15
17
  }
16
18
  export type ConfigProviderConfigProps = Partial<ConfigContextProps>;
17
19
  export {};
@@ -0,0 +1,3 @@
1
+ import type { SearchParams, SearchParamsType, UseSearchParamsOptions } from './types.ts';
2
+ declare const useSearchParams: <T extends SearchParamsType>(initialValue: T, options?: UseSearchParamsOptions) => SearchParams<T>;
3
+ export default useSearchParams;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * 搜索参数类型
3
+ */
4
+ export type SearchParamsType = Record<string, any>;
5
+ /**
6
+ * 编码后的搜索参数类型
7
+ */
8
+ export type EncodeSearchParamsType = Record<string, string>;
9
+ /**
10
+ * 搜索参数接口
11
+ */
12
+ export interface SearchParams<T extends SearchParamsType> {
13
+ /**
14
+ * 当前搜索参数
15
+ */
16
+ searchParams: T;
17
+ /**
18
+ * 设置搜索参数
19
+ */
20
+ setSearchParams: (value: T | Partial<T> | ((prev: T) => T)) => void;
21
+ }
22
+ export interface UseSearchParamsOptions {
23
+ /**
24
+ * 存储方式:url 参数或路由 state
25
+ */
26
+ storage?: 'url' | 'state';
27
+ /**
28
+ * 路由 state 模式下存储的 key
29
+ */
30
+ stateKey?: string;
31
+ }
@@ -0,0 +1,11 @@
1
+ import type { EncodeSearchParamsType, SearchParamsType } from './types.ts';
2
+ /**
3
+ * 加密
4
+ * @param params
5
+ */
6
+ export declare const encodeParams: (params: SearchParamsType) => EncodeSearchParamsType;
7
+ /**
8
+ * 解密
9
+ * @param params
10
+ */
11
+ export declare const decodeParams: (params: EncodeSearchParamsType) => SearchParamsType;
@@ -70,7 +70,7 @@ export interface OptionsProps<T = AnyObject> {
70
70
  * 响应时回调
71
71
  * @param response 响应数据
72
72
  */
73
- onAfterRequest?: <R = T>(response: ResponseType<R>) => Promise<ResponseType<R> | undefined> | R[] | undefined;
73
+ onAfterRequest?: <R = T>(response: ResponseJSON) => Promise<ResponseType<R> | undefined> | R[] | undefined;
74
74
  }
75
75
  export interface ReturnData<T = AnyObject> {
76
76
  /**
@@ -105,7 +105,7 @@ export interface ReturnData<T = AnyObject> {
105
105
  /**
106
106
  * 刷新页面
107
107
  */
108
- refresh: () => void;
108
+ refresh: (searchData?: Record<string, unknown>) => void;
109
109
  };
110
110
  /**
111
111
  * 多选条件
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xmirror-components",
3
- "version": "1.0.32",
3
+ "version": "1.0.34-alpha.1",
4
4
  "type": "module",
5
5
  "main": "build/lib/index.js",
6
6
  "module": "build/es/index.js",
@@ -29,20 +29,23 @@
29
29
  "lodash-es": ">=4.17.0",
30
30
  "react": ">=18.0.0",
31
31
  "react-dom": ">=18.0.0",
32
- "react-intl": ">=7.0.0",
33
- "react-transition-group": ">=4.4.0"
32
+ "react-intl": "^7.1.14",
33
+ "react-transition-group": ">=4.4.0",
34
+ "@ahooksjs/use-url-state": "^3.5.1",
35
+ "react-router-dom": "^6.30.2"
34
36
  },
35
37
  "dependencies": {
36
38
  "@emotion/react": "^11.14.0",
37
39
  "@emotion/styled": "^11.14.1",
38
40
  "@types/react-resizable": "^3.0.8",
41
+ "classnames": "^2.5.1",
39
42
  "react-resizable": "^3.0.5"
40
43
  },
41
44
  "devDependencies": {
42
45
  "@types/lodash-es": "^4.17.12",
43
46
  "@types/node": "^22.13.10",
44
- "@types/react": "^19.0.10",
45
- "@types/react-dom": "^19.0.4",
47
+ "@types/react": "^18.2.0",
48
+ "@types/react-dom": "^18.2.0",
46
49
  "@types/react-transition-group": "^4.4.12",
47
50
  "@vitejs/plugin-react-swc": "^3.8.0",
48
51
  "eslint": "^9.21.0",