模块化 AppStore 并完善素材管理与个人空间设置。
将会话、权限、位置、收款与排队存储拆分为独立模块,同步更新各 ViewModel 与单元测试,并补充素材管理 UI 与个人空间设置交互。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user