Commit 2dd3d8544866231895d23dba63785b683ae0062e

Authored by 无木
1 parent da12da9d

fix: fixed `useRedo` may loss route params

修复useRedo会丢失当前路由的params数据问题

fixed: #1079
CHANGELOG.zh_CN.md
@@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
17 - 修复在`editComponentProps`中为编辑组件提供的`size`属性无效的问题 17 - 修复在`editComponentProps`中为编辑组件提供的`size`属性无效的问题
18 - **Qrcode** 修复二维码组件在创建时未能及时绘制的问题 18 - **Qrcode** 修复二维码组件在创建时未能及时绘制的问题
19 - **BasicModal** 修复`helpMessage`属性不起作用的问题 19 - **BasicModal** 修复`helpMessage`属性不起作用的问题
  20 +- **其它** 修复`useRedo`(重新加载当前路由)会丢失路由`params`数据的问题
20 21
21 ## 2.7.0(2021-08-03) 22 ## 2.7.0(2021-08-03)
22 23
src/components/Table/src/BasicTable.vue
@@ -110,7 +110,7 @@ @@ -110,7 +110,7 @@
110 watchEffect(() => { 110 watchEffect(() => {
111 unref(isFixedHeightPage) && 111 unref(isFixedHeightPage) &&
112 props.canResize && 112 props.canResize &&
113 - warn("[BasicTable] 'canRize' not worked with PageWrapper while 'fixedHeight' is true"); 113 + warn("[BasicTable] 'canResize' may not worked in PageWrapper with 'fixedHeight'");
114 }); 114 });
115 115
116 const { getLoading, setLoading } = useLoading(getProps); 116 const { getLoading, setLoading } = useLoading(getProps);
src/hooks/web/usePage.ts
@@ -5,6 +5,7 @@ import { isString } from '/@/utils/is'; @@ -5,6 +5,7 @@ import { isString } from '/@/utils/is';
5 import { unref } from 'vue'; 5 import { unref } from 'vue';
6 6
7 import { useRouter } from 'vue-router'; 7 import { useRouter } from 'vue-router';
  8 +import { REDIRECT_NAME } from '/@/router/constant';
8 9
9 export type RouteLocationRawEx = Omit<RouteLocationRaw, 'path'> & { path: PageEnum }; 10 export type RouteLocationRawEx = Omit<RouteLocationRaw, 'path'> & { path: PageEnum };
10 11
@@ -37,19 +38,18 @@ export function useGo(_router?: Router) { @@ -37,19 +38,18 @@ export function useGo(_router?: Router) {
37 * @description: redo current page 38 * @description: redo current page
38 */ 39 */
39 export const useRedo = (_router?: Router) => { 40 export const useRedo = (_router?: Router) => {
40 - let router;  
41 - if (!_router) {  
42 - router = useRouter();  
43 - }  
44 - const { push, currentRoute } = _router || router;  
45 - const { query, params } = currentRoute.value; 41 + const { push, currentRoute } = _router || useRouter();
  42 + const { query, params = {}, name, fullPath } = unref(currentRoute.value);
46 function redo(): Promise<boolean> { 43 function redo(): Promise<boolean> {
47 return new Promise((resolve) => { 44 return new Promise((resolve) => {
48 - push({  
49 - path: '/redirect' + unref(currentRoute).fullPath,  
50 - query,  
51 - params,  
52 - }).then(() => resolve(true)); 45 + if (name && Object.keys(params).length > 0) {
  46 + params['_redirect_type'] = 'name';
  47 + params['path'] = String(name);
  48 + } else {
  49 + params['_redirect_type'] = 'path';
  50 + params['path'] = fullPath;
  51 + }
  52 + push({ name: REDIRECT_NAME, params, query }).then(() => resolve(true));
53 }); 53 });
54 } 54 }
55 return redo; 55 return redo;
src/router/routes/basic.ts
@@ -33,8 +33,8 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = { @@ -33,8 +33,8 @@ export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
33 33
34 export const REDIRECT_ROUTE: AppRouteRecordRaw = { 34 export const REDIRECT_ROUTE: AppRouteRecordRaw = {
35 path: '/redirect', 35 path: '/redirect',
36 - name: REDIRECT_NAME,  
37 component: LAYOUT, 36 component: LAYOUT,
  37 + name: 'RedirectTo',
38 meta: { 38 meta: {
39 title: REDIRECT_NAME, 39 title: REDIRECT_NAME,
40 hideBreadcrumb: true, 40 hideBreadcrumb: true,
src/views/sys/redirect/index.vue
@@ -8,12 +8,23 @@ @@ -8,12 +8,23 @@
8 const { currentRoute, replace } = useRouter(); 8 const { currentRoute, replace } = useRouter();
9 9
10 const { params, query } = unref(currentRoute); 10 const { params, query } = unref(currentRoute);
11 - const { path } = params; 11 + const { path, _redirect_type = 'path' } = params;
  12 +
  13 + Reflect.deleteProperty(params, '_redirect_type');
  14 + Reflect.deleteProperty(params, 'path');
12 15
13 const _path = Array.isArray(path) ? path.join('/') : path; 16 const _path = Array.isArray(path) ? path.join('/') : path;
14 17
15 - replace({  
16 - path: '/' + _path,  
17 - query,  
18 - }); 18 + if (_redirect_type === 'name') {
  19 + replace({
  20 + name: _path,
  21 + query,
  22 + params,
  23 + });
  24 + } else {
  25 + replace({
  26 + path: _path.startsWith('/') ? _path : '/' + _path,
  27 + query,
  28 + });
  29 + }
19 </script> 30 </script>