模块化 AppStore 并完善素材管理与个人空间设置。

将会话、权限、位置、收款与排队存储拆分为独立模块,同步更新各 ViewModel 与单元测试,并补充素材管理 UI 与个人空间设置交互。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-13 11:01:08 +08:00
parent ceca780ab3
commit 005349f8e6
128 changed files with 2953 additions and 1123 deletions

View File

@ -22,6 +22,9 @@ protocol ProfileSpaceSettingsAPI {
///
func deleteSchedule(id: Int) async throws
///
func uploadAvatar(data: Data, fileName: String) async throws
}
extension ProfileAPI: ProfileSpaceSettingsAPI {}
@ -85,6 +88,7 @@ final class ProfileSpaceSettingsViewModel {
private(set) var scheduleMap: [String: [PhotographerSchedule]] = [:]
private(set) var selectedDate: Date
private(set) var isEditingProfile = false
private(set) var isCertificationExpanded = false
private(set) var isLoading = false
private(set) var hasChanges = false
@ -109,7 +113,7 @@ final class ProfileSpaceSettingsViewModel {
/// ID
var scenicId: Int {
appStore.currentScenicId
appStore.session.currentScenicId
}
///
@ -156,7 +160,7 @@ final class ProfileSpaceSettingsViewModel {
do {
try await api.updateUserInfo(nickname: newNickname, password: nil, avatar: nil)
nickname = newNickname
appStore.userName = newNickname
appStore.session.userName = newNickname
isEditingProfile = false
onShowMessage?("修改成功")
notifyStateChange()
@ -175,10 +179,35 @@ final class ProfileSpaceSettingsViewModel {
/// URL
func updateAvatarURL(_ url: String) {
avatarURL = url
appStore.avatar = url
appStore.session.avatar = url
notifyStateChange()
}
///
func toggleCertificationExpanded() {
isCertificationExpanded.toggle()
notifyStateChange()
}
///
func uploadAvatar(
data: Data,
fileName: String,
api: any ProfileSpaceSettingsAPI
) async {
setLoading(true)
defer { setLoading(false) }
do {
try await api.uploadAvatar(data: data, fileName: fileName)
onShowMessage?("上传成功")
await load(api: api)
} catch is CancellationError {
return
} catch {
onShowMessage?(error.localizedDescription)
}
}
///
func updateEditingNickname(_ value: String) {
editingNickname = value
@ -225,41 +254,41 @@ final class ProfileSpaceSettingsViewModel {
///
func updateBusinessStartTime(_ value: String) {
businessStartTime = value
if let end = businessEndTime, !Self.isStart(value, before: end) {
onShowMessage?("开始时间不能大于结束时间")
businessStartTime = nil
return
}
businessStartTime = value
updateHasChanges()
}
///
func updateBusinessEndTime(_ value: String) {
businessEndTime = value
if let start = businessStartTime, !Self.isStart(start, before: value) {
onShowMessage?("结束时间不能小于开始时间")
businessEndTime = nil
return
}
businessEndTime = value
updateHasChanges()
}
///
func updateHolidayStartTime(_ value: String) {
holidayStartTime = value
if let end = holidayEndTime, !Self.isStart(value, before: end) {
onShowMessage?("开始时间不能大于结束时间")
holidayStartTime = nil
return
}
holidayStartTime = value
updateHasChanges()
}
///
func updateHolidayEndTime(_ value: String) {
holidayEndTime = value
if let start = holidayStartTime, !Self.isStart(start, before: value) {
onShowMessage?("结束时间不能小于开始时间")
holidayEndTime = nil
return
}
holidayEndTime = value
updateHasChanges()
}
@ -417,7 +446,7 @@ final class ProfileSpaceSettingsViewModel {
editingNickname = response.nickname
if !response.avatar.isEmpty {
avatarURL = response.avatar
appStore.avatar = response.avatar
appStore.session.avatar = response.avatar
}
scenicCertification = response.scenicCertification
introduction = response.description
@ -430,8 +459,8 @@ final class ProfileSpaceSettingsViewModel {
holidayEndTime = Self.shortTimeString(response.holidayEndTime)
acceptOrderStatus = response.acceptOrderStatus
scheduleMap = response.schedule
appStore.userName = response.nickname
appStore.realName = response.realName
appStore.session.userName = response.nickname
appStore.session.realName = response.realName
originalSnapshot = currentSnapshot()
hasChanges = false
notifyStateChange()