fix: use v9 store status for deregistration login

This commit is contained in:
2026-08-31 16:36:20 +08:00
parent 4444d328df
commit b8343ad9eb
8 changed files with 194 additions and 11 deletions
@@ -57,6 +57,7 @@ enum LoginValidationError: Equatable {
enum LoginResolution {
case completed(V9AuthResponse, AccountSwitchAccount)
case needsAccountSelection(AccountSelectionPayload)
case needsDeregistrationConfirmation(DeregistrationLoginConfirmation)
}
/// 登录流程错误实体,表示 token、账号列表或账号 ID 异常。
@@ -124,8 +125,40 @@ struct AccountSwitchAccount: Identifiable, Hashable {
let storeId: Int?
let storeName: String
let scenicId: Int?
let status: Int
let isCurrent: Bool
/// 创建统一账号展示模型;门店状态默认为正常,兼容尚未返回 `status` 的旧响应。
init(
accountType: String,
businessUserId: Int,
title: String,
subtitle: String,
phone: String,
realName: String,
avatar: String,
scenicName: String,
storeId: Int?,
storeName: String,
scenicId: Int?,
status: Int = 1,
isCurrent: Bool
) {
self.accountType = accountType
self.businessUserId = businessUserId
self.title = title
self.subtitle = subtitle
self.phone = phone
self.realName = realName
self.avatar = avatar
self.scenicName = scenicName
self.storeId = storeId
self.storeName = storeName
self.scenicId = scenicId
self.status = status
self.isCurrent = isCurrent
}
var id: String {
"\(accountType)_\(businessUserId)"
}
@@ -134,6 +167,11 @@ struct AccountSwitchAccount: Identifiable, Hashable {
accountType == V9StoreUser.accountTypeValue
}
/// `status == 2` 表示门店身份已提交注销申请,登录前需要用户明确确认撤销。
var requiresDeregistrationConfirmation: Bool {
isStoreUser && status == 2
}
var accountTypeLabel: String {
isStoreUser ? "门店账号" : "景区账号"
}
@@ -146,6 +184,12 @@ struct AccountSwitchAccount: Identifiable, Hashable {
}
}
/// 冷静期门店身份的待确认登录信息;确认后继续调用 `set-user`,由后端自动撤销注销申请。
struct DeregistrationLoginConfirmation: Equatable {
let tempToken: String
let account: AccountSwitchAccount
}
/// 登录账号选择载荷,保存临时 token 和待用户选择的账号列表。
struct AccountSelectionPayload: Equatable, Identifiable {
let id = UUID()
@@ -285,6 +329,7 @@ struct V9StoreUser: Decodable, Equatable {
let roleName: String
let appRoleCode: String
let appRoleName: String
let status: Int
let isCurrent: Bool
var businessUserId: Int {
@@ -308,6 +353,7 @@ struct V9StoreUser: Decodable, Equatable {
storeId: storeId > 0 ? storeId : nil,
storeName: storeName,
scenicId: scenicId > 0 ? scenicId : nil,
status: status,
isCurrent: isCurrent
)
}
@@ -327,6 +373,7 @@ struct V9StoreUser: Decodable, Equatable {
case roleName = "role_name"
case appRoleCode = "app_role_code"
case appRoleName = "app_role_name"
case status
case isCurrent = "is_current"
}
@@ -346,6 +393,7 @@ struct V9StoreUser: Decodable, Equatable {
roleName = try container.decodeLossyString(forKey: .roleName)
appRoleCode = try container.decodeLossyString(forKey: .appRoleCode)
appRoleName = try container.decodeLossyString(forKey: .appRoleName)
status = try container.decodeLossyInt(forKey: .status) ?? 1
isCurrent = try container.decodeLossyBool(forKey: .isCurrent) ?? false
}
}