fix: 修正账号姓名展示与资料缓存
This commit is contained in:
@ -70,10 +70,10 @@ enum AuthSessionHelper {
|
||||
AppStore.shared.session.userId = String(user.businessUserId)
|
||||
AppStore.shared.session.accountType = .scenicUser
|
||||
AppStore.shared.session.accountDisplayName = firstNonEmpty(
|
||||
user.scenicName, user.nickname, user.realName, user.username
|
||||
user.scenicName, user.nickname, user.realName
|
||||
)
|
||||
AppStore.shared.session.userName = firstNonEmpty(user.nickname, user.username, user.realName)
|
||||
AppStore.shared.session.realName = firstNonEmpty(user.realName, user.nickname, user.username)
|
||||
AppStore.shared.session.userName = firstNonEmpty(user.nickname, user.realName)
|
||||
AppStore.shared.session.realName = user.realName
|
||||
AppStore.shared.session.phone = user.phone
|
||||
AppStore.shared.session.currentScenicId = user.scenicId
|
||||
AppStore.shared.session.currentScenicName = user.scenicName
|
||||
@ -90,10 +90,10 @@ enum AuthSessionHelper {
|
||||
AppStore.shared.session.userId = String(user.businessUserId)
|
||||
AppStore.shared.session.accountType = .storeUser
|
||||
AppStore.shared.session.accountDisplayName = firstNonEmpty(
|
||||
user.storeName, user.scenicName, user.realName, user.userName, user.username
|
||||
user.storeName, user.scenicName, user.realName
|
||||
)
|
||||
AppStore.shared.session.userName = firstNonEmpty(user.userName, user.username, user.realName)
|
||||
AppStore.shared.session.realName = firstNonEmpty(user.realName, user.userName, user.username)
|
||||
AppStore.shared.session.userName = user.realName
|
||||
AppStore.shared.session.realName = user.realName
|
||||
AppStore.shared.session.phone = user.phone
|
||||
AppStore.shared.session.avatar = user.avatar
|
||||
AppStore.shared.session.currentScenicId = user.scenicId
|
||||
|
||||
@ -196,7 +196,6 @@ struct V9ScenicUser: Decodable, Equatable {
|
||||
let userId: Int
|
||||
let scenicUserId: Int
|
||||
let ssUserId: Int
|
||||
let username: String
|
||||
let realName: String
|
||||
let nickname: String
|
||||
let phone: String
|
||||
@ -212,7 +211,7 @@ struct V9ScenicUser: Decodable, Equatable {
|
||||
}
|
||||
|
||||
var displayName: String {
|
||||
scenicName.nonEmpty ?? nickname.nonEmpty ?? realName.nonEmpty ?? username
|
||||
scenicName.nonEmpty ?? nickname.nonEmpty ?? realName
|
||||
}
|
||||
|
||||
func toAccountSwitchAccount() -> AccountSwitchAccount {
|
||||
@ -238,8 +237,6 @@ struct V9ScenicUser: Decodable, Equatable {
|
||||
case userId = "user_id"
|
||||
case scenicUserId = "scenic_user_id"
|
||||
case ssUserId = "ss_user_id"
|
||||
case username = "user_name"
|
||||
case legacyUsername = "username"
|
||||
case realName = "real_name"
|
||||
case nickname
|
||||
case phone
|
||||
@ -258,9 +255,6 @@ struct V9ScenicUser: Decodable, Equatable {
|
||||
userId = try container.decodeLossyInt(forKey: .userId) ?? 0
|
||||
scenicUserId = try container.decodeLossyInt(forKey: .scenicUserId) ?? 0
|
||||
ssUserId = try container.decodeLossyInt(forKey: .ssUserId) ?? 0
|
||||
let preferredUsername = try container.decodeLossyString(forKey: .username)
|
||||
let legacyUsername = try container.decodeLossyString(forKey: .legacyUsername)
|
||||
username = preferredUsername.nonEmpty ?? legacyUsername
|
||||
realName = try container.decodeLossyString(forKey: .realName)
|
||||
nickname = try container.decodeLossyString(forKey: .nickname)
|
||||
phone = try container.decodeLossyString(forKey: .phone)
|
||||
@ -281,8 +275,6 @@ struct V9StoreUser: Decodable, Equatable {
|
||||
let id: Int
|
||||
let userId: Int
|
||||
let storeUserId: Int
|
||||
let username: String
|
||||
let userName: String
|
||||
let realName: String
|
||||
let phone: String
|
||||
let avatar: String
|
||||
@ -300,14 +292,14 @@ struct V9StoreUser: Decodable, Equatable {
|
||||
}
|
||||
|
||||
var displayName: String {
|
||||
storeName.nonEmpty ?? scenicName.nonEmpty ?? realName.nonEmpty ?? userName.nonEmpty ?? username
|
||||
storeName.nonEmpty ?? scenicName.nonEmpty ?? realName
|
||||
}
|
||||
|
||||
func toAccountSwitchAccount() -> AccountSwitchAccount {
|
||||
AccountSwitchAccount(
|
||||
accountType: accountType.nonEmpty ?? Self.accountTypeValue,
|
||||
businessUserId: businessUserId,
|
||||
title: storeName.nonEmpty ?? scenicName.nonEmpty ?? realName.nonEmpty ?? userName.nonEmpty ?? "门店账号",
|
||||
title: storeName.nonEmpty ?? scenicName.nonEmpty ?? realName.nonEmpty ?? "门店账号",
|
||||
subtitle: joinAccountSubtitle(scenicName, roleName),
|
||||
phone: phone,
|
||||
realName: realName,
|
||||
@ -325,8 +317,6 @@ struct V9StoreUser: Decodable, Equatable {
|
||||
case id
|
||||
case userId = "user_id"
|
||||
case storeUserId = "store_user_id"
|
||||
case username
|
||||
case userName = "user_name"
|
||||
case realName = "real_name"
|
||||
case phone
|
||||
case avatar
|
||||
@ -346,8 +336,6 @@ struct V9StoreUser: Decodable, Equatable {
|
||||
id = try container.decodeLossyInt(forKey: .id) ?? 0
|
||||
userId = try container.decodeLossyInt(forKey: .userId) ?? 0
|
||||
storeUserId = try container.decodeLossyInt(forKey: .storeUserId) ?? 0
|
||||
username = try container.decodeLossyString(forKey: .username)
|
||||
userName = try container.decodeLossyString(forKey: .userName)
|
||||
realName = try container.decodeLossyString(forKey: .realName)
|
||||
phone = try container.decodeLossyString(forKey: .phone)
|
||||
avatar = try container.decodeLossyString(forKey: .avatar)
|
||||
|
||||
@ -69,9 +69,9 @@ enum PayPageBrandingPolicy {
|
||||
|
||||
/// 收款页当前账号信息的展示文本格式化规则。
|
||||
enum PaymentAccountDisplayFormatter {
|
||||
/// 解析当前登录摄影师名称,昵称为空时使用实名,仍为空时显示占位符。
|
||||
static func photographerName(userName: String, realName: String) -> String {
|
||||
userName.trimmedNonEmpty ?? realName.trimmedNonEmpty ?? "-"
|
||||
/// 解析当前登录摄影师的真实姓名,空值显示占位符。
|
||||
static func photographerName(realName: String) -> String {
|
||||
realName.trimmedNonEmpty ?? "-"
|
||||
}
|
||||
|
||||
/// 去除空值与重复项后,合并当前账号的全部店铺名称。
|
||||
|
||||
@ -66,7 +66,6 @@ final class PaymentCollectionDetailsViewModel {
|
||||
|
||||
var displayPhotographerName: String {
|
||||
PaymentAccountDisplayFormatter.photographerName(
|
||||
userName: appStore.session.userName,
|
||||
realName: appStore.session.realName
|
||||
)
|
||||
}
|
||||
|
||||
@ -17,11 +17,11 @@ final class ProfileViewModel {
|
||||
var onStateChange: (() -> Void)?
|
||||
|
||||
var displayNickname: String {
|
||||
nonEmpty(userInfo?.nickname) ?? "未设置昵称"
|
||||
nonEmpty(userInfo?.nickname) ?? AppStore.shared.session.userName.nonEmpty ?? "未设置昵称"
|
||||
}
|
||||
|
||||
var displayRealName: String {
|
||||
nonEmpty(userInfo?.realName) ?? "--"
|
||||
nonEmpty(userInfo?.realName) ?? AppStore.shared.session.realName.nonEmpty ?? "--"
|
||||
}
|
||||
|
||||
var displayPhone: String {
|
||||
@ -37,6 +37,17 @@ final class ProfileViewModel {
|
||||
return uid.isEmpty ? "--" : uid
|
||||
}
|
||||
|
||||
/// 本地是否已有可供冷启动首屏展示的基本资料。
|
||||
var hasCachedBasicInfo: Bool {
|
||||
[
|
||||
AppStore.shared.session.userName,
|
||||
AppStore.shared.session.realName,
|
||||
AppStore.shared.session.phone,
|
||||
AppStore.shared.session.avatar,
|
||||
AppStore.shared.session.userId,
|
||||
].contains { nonEmpty($0) != nil }
|
||||
}
|
||||
|
||||
var accountDisplayName: String {
|
||||
let name = AppStore.shared.session.accountDisplayName.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
return name.isEmpty ? "--" : name
|
||||
@ -112,6 +123,7 @@ final class ProfileViewModel {
|
||||
if !info.roleName.isEmpty {
|
||||
AppStore.shared.session.roleName = info.roleName
|
||||
}
|
||||
notifyStateChange()
|
||||
|
||||
if showPhotographerFields {
|
||||
async let realName = api.realNameInfo()
|
||||
|
||||
@ -38,6 +38,11 @@ final class ProfileViewController: BaseViewController {
|
||||
title = "我的"
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
applyViewModel()
|
||||
}
|
||||
|
||||
override func setupUI() {
|
||||
view.backgroundColor = UIColor(hex: 0xF7FAFF)
|
||||
|
||||
@ -104,12 +109,10 @@ final class ProfileViewController: BaseViewController {
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
let showLoading = !hasLoadedProfileOnce
|
||||
let showLoading = !hasLoadedProfileOnce && !viewModel.hasCachedBasicInfo
|
||||
Task {
|
||||
await reloadProfile(showGlobalLoading: showLoading)
|
||||
if showLoading {
|
||||
hasLoadedProfileOnce = true
|
||||
}
|
||||
hasLoadedProfileOnce = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user