front/src/utils/enter-system.ts
zzh 3bfe6c6a26
All checks were successful
Build and Deploy Front / deploy (push) Successful in 6m30s
fix: 登录页签残留、表单校验脱节与仓库入口合并
排除登录路由进页签;FormPro 内部 model 优先;侧栏仓库选择与地址弹窗合并并可切换。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-26 12:19:47 +08:00

79 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { RouteLocationRaw } from 'vue-router';
import { isNavigationFailure } from 'vue-router';
import router from '@/router';
import { useUserStore, useTabBarStore } from '@/store';
import { ensureDynamicRouterReady } from '@/router/ensure-dynamic-router';
import { ensureHeavyPlugins } from '@/plugins/heavy-plugins';
import { ensureFullLocaleMessages } from '@/locale';
import { skipNextPageTransition } from '@/utils/page-transition-flag';
import type { UserInfoDto } from '@/api/rbac';
import { resolveAvatarUrl } from '@/utils/avatar';
export type EnterSystemTarget = {
path?: string;
name?: string;
query?: Record<string, unknown>;
};
/** 将 RBAC 用户写入 userStore(密码/微信/SSO 共用) */
export function applyRbacUserToUserStore(
userInfoData: UserInfoDto,
fallbackAccount = '',
) {
const userStore = useUserStore();
const displayName =
userInfoData.name ||
userInfoData.account ||
fallbackAccount ||
String(userInfoData.id ?? '');
userStore.setInfo({
account: userInfoData.account || fallbackAccount,
name: displayName,
avatar: resolveAvatarUrl(userInfoData.avatar),
email: userInfoData.email,
id: userInfoData.id,
accountId: userInfoData.id,
defaultModule: undefined,
moduleList: [],
});
}
/**
* 登录成功后进入系统(客户端 / 管理端共用)
*
* 关键路径只等:完整语言包 + 动态路由就绪 → replace
* 退场动画、重型插件:后台进行,不堵跳转
*/
export async function enterSystemAfterLogin(options: {
target: EnterSystemTarget;
fallbackPath: string;
playExit?: () => Promise<void>;
}): Promise<void> {
const userStore = useUserStore();
if (!userStore.chooseModuleGet) {
userStore.setModule(1);
}
void options.playExit?.();
void ensureHeavyPlugins();
await Promise.all([
ensureFullLocaleMessages(),
ensureDynamicRouterReady({ forceRefresh: false }),
]);
skipNextPageTransition();
// 登录壳不进业务页签;进系统前清空,避免残留「login」标签
useTabBarStore().resetTabList();
try {
await router.replace({ ...options.target } as RouteLocationRaw);
} catch (navErr) {
if (!isNavigationFailure(navErr)) throw navErr;
await router.replace({
path: options.fallbackPath,
query: (options.target.query || {}) as Record<string, string>,
});
}
}