优化冷启动流程:Launch Screen 对齐 Splash,仅阻塞 rolePermissions。
移除 SplashCoordinator,bootstrap 期间用 SplashView 覆盖避免空白闪屏,其余账号数据改为后台补充刷新。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -17,7 +17,7 @@ protocol UserProfileServing {
|
||||
@MainActor
|
||||
/// 账号上下文加载器,统一装配用户资料、角色权限、景区和门店上下文。
|
||||
struct AccountContextLoader {
|
||||
/// 刷新账号上下文,权限失败会向外抛错,景区和门店按旧工程规则兜底。
|
||||
/// 刷新完整账号上下文;登录成功等场景仍需要同步拉齐全部数据。
|
||||
func refresh(
|
||||
accountContext: AccountContext,
|
||||
permissionContext: PermissionContext,
|
||||
@ -28,17 +28,66 @@ struct AccountContextLoader {
|
||||
cachedCurrentScenicId: Int? = nil,
|
||||
cachedCurrentStoreId: Int? = nil
|
||||
) async throws {
|
||||
async let userData = profileAPI.userInfo()
|
||||
async let roleData = accountContextAPI.rolePermissions()
|
||||
let (userInfo, rolePermissions) = try await (userData, roleData)
|
||||
try await restorePermissions(
|
||||
permissionContext: permissionContext,
|
||||
accountContext: accountContext,
|
||||
accountContextAPI: accountContextAPI,
|
||||
cachedCurrentRoleCode: cachedCurrentRoleCode,
|
||||
cachedLegacyRoleId: cachedLegacyRoleId,
|
||||
cachedCurrentScenicId: cachedCurrentScenicId,
|
||||
cachedCurrentStoreId: cachedCurrentStoreId
|
||||
)
|
||||
try await refreshSupplementalContext(
|
||||
accountContext: accountContext,
|
||||
permissionContext: permissionContext,
|
||||
profileAPI: profileAPI,
|
||||
accountContextAPI: accountContextAPI,
|
||||
cachedCurrentScenicId: cachedCurrentScenicId,
|
||||
cachedCurrentStoreId: cachedCurrentStoreId
|
||||
)
|
||||
}
|
||||
|
||||
/// 冷启动阻塞阶段:仅恢复角色权限,确保首页菜单和权限控制可用。
|
||||
func restorePermissions(
|
||||
permissionContext: PermissionContext,
|
||||
accountContext: AccountContext,
|
||||
accountContextAPI: AccountContextServing,
|
||||
cachedCurrentRoleCode: String? = nil,
|
||||
cachedLegacyRoleId: Int? = nil,
|
||||
cachedCurrentScenicId: Int? = nil,
|
||||
cachedCurrentStoreId: Int? = nil
|
||||
) async throws {
|
||||
let rolePermissions = try await accountContextAPI.rolePermissions()
|
||||
permissionContext.replaceRolePermissions(
|
||||
rolePermissions,
|
||||
currentRoleCode: cachedCurrentRoleCode,
|
||||
cachedLegacyRoleId: cachedLegacyRoleId
|
||||
)
|
||||
|
||||
let scenicResponse = await loadScenicList(accountContextAPI: accountContextAPI, rolePermissions: rolePermissions)
|
||||
let roleScenicScopes = permissionContext.currentRoleScenicScopes()
|
||||
guard accountContext.scenicScopes.isEmpty, !roleScenicScopes.isEmpty else { return }
|
||||
accountContext.replaceScopes(
|
||||
scenic: roleScenicScopes,
|
||||
stores: accountContext.storeScopes,
|
||||
currentScenicId: cachedCurrentScenicId,
|
||||
currentStoreId: cachedCurrentStoreId
|
||||
)
|
||||
}
|
||||
|
||||
/// 冷启动后台阶段:补齐用户资料、景区和门店上下文。
|
||||
func refreshSupplementalContext(
|
||||
accountContext: AccountContext,
|
||||
permissionContext: PermissionContext,
|
||||
profileAPI: UserProfileServing,
|
||||
accountContextAPI: AccountContextServing,
|
||||
cachedCurrentScenicId: Int? = nil,
|
||||
cachedCurrentStoreId: Int? = nil
|
||||
) async throws {
|
||||
let userInfo = try await profileAPI.userInfo()
|
||||
let scenicResponse = await loadScenicList(
|
||||
accountContextAPI: accountContextAPI,
|
||||
rolePermissions: permissionContext.rolePermissions
|
||||
)
|
||||
let storesResponse = await loadStores(accountContextAPI: accountContextAPI)
|
||||
let profile = makeProfile(from: userInfo, fallback: accountContext.profile)
|
||||
let scenicScopes = scopedScenics(
|
||||
@ -53,8 +102,8 @@ struct AccountContextLoader {
|
||||
accountContext.replaceScopes(
|
||||
scenic: scenicScopes,
|
||||
stores: storeScopes,
|
||||
currentScenicId: cachedCurrentScenicId,
|
||||
currentStoreId: cachedCurrentStoreId
|
||||
currentScenicId: cachedCurrentScenicId ?? accountContext.currentScenic?.id,
|
||||
currentStoreId: cachedCurrentStoreId ?? accountContext.currentStore?.id
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user