xmirror-components 1.0.35 → 1.0.37

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.
@@ -1,3 +1,12 @@
1
1
  import type { SearchParams, SearchParamsType, UseSearchParamsOptions } from './types.ts';
2
+ declare global {
3
+ interface Window {
4
+ routerHistory: Map<string, {
5
+ path: string;
6
+ replace: boolean;
7
+ state?: Record<string, any>;
8
+ }>;
9
+ }
10
+ }
2
11
  declare const useSearchParams: <T extends SearchParamsType>(initialValue: T, options?: UseSearchParamsOptions) => SearchParams<T>;
3
12
  export default useSearchParams;
@@ -55,6 +55,8 @@ import { ConfigContext } from '../../components/ConfigProvider';
55
55
  var initialSearchParams = {
56
56
  y: undefined
57
57
  };
58
+ // 确保 routerHistory 已初始化
59
+ window.routerHistory = window.routerHistory || new Map();
58
60
  var useSearchParams = function (initialValue, options) {
59
61
  var _a;
60
62
  var defaultConfigOptions = useContext(ConfigContext).useSearchParams;
@@ -85,17 +87,33 @@ var useSearchParams = function (initialValue, options) {
85
87
  * 根据配置更新存储
86
88
  */
87
89
  var persistParams = function (params) { return __awaiter(void 0, void 0, void 0, function () {
88
- var payload;
89
- var _a;
90
- return __generator(this, function (_b) {
90
+ var payload, params_1, search, key, value;
91
+ var _a, _b;
92
+ return __generator(this, function (_c) {
91
93
  payload = __assign(__assign({}, params), { y: window.scrollY });
92
94
  if (storage === 'url') {
93
- setUrlParams(encodeParams(payload));
95
+ params_1 = encodeParams(payload);
96
+ setUrlParams(params_1);
97
+ search = '';
98
+ for (key in params_1) {
99
+ value = params_1[key];
100
+ search += "".concat(key, "=").concat(value, "&");
101
+ }
102
+ search = search.slice(0, -1);
103
+ window.routerHistory.set(location.pathname, {
104
+ path: "".concat(location.pathname, "?").concat(search),
105
+ replace: true,
106
+ });
94
107
  return [2 /*return*/];
95
108
  }
109
+ window.routerHistory.set(location.pathname, {
110
+ path: location.pathname,
111
+ replace: true,
112
+ state: __assign(__assign({}, (location.state || {})), (_a = {}, _a[stateKey] = payload, _a)),
113
+ });
96
114
  navigator(location.pathname, {
97
115
  replace: true,
98
- state: __assign(__assign({}, location.state), (_a = {}, _a[stateKey] = payload, _a))
116
+ state: __assign(__assign({}, location.state), (_b = {}, _b[stateKey] = payload, _b))
99
117
  });
100
118
  return [2 /*return*/];
101
119
  });
@@ -159,6 +177,9 @@ var useSearchParams = function (initialValue, options) {
159
177
  !navEndRef.current))) {
160
178
  setTimeout(function () {
161
179
  var targetLocation = targetLocationRef.current;
180
+ if (!targetLocation) {
181
+ return;
182
+ }
162
183
  var path = "".concat(targetLocation.pathname).concat(targetLocation.search);
163
184
  navigator(path, {
164
185
  replace: targetLocation.historyAction !== 'PUSH',
@@ -295,6 +295,14 @@ function useTable(request, options) {
295
295
  var currentPageSize = (_c = pagination.pageSize) !== null && _c !== void 0 ? _c : paginationRef.current.pageSize;
296
296
  initList(currentPage, currentPageSize);
297
297
  }, [initList, searchParams]);
298
+ var reset = function () {
299
+ setSelectedRows([]);
300
+ setTableData([]);
301
+ setPagination(__assign({ current: 1, pageSize: 10, total: 0 }, defaultPagination));
302
+ setLoading(false);
303
+ searchParams.pageNum = 1;
304
+ searchParams.pageSize = (defaultPagination === null || defaultPagination === void 0 ? void 0 : defaultPagination.pageSize) || 10;
305
+ };
298
306
  // 初始化
299
307
  useEffect(function () {
300
308
  if (immediate) {
@@ -321,7 +329,8 @@ function useTable(request, options) {
321
329
  pagination: pagination,
322
330
  params: searchParams,
323
331
  submit: search,
324
- refresh: refresh
332
+ refresh: refresh,
333
+ reset: reset
325
334
  },
326
335
  rowSelection: {
327
336
  selectedRows: selectedRows,
@@ -106,6 +106,10 @@ export interface ReturnData<T = AnyObject> {
106
106
  * 刷新页面
107
107
  */
108
108
  refresh: (searchData?: Record<string, unknown>) => void;
109
+ /**
110
+ * 重置分页信息
111
+ */
112
+ reset: () => void;
109
113
  };
110
114
  /**
111
115
  * 多选条件
@@ -60,6 +60,8 @@ var ConfigProvider_1 = require("../../components/ConfigProvider");
60
60
  var initialSearchParams = {
61
61
  y: undefined
62
62
  };
63
+ // 确保 routerHistory 已初始化
64
+ window.routerHistory = window.routerHistory || new Map();
63
65
  var useSearchParams = function (initialValue, options) {
64
66
  var _a;
65
67
  var defaultConfigOptions = (0, react_1.useContext)(ConfigProvider_1.ConfigContext).useSearchParams;
@@ -90,17 +92,33 @@ var useSearchParams = function (initialValue, options) {
90
92
  * 根据配置更新存储
91
93
  */
92
94
  var persistParams = function (params) { return __awaiter(void 0, void 0, void 0, function () {
93
- var payload;
94
- var _a;
95
- return __generator(this, function (_b) {
95
+ var payload, params_1, search, key, value;
96
+ var _a, _b;
97
+ return __generator(this, function (_c) {
96
98
  payload = __assign(__assign({}, params), { y: window.scrollY });
97
99
  if (storage === 'url') {
98
- setUrlParams((0, util_1.encodeParams)(payload));
100
+ params_1 = (0, util_1.encodeParams)(payload);
101
+ setUrlParams(params_1);
102
+ search = '';
103
+ for (key in params_1) {
104
+ value = params_1[key];
105
+ search += "".concat(key, "=").concat(value, "&");
106
+ }
107
+ search = search.slice(0, -1);
108
+ window.routerHistory.set(location.pathname, {
109
+ path: "".concat(location.pathname, "?").concat(search),
110
+ replace: true,
111
+ });
99
112
  return [2 /*return*/];
100
113
  }
114
+ window.routerHistory.set(location.pathname, {
115
+ path: location.pathname,
116
+ replace: true,
117
+ state: __assign(__assign({}, (location.state || {})), (_a = {}, _a[stateKey] = payload, _a)),
118
+ });
101
119
  navigator(location.pathname, {
102
120
  replace: true,
103
- state: __assign(__assign({}, location.state), (_a = {}, _a[stateKey] = payload, _a))
121
+ state: __assign(__assign({}, location.state), (_b = {}, _b[stateKey] = payload, _b))
104
122
  });
105
123
  return [2 /*return*/];
106
124
  });
@@ -164,6 +182,9 @@ var useSearchParams = function (initialValue, options) {
164
182
  !navEndRef.current))) {
165
183
  setTimeout(function () {
166
184
  var targetLocation = targetLocationRef.current;
185
+ if (!targetLocation) {
186
+ return;
187
+ }
167
188
  var path = "".concat(targetLocation.pathname).concat(targetLocation.search);
168
189
  navigator(path, {
169
190
  replace: targetLocation.historyAction !== 'PUSH',
@@ -297,6 +297,14 @@ function useTable(request, options) {
297
297
  var currentPageSize = (_c = pagination.pageSize) !== null && _c !== void 0 ? _c : paginationRef.current.pageSize;
298
298
  initList(currentPage, currentPageSize);
299
299
  }, [initList, searchParams]);
300
+ var reset = function () {
301
+ setSelectedRows([]);
302
+ setTableData([]);
303
+ setPagination(__assign({ current: 1, pageSize: 10, total: 0 }, defaultPagination));
304
+ setLoading(false);
305
+ searchParams.pageNum = 1;
306
+ searchParams.pageSize = (defaultPagination === null || defaultPagination === void 0 ? void 0 : defaultPagination.pageSize) || 10;
307
+ };
300
308
  // 初始化
301
309
  (0, react_1.useEffect)(function () {
302
310
  if (immediate) {
@@ -323,7 +331,8 @@ function useTable(request, options) {
323
331
  pagination: pagination,
324
332
  params: searchParams,
325
333
  submit: search,
326
- refresh: refresh
334
+ refresh: refresh,
335
+ reset: reset
327
336
  },
328
337
  rowSelection: {
329
338
  selectedRows: selectedRows,
@@ -345,6 +345,10 @@ declare interface ReturnData<T = AnyObject> {
345
345
  * 刷新页面
346
346
  */
347
347
  refresh: (searchData?: Record<string, unknown>) => void;
348
+ /**
349
+ * 重置分页信息
350
+ */
351
+ reset: () => void;
348
352
  };
349
353
  /**
350
354
  * 多选条件
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xmirror-components",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "type": "module",
5
5
  "main": "build/lib/index.js",
6
6
  "module": "build/es/index.js",
@@ -1,3 +1,12 @@
1
1
  import type { SearchParams, SearchParamsType, UseSearchParamsOptions } from './types.ts';
2
+ declare global {
3
+ interface Window {
4
+ routerHistory: Map<string, {
5
+ path: string;
6
+ replace: boolean;
7
+ state?: Record<string, any>;
8
+ }>;
9
+ }
10
+ }
2
11
  declare const useSearchParams: <T extends SearchParamsType>(initialValue: T, options?: UseSearchParamsOptions) => SearchParams<T>;
3
12
  export default useSearchParams;
@@ -106,6 +106,10 @@ export interface ReturnData<T = AnyObject> {
106
106
  * 刷新页面
107
107
  */
108
108
  refresh: (searchData?: Record<string, unknown>) => void;
109
+ /**
110
+ * 重置分页信息
111
+ */
112
+ reset: () => void;
109
113
  };
110
114
  /**
111
115
  * 多选条件
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xmirror-components",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "type": "module",
5
5
  "main": "build/lib/index.js",
6
6
  "module": "build/es/index.js",