feat(utils): support replaceTab. (#713)
This commit is contained in:
parent
3e0076d466
commit
be6080ba0f
@ -18,12 +18,7 @@ export function useRouterPush(inSetup = true) {
|
|||||||
|
|
||||||
const routerBack = router.back;
|
const routerBack = router.back;
|
||||||
|
|
||||||
interface RouterPushOptions {
|
async function routerPushByKey(key: RouteKey, options?: App.Global.RouterPushOptions) {
|
||||||
query?: Record<string, string>;
|
|
||||||
params?: Record<string, string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function routerPushByKey(key: RouteKey, options?: RouterPushOptions) {
|
|
||||||
const { query, params } = options || {};
|
const { query, params } = options || {};
|
||||||
|
|
||||||
const routeLocation: RouteLocationRaw = {
|
const routeLocation: RouteLocationRaw = {
|
||||||
@ -67,7 +62,7 @@ export function useRouterPush(inSetup = true) {
|
|||||||
async function toLogin(loginModule?: UnionKey.LoginModule, redirectUrl?: string) {
|
async function toLogin(loginModule?: UnionKey.LoginModule, redirectUrl?: string) {
|
||||||
const module = loginModule || 'pwd-login';
|
const module = loginModule || 'pwd-login';
|
||||||
|
|
||||||
const options: RouterPushOptions = {
|
const options: App.Global.RouterPushOptions = {
|
||||||
params: {
|
params: {
|
||||||
module
|
module
|
||||||
}
|
}
|
||||||
|
@ -160,6 +160,25 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { routerPushByKey } = useRouterPush();
|
||||||
|
/**
|
||||||
|
* Replace tab
|
||||||
|
*
|
||||||
|
* @param key Route key
|
||||||
|
* @param options Router push options
|
||||||
|
*/
|
||||||
|
async function replaceTab(key: RouteKey, options?: App.Global.RouterPushOptions) {
|
||||||
|
const oldTabId = activeTabId.value;
|
||||||
|
|
||||||
|
// push new route
|
||||||
|
await routerPushByKey(key, options);
|
||||||
|
|
||||||
|
// remove old tab (exclude fixed tab)
|
||||||
|
if (!isTabRetain(oldTabId)) {
|
||||||
|
await removeTab(oldTabId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switch route by tab
|
* Switch route by tab
|
||||||
*
|
*
|
||||||
@ -282,6 +301,7 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
|
|||||||
removeTab,
|
removeTab,
|
||||||
removeActiveTab,
|
removeActiveTab,
|
||||||
removeTabByRouteName,
|
removeTabByRouteName,
|
||||||
|
replaceTab,
|
||||||
clearTabs,
|
clearTabs,
|
||||||
clearLeftTabs,
|
clearLeftTabs,
|
||||||
clearRightTabs,
|
clearRightTabs,
|
||||||
|
6
src/typings/app.d.ts
vendored
6
src/typings/app.d.ts
vendored
@ -175,6 +175,12 @@ declare namespace App {
|
|||||||
type RoutePath = import('@elegant-router/types').RoutePath;
|
type RoutePath = import('@elegant-router/types').RoutePath;
|
||||||
type LastLevelRouteKey = import('@elegant-router/types').LastLevelRouteKey;
|
type LastLevelRouteKey = import('@elegant-router/types').LastLevelRouteKey;
|
||||||
|
|
||||||
|
/** The router push options */
|
||||||
|
type RouterPushOptions = {
|
||||||
|
query?: Record<string, string>;
|
||||||
|
params?: Record<string, string>;
|
||||||
|
};
|
||||||
|
|
||||||
/** The global header props */
|
/** The global header props */
|
||||||
interface HeaderProps {
|
interface HeaderProps {
|
||||||
/** Whether to show the logo */
|
/** Whether to show the logo */
|
||||||
|
Loading…
Reference in New Issue
Block a user