|
|
@@ -0,0 +1,729 @@
|
|
|
+import { HMRouterMgr } from '@hadss/hmrouter';
|
|
|
+import { RoutePath } from './RoutePath';
|
|
|
+import { RouteConfig } from './RouteConfig';
|
|
|
+import { RouteParamsHelper } from './RouteParamsHelper';
|
|
|
+import { LogHelper } from '../log/LogHelper';
|
|
|
+import { RouteInterceptorManager } from './RouteInterceptor';
|
|
|
+import { ARouter } from './ARouter';
|
|
|
+import { AuthGuardHolder } from '../auth/AuthGuardHolder';
|
|
|
+import type { IAuthGuard } from '../auth/IAuthGuard';
|
|
|
+
|
|
|
+/**
|
|
|
+ * 路由管理器(单例)
|
|
|
+ *
|
|
|
+ * 统一管理所有页面跳转,使用 HMRouterMgr 进行跳转
|
|
|
+ *
|
|
|
+ * 规范:
|
|
|
+ * - 所有页面跳转必须通过 RouterManager
|
|
|
+ * - 禁止直接使用 HMRouterMgr.to()
|
|
|
+ * - Token 过期跳转必须使用 navigateToLoginOnTokenExpired()
|
|
|
+ *
|
|
|
+ * 使用方式:
|
|
|
+ * ```typescript
|
|
|
+ * import { RouterManager } from '@xdz/base-common';
|
|
|
+ *
|
|
|
+ * // 跳转到登录页
|
|
|
+ * RouterManager.navigateToLogin();
|
|
|
+ *
|
|
|
+ * // 跳转到帖子详情页
|
|
|
+ * RouterManager.navigateToPostDetail(123);
|
|
|
+ * ```
|
|
|
+ */
|
|
|
+/**
|
|
|
+ * 将 RoutePath 文件路径转换为 RouteConfig routeKey
|
|
|
+ */
|
|
|
+export function getRouteKeyFromPath(filePath: string): string {
|
|
|
+ // 映射文件路径到 routeKey
|
|
|
+ const pathToKeyMap: Record<string, string> = {
|
|
|
+ "pages/Index": "APP_MAIN",
|
|
|
+ "modules/auth/pages/LoginPage": "AUTH_LOGIN",
|
|
|
+ "modules/auth/pages/RegisterPage": "AUTH_REGISTER",
|
|
|
+ "modules/auth/pages/UnifiedLoginPage": "AUTH_VERIFY_CODE_LOGIN",
|
|
|
+ // 密码登录路由映射到统一登录页面(通过参数区分模式)
|
|
|
+ "modules/auth/pages/PasswordLoginPage": "AUTH_PASSWORD_LOGIN",
|
|
|
+ "modules/auth/pages/ThirdPartyBindingPage": "AUTH_THIRD_PARTY_BINDING",
|
|
|
+ "modules/auth/pages/ResetPasswordPage": "AUTH_RESET_PASSWORD",
|
|
|
+ "modules/community/pages/PostDetailPage": "COMMUNITY_POST_DETAIL",
|
|
|
+ "modules/community/pages/CreatePostPage": "COMMUNITY_CREATE_POST",
|
|
|
+ "modules/user/pages/PersonalInfoPage": "USER_PERSONAL_INFO",
|
|
|
+ "modules/user/pages/SettingsPage": "USER_SETTINGS",
|
|
|
+ "modules/user/pages/AccountManagePage": "USER_ACCOUNT_MANAGE",
|
|
|
+ "modules/user/pages/MessageListPage": "USER_MESSAGE_LIST",
|
|
|
+ "modules/user/pages/CollectListPage": "USER_COLLECT_LIST",
|
|
|
+ "modules/user/pages/VehicleListPage": "USER_VEHICLE_LIST",
|
|
|
+ "modules/user/pages/OrderListPage": "USER_ORDER_LIST",
|
|
|
+ "modules/user/pages/ActivityListPage": "USER_ACTIVITY_LIST",
|
|
|
+ "modules/user/pages/InvitePage": "USER_INVITE",
|
|
|
+ "modules/user/pages/RidingStatisticsPage": "USER_RIDING_STATISTICS",
|
|
|
+ "modules/user/pages/FeedbackPage": "USER_FEEDBACK",
|
|
|
+ "modules/user/pages/ContactPage": "USER_CONTACT",
|
|
|
+ "modules/user/pages/BlacklistPage": "USER_BLACKLIST",
|
|
|
+ "modules/user/pages/SimplePlaceholderPage": "USER_SIMPLE_PLACEHOLDER",
|
|
|
+ "modules/vehicle/pages/VehicleBindPage": "VEHICLE_BIND",
|
|
|
+ "modules/vehicle/pages/VehicleQRScanPage": "QRCODE_SCAN",
|
|
|
+ "modules/vehicle/pages/VehicleBindConfirmPage": "VEHICLE_BIND_CONFIRM",
|
|
|
+ "modules/vehicle/pages/VehicleManagePage": "VEHICLE_MANAGE",
|
|
|
+ "modules/vehicle/pages/RidingRecordListPage": "RIDING_RECORD_LIST",
|
|
|
+ "modules/vehicle/pages/RidingRecordDetailPage": "RIDING_RECORD_DETAIL",
|
|
|
+ "modules/vehicle/pages/FirmwareUpgradePage": "FIRMWARE_UPGRADE",
|
|
|
+ "modules/vehicle/pages/FirmwareUpgradeDetailPage": "FIRMWARE_UPGRADE_DETAIL",
|
|
|
+ "modules/vehicle/pages/MapPage": "MAP",
|
|
|
+ "modules/vehicle/pages/KeySharePage": "KEY_SHARE",
|
|
|
+ "modules/vehicle/pages/BatteryDetailsPage": "BATTERY_DETAILS",
|
|
|
+ "modules/vehicle/pages/BluetoothDeviceSearchPage": "VEHICLE_BLE_SEARCH",
|
|
|
+ "modules/vehicle/pages/TirePressurePage": "TIRE_PRESSURE",
|
|
|
+ "modules/vehicle/pages/AmbientLightSettingsPage": "AMBIENT_LIGHT_SETTINGS",
|
|
|
+ "modules/vehicle/pages/RGBColorPickerPage": "RGB_COLOR_PICKER",
|
|
|
+ "modules/vehicle/pages/SetStartupPasswordPage": "SET_STARTUP_PASSWORD",
|
|
|
+ "modules/vehicle/pages/CreateSharePage": "CREATE_SHARE",
|
|
|
+ "modules/vehicle/pages/DrivingRecorderPage": "DRIVING_RECORDER",
|
|
|
+ "modules/vehicle/pages/SmartAccessoriesPage": "SMART_ACCESSORIES"
|
|
|
+ };
|
|
|
+ return pathToKeyMap[filePath] || filePath;
|
|
|
+}
|
|
|
+
|
|
|
+export class RouterManager {
|
|
|
+ private static readonly TAG = 'RouterManager';
|
|
|
+ private static logoutCallback: (() => void) | null = null;
|
|
|
+ /**
|
|
|
+ * 设置认证守卫(3.3.2,entry 在 init 后调用)
|
|
|
+ */
|
|
|
+ static setAuthGuard(guard: IAuthGuard | null): void {
|
|
|
+ AuthGuardHolder.setGuard(guard);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化(在 AppInitializer 中调用)
|
|
|
+ *
|
|
|
+ * @param logoutCallback 登出回调(从 entry 模块传入,与 setAuthGuard 二选一或同时使用)
|
|
|
+ */
|
|
|
+ static init(logoutCallback?: () => void): void {
|
|
|
+ RouterManager.logoutCallback = logoutCallback || null;
|
|
|
+ RouteInterceptorManager.init();
|
|
|
+ ARouter.init();
|
|
|
+ LogHelper.d(RouterManager.TAG, 'RouterManager 初始化完成');
|
|
|
+ }
|
|
|
+
|
|
|
+ // ========== 认证相关路由 ==========
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到登录页(Token 过期专用)
|
|
|
+ *
|
|
|
+ * 特点:
|
|
|
+ * - 清除路由栈
|
|
|
+ * - 无法返回
|
|
|
+ * - 清除登录状态
|
|
|
+ *
|
|
|
+ * 使用场景:
|
|
|
+ * - Token 刷新失败
|
|
|
+ * - 401/402 响应且刷新失败
|
|
|
+ */
|
|
|
+ static navigateToLoginOnTokenExpired(): void {
|
|
|
+ LogHelper.d(RouterManager.TAG, 'Token 过期,跳转到登录页(清除路由栈)');
|
|
|
+ const guard = AuthGuardHolder.getGuard();
|
|
|
+ if (guard) {
|
|
|
+ guard.logout();
|
|
|
+ }
|
|
|
+ if (RouterManager.logoutCallback) {
|
|
|
+ RouterManager.logoutCallback();
|
|
|
+ }
|
|
|
+ // 清空路由栈并跳转到登录页
|
|
|
+ HMRouterMgr.to('AUTH_LOGIN').pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到登录页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 登录成功后回跳(2.2.4)
|
|
|
+ * 若当前页参数带有 targetRoute,则跳转至该路由;否则跳转主界面。
|
|
|
+ */
|
|
|
+ static navigateAfterLogin(): void {
|
|
|
+ const params = RouteParamsHelper.getParams();
|
|
|
+ const targetRoute = params ? RouteParamsHelper.getString(params, 'targetRoute', '') : '';
|
|
|
+ if (targetRoute !== '' && RouteConfig.hasRoute(targetRoute)) {
|
|
|
+ LogHelper.d(RouterManager.TAG, `登录回跳: ${targetRoute}`);
|
|
|
+ ARouter.build(targetRoute).skipInterceptor().navigation();
|
|
|
+ } else {
|
|
|
+ RouterManager.navigateToMain();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到登录页(普通跳转)
|
|
|
+ *
|
|
|
+ * @param skipInterceptors 是否跳过拦截器(默认 false)
|
|
|
+ */
|
|
|
+ static async navigateToLogin(skipInterceptors: boolean = false): Promise<void> {
|
|
|
+ LogHelper.d('PageDebug', `[RouterManager] navigateToLogin 开始, skipInterceptors=${skipInterceptors}`);
|
|
|
+ // 跳转到登录页时,总是跳过拦截器(避免循环拦截)
|
|
|
+ const canNavigate = await RouteInterceptorManager.check(RoutePath.LOGIN, undefined, true);
|
|
|
+ LogHelper.d('PageDebug', `[RouterManager] RouteInterceptorManager.check 返回: ${canNavigate}`);
|
|
|
+ if (!canNavigate) {
|
|
|
+ LogHelper.w('PageDebug', '[RouterManager] 路由拦截器阻止跳转到登录页');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ LogHelper.d('PageDebug', '[RouterManager] 准备跳转到登录页');
|
|
|
+ try {
|
|
|
+ // 检查 HMNavigation 是否存在
|
|
|
+ LogHelper.d('PageDebug', '[RouterManager] 检查 HMNavigation (mainNavigation) 是否存在...');
|
|
|
+ try {
|
|
|
+ const pathStack = HMRouterMgr.getPathStack('mainNavigation');
|
|
|
+ LogHelper.d('PageDebug', `[RouterManager] HMNavigation pathStack: ${pathStack ? '存在' : '不存在'}`);
|
|
|
+ if (pathStack) {
|
|
|
+ LogHelper.d('PageDebug', `[RouterManager] pathStack 详情: ${JSON.stringify(pathStack)}`);
|
|
|
+ }
|
|
|
+ } catch (stackError) {
|
|
|
+ LogHelper.e('PageDebug', '[RouterManager] 获取 pathStack 失败,可能 HMNavigation 未创建', stackError as Error);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用 HMRouter 标准跳转方式(必须指定 navigationId)
|
|
|
+ LogHelper.d('PageDebug', '[RouterManager] 调用 HMRouterMgr.push({ navigationId: "mainNavigation", pageUrl: "AUTH_LOGIN" })');
|
|
|
+ const pushResult = await HMRouterMgr.push({
|
|
|
+ navigationId: 'mainNavigation',
|
|
|
+ pageUrl: 'AUTH_LOGIN'
|
|
|
+ });
|
|
|
+ LogHelper.d('PageDebug', `[RouterManager] push 返回结果: ${pushResult}`);
|
|
|
+ LogHelper.d('PageDebug', '[RouterManager] 跳转到登录页成功,LoginPage 应该已创建');
|
|
|
+
|
|
|
+ // 再次检查 pathStack,确认页面是否已添加
|
|
|
+ setTimeout(() => {
|
|
|
+ try {
|
|
|
+ const pathStackAfter = HMRouterMgr.getPathStack('mainNavigation');
|
|
|
+ LogHelper.d('PageDebug', `[RouterManager] push 后 pathStack: ${pathStackAfter ? '存在' : '不存在'}`);
|
|
|
+ if (pathStackAfter) {
|
|
|
+ LogHelper.d('PageDebug', `[RouterManager] push 后 pathStack 详情: ${JSON.stringify(pathStackAfter)}`);
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ LogHelper.e('PageDebug', '[RouterManager] push 后获取 pathStack 失败', e as Error);
|
|
|
+ }
|
|
|
+ }, 100);
|
|
|
+ } catch (error) {
|
|
|
+ LogHelper.e('PageDebug', '[RouterManager] 跳转到登录页异常', error as Error);
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到登录页失败', error as Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到注册页
|
|
|
+ */
|
|
|
+ static navigateToRegister(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.REGISTER);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到注册页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到验证码登录页(统一登录页面,默认显示验证码登录)
|
|
|
+ */
|
|
|
+ static navigateToVerifyCodeLogin(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.VERIFY_CODE_LOGIN);
|
|
|
+ try {
|
|
|
+ HMRouterMgr.push({
|
|
|
+ navigationId: 'mainNavigation',
|
|
|
+ pageUrl: pageUrl
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到验证码登录页失败', error as Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到密码登录页(统一登录页面,显示密码登录)
|
|
|
+ */
|
|
|
+ static navigateToPasswordLogin(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.PASSWORD_LOGIN);
|
|
|
+ try {
|
|
|
+ HMRouterMgr.push({
|
|
|
+ navigationId: 'mainNavigation',
|
|
|
+ pageUrl: pageUrl
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到密码登录页失败', error as Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到忘记密码页(实际跳转到重置密码页)
|
|
|
+ * @param mobile 手机号(可选,如果提供则传递给重置密码页)
|
|
|
+ */
|
|
|
+ static navigateToForgotPassword(mobile?: string): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.RESET_PASSWORD);
|
|
|
+ if (mobile) {
|
|
|
+ // ✅ 修复:传递手机号参数
|
|
|
+ try {
|
|
|
+ HMRouterMgr.push({
|
|
|
+ navigationId: 'mainNavigation',
|
|
|
+ pageUrl: pageUrl,
|
|
|
+ param: { mobile: mobile } as ESObject
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到重置密码页失败', error as Error);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到重置密码页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** A.5 跳转重置密码页(从设置/账号安全进入,需登录) */
|
|
|
+ static navigateToResetPassword(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.RESET_PASSWORD);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到重置密码页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到第三方绑定页
|
|
|
+ *
|
|
|
+ * @param platform 平台名称(如:wechat, qq)
|
|
|
+ * @param openId 第三方平台的 openId
|
|
|
+ */
|
|
|
+ static navigateToThirdPartyBinding(platform: string, openId: string): void {
|
|
|
+ // 使用 ARouter 统一跳转
|
|
|
+ ARouter.build("AUTH_THIRD_PARTY_BINDING")
|
|
|
+ .withString("platform", platform)
|
|
|
+ .withString("openId", openId)
|
|
|
+ .navigation()
|
|
|
+ .catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到第三方绑定页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // ========== 主界面路由 ==========
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到主界面
|
|
|
+ */
|
|
|
+ static navigateToMain(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.MAIN); // 应该解析为 'APP_MAIN'
|
|
|
+ LogHelper.d(RouterManager.TAG, `[navigateToMain] 开始跳转,pageUrl: ${pageUrl}`);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync()
|
|
|
+ .then(() => {
|
|
|
+ LogHelper.d(RouterManager.TAG, '[navigateToMain] 跳转主界面成功');
|
|
|
+ })
|
|
|
+ .catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '[navigateToMain] 跳转主界面失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // ========== 社区相关路由 ==========
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到帖子详情页
|
|
|
+ *
|
|
|
+ * @param postId 帖子ID
|
|
|
+ */
|
|
|
+ static async navigateToPostDetail(postId: number): Promise<void> {
|
|
|
+ // 使用 ARouter 统一跳转
|
|
|
+ ARouter.build("COMMUNITY_POST_DETAIL")
|
|
|
+ .withInt("postId", postId)
|
|
|
+ .navigation()
|
|
|
+ .catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到帖子详情页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到创建帖子页
|
|
|
+ */
|
|
|
+ static async navigateToCreatePost(): Promise<void> {
|
|
|
+ const canNavigate = await RouteInterceptorManager.check(RoutePath.COMMUNITY_CREATE_POST);
|
|
|
+ if (!canNavigate) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.COMMUNITY_CREATE_POST);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到创建帖子页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // ========== 用户相关路由 ==========
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到个人资料页
|
|
|
+ */
|
|
|
+ static async navigateToPersonalInfo(): Promise<void> {
|
|
|
+ const canNavigate = await RouteInterceptorManager.check(RoutePath.USER_PERSONAL_INFO);
|
|
|
+ if (!canNavigate) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_PERSONAL_INFO);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到个人资料页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到设置页
|
|
|
+ */
|
|
|
+ static async navigateToSettings(): Promise<void> {
|
|
|
+ const canNavigate = await RouteInterceptorManager.check(RoutePath.USER_SETTINGS);
|
|
|
+ if (!canNavigate) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_SETTINGS);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到设置页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到账号管理页
|
|
|
+ */
|
|
|
+ static async navigateToAccountManage(): Promise<void> {
|
|
|
+ const canNavigate = await RouteInterceptorManager.check(RoutePath.USER_ACCOUNT_MANAGE);
|
|
|
+ if (!canNavigate) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_ACCOUNT_MANAGE);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到账号管理页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到活动列表页
|
|
|
+ */
|
|
|
+ static navigateToActivityList(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_ACTIVITY_LIST);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到活动列表页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到黑名单页
|
|
|
+ */
|
|
|
+ static navigateToBlacklist(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_BLACKLIST);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到黑名单页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到收藏列表页
|
|
|
+ */
|
|
|
+ static navigateToCollectList(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_COLLECT_LIST);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到收藏列表页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到联系我们页
|
|
|
+ */
|
|
|
+ static navigateToContact(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_CONTACT);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到联系我们页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到简单占位页
|
|
|
+ *
|
|
|
+ * @param title 页面标题
|
|
|
+ */
|
|
|
+ static navigateToSimplePlaceholder(title: string): void {
|
|
|
+ // 使用 ARouter 统一跳转
|
|
|
+ ARouter.build("USER_SIMPLE_PLACEHOLDER")
|
|
|
+ .withString("title", title)
|
|
|
+ .navigation()
|
|
|
+ .catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到简单占位页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到意见反馈页
|
|
|
+ */
|
|
|
+ static navigateToFeedback(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_FEEDBACK);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到意见反馈页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到邀友购车页
|
|
|
+ */
|
|
|
+ static navigateToInvite(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_INVITE);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到邀友购车页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到消息列表页
|
|
|
+ */
|
|
|
+ static navigateToMessageList(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_MESSAGE_LIST);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到消息列表页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到订单列表页
|
|
|
+ */
|
|
|
+ static navigateToOrderList(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_ORDER_LIST);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到订单列表页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到骑行统计页
|
|
|
+ */
|
|
|
+ static navigateToRidingStatistics(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_RIDING_STATISTICS);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到骑行统计页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到车辆列表页
|
|
|
+ */
|
|
|
+ static navigateToVehicleList(): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_VEHICLE_LIST);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到车辆列表页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到占位页
|
|
|
+ *
|
|
|
+ * @param title 页面标题
|
|
|
+ */
|
|
|
+ static navigateToPlaceholder(title: string): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(RoutePath.USER_SIMPLE_PLACEHOLDER);
|
|
|
+ HMRouterMgr.to(pageUrl).pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到占位页失败', error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // ========== 车辆相关路由 ==========
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到车辆绑定页
|
|
|
+ */
|
|
|
+ static navigateToVehicleBind(): void {
|
|
|
+ ARouter.build('VEHICLE_BIND').skipInterceptor().navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到车辆绑定页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到车辆绑定页并回填识别码(6.2.1 串联车辆绑定:扫码/手动输入后带参进入)
|
|
|
+ */
|
|
|
+ static navigateToVehicleBindWithCode(code: string): void {
|
|
|
+ ARouter.build('VEHICLE_BIND').withParam('code', code).skipInterceptor().navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到车辆绑定页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到车辆扫码页(6.1.x 生命周期/权限/重试;6.2.2 需登录,未登录会拦截并回跳扫码页)
|
|
|
+ */
|
|
|
+ static navigateToVehicleQRScan(): void {
|
|
|
+ ARouter.build('QRCODE_SCAN').navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到扫码页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 跳转绑定确认页(固定参数签名,避免 JSON.parse + 动态key) */
|
|
|
+ static navigateToVehicleBindConfirm(code: string, deviceName?: string): void {
|
|
|
+ const builder = ARouter.build('VEHICLE_BIND_CONFIRM');
|
|
|
+ builder.withParam('code', code);
|
|
|
+ if (deviceName !== undefined && deviceName !== '') {
|
|
|
+ builder.withParam('deviceName', deviceName);
|
|
|
+ }
|
|
|
+ builder.skipInterceptor().navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到绑定确认页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 跳转车辆管理页 */
|
|
|
+ static navigateToVehicleManage(vehicleId: number): void {
|
|
|
+ ARouter.build('VEHICLE_MANAGE').withParam('vehicleId', vehicleId).navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到车辆管理页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 跳转骑行记录列表 */
|
|
|
+ static navigateToRidingRecordList(vehicleId: number): void {
|
|
|
+ ARouter.build('RIDING_RECORD_LIST').withParam('vehicleId', vehicleId).navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到骑行记录列表失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 跳转骑行记录详情 */
|
|
|
+ static navigateToRidingRecordDetail(recordId: string): void {
|
|
|
+ ARouter.build('RIDING_RECORD_DETAIL').withParam('recordId', recordId).navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到骑行记录详情失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 跳转固件升级列表 */
|
|
|
+ static navigateToFirmwareUpgrade(vehicleId: number): void {
|
|
|
+ ARouter.build('FIRMWARE_UPGRADE').withParam('vehicleId', vehicleId).navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到固件升级页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 跳转固件升级详情 */
|
|
|
+ static navigateToFirmwareUpgradeDetail(vehicleId: number, firmwareId: number, firmwareName?: string, firmwareVersion?: string): void {
|
|
|
+ const builder = ARouter.build('FIRMWARE_UPGRADE_DETAIL')
|
|
|
+ .withParam('vehicleId', vehicleId)
|
|
|
+ .withParam('firmwareId', firmwareId);
|
|
|
+ if (firmwareName !== undefined) builder.withParam('firmwareName', firmwareName);
|
|
|
+ if (firmwareVersion !== undefined) builder.withParam('firmwareVersion', firmwareVersion);
|
|
|
+ builder.navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到固件升级详情失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** P1 跳转地图页 */
|
|
|
+ static navigateToMap(vehicleId: number): void {
|
|
|
+ ARouter.build('MAP').withParam('vehicleId', vehicleId).navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到地图页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** P1 跳转钥匙共享页 */
|
|
|
+ static navigateToKeyShare(vehicleId: number): void {
|
|
|
+ ARouter.build('KEY_SHARE').withParam('vehicleId', vehicleId).navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到钥匙共享页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** P1 跳转电池详情页 */
|
|
|
+ static navigateToBatteryDetails(vehicleId: number): void {
|
|
|
+ ARouter.build('BATTERY_DETAILS').withParam('vehicleId', vehicleId).navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到电池详情页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** P1 跳转蓝牙设备搜索页 */
|
|
|
+ static navigateToBluetoothDeviceSearch(): void {
|
|
|
+ ARouter.build('VEHICLE_BLE_SEARCH').navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到蓝牙设备搜索页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** P2 胎压 */
|
|
|
+ static navigateToTirePressure(vehicleId: number): void {
|
|
|
+ ARouter.build('TIRE_PRESSURE').withParam('vehicleId', vehicleId).navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到胎压页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** P2 氛围灯设置 */
|
|
|
+ static navigateToAmbientLightSettings(vehicleId: number): void {
|
|
|
+ ARouter.build('AMBIENT_LIGHT_SETTINGS').withParam('vehicleId', vehicleId).navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到氛围灯设置页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** P2 RGB 颜色选择(可选 callbackKey 用于回传) */
|
|
|
+ static navigateToRGBColorPicker(callbackKey?: string): void {
|
|
|
+ const b = ARouter.build('RGB_COLOR_PICKER');
|
|
|
+ if (callbackKey !== undefined) b.withParam('callbackKey', callbackKey);
|
|
|
+ b.navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到RGB选择页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** P2 开机密码设置 */
|
|
|
+ static navigateToSetStartupPassword(vehicleId: number): void {
|
|
|
+ ARouter.build('SET_STARTUP_PASSWORD').withParam('vehicleId', vehicleId).navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到开机密码页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** P2 创建分享 */
|
|
|
+ static navigateToCreateShare(vehicleId: number): void {
|
|
|
+ ARouter.build('CREATE_SHARE').withParam('vehicleId', vehicleId).navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到创建分享页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** P2 行车记录仪 */
|
|
|
+ static navigateToDrivingRecorder(vehicleId: number): void {
|
|
|
+ ARouter.build('DRIVING_RECORDER').withParam('vehicleId', vehicleId).navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到行车记录仪页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** P2 智能周边 */
|
|
|
+ static navigateToSmartAccessories(vehicleId?: number): void {
|
|
|
+ const b = ARouter.build('SMART_ACCESSORIES');
|
|
|
+ if (vehicleId !== undefined && vehicleId > 0) b.withParam('vehicleId', vehicleId);
|
|
|
+ b.navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到智能周边页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /** P2 车辆设置 */
|
|
|
+ static navigateToVehicleSettings(vehicleId: number): void {
|
|
|
+ ARouter.build('VEHICLE_SETTINGS').withParam('vehicleId', vehicleId).navigation().catch((e: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, '跳转到车辆设置页失败', e);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回上一页
|
|
|
+ */
|
|
|
+ static back(): void {
|
|
|
+ HMRouterMgr.popAsync();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 替换当前页面
|
|
|
+ *
|
|
|
+ * @param path 路由路径
|
|
|
+ * @param params 路由参数(可选)
|
|
|
+ */
|
|
|
+ static replace(path: string, params?: Record<string, Object>): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(path);
|
|
|
+ const builder = HMRouterMgr.to(pageUrl);
|
|
|
+ if (params) {
|
|
|
+ builder.withParam(params);
|
|
|
+ }
|
|
|
+ builder.pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, `替换页面失败: ${path}`, error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清空路由栈并跳转
|
|
|
+ *
|
|
|
+ * @param path 路由路径
|
|
|
+ * @param params 路由参数(可选)
|
|
|
+ */
|
|
|
+ static clearStack(path: string, params?: Record<string, Object>): void {
|
|
|
+ const pageUrl = getRouteKeyFromPath(path);
|
|
|
+ const builder = HMRouterMgr.to(pageUrl);
|
|
|
+ if (params) {
|
|
|
+ builder.withParam(params);
|
|
|
+ }
|
|
|
+ builder.pushAsync().catch((error: Error) => {
|
|
|
+ LogHelper.e(RouterManager.TAG, `清空栈并跳转失败: ${path}`, error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|