feat: 更新依赖和项目配置,优化代码结构
- 在Package.swift中注释掉旧的swift-composable-architecture依赖,并添加swift-case-paths依赖。 - 在Podfile中将iOS平台版本更新至16.0,并移除QCloudCOSXML/Transfer依赖,改为使用QCloudCOSXML。 - 更新Podfile.lock以反映依赖变更,确保项目依赖的准确性。 - 新增架构分析需求文档,明确项目架构评估和改进建议。 - 在多个文件中实现async/await语法,提升异步操作的可读性和性能。 - 更新日志输出方法,确保在调试模式下提供一致的调试信息。 - 优化多个视图组件,提升用户体验和代码可维护性。
This commit is contained in:
@@ -10,6 +10,7 @@ import Foundation
|
||||
/// 2. 迁移到 Keychain
|
||||
/// 3. 验证迁移结果
|
||||
/// 4. 清理旧数据
|
||||
@MainActor
|
||||
final class DataMigrationManager {
|
||||
|
||||
// MARK: - 单例
|
||||
@@ -54,23 +55,23 @@ final class DataMigrationManager {
|
||||
/// 执行数据迁移
|
||||
/// - Returns: 迁移结果
|
||||
func performMigration() -> MigrationResult {
|
||||
debugInfo("🔄 开始检查数据迁移...")
|
||||
debugInfoSync("🔄 开始检查数据迁移...")
|
||||
|
||||
// 检查是否已经迁移过
|
||||
if isMigrationCompleted() {
|
||||
debugInfo("✅ 数据已经迁移过,跳过迁移")
|
||||
debugInfoSync("✅ 数据已经迁移过,跳过迁移")
|
||||
return .alreadyMigrated
|
||||
}
|
||||
|
||||
// 检查是否有需要迁移的数据
|
||||
let legacyData = collectLegacyData()
|
||||
if legacyData.isEmpty {
|
||||
debugInfo("ℹ️ 没有发现需要迁移的数据")
|
||||
debugInfoSync("ℹ️ 没有发现需要迁移的数据")
|
||||
markMigrationCompleted()
|
||||
return .noDataToMigrate
|
||||
}
|
||||
|
||||
debugInfo("📦 发现需要迁移的数据: \(legacyData.keys.joined(separator: ", "))")
|
||||
debugInfoSync("📦 发现需要迁移的数据: \(legacyData.keys.joined(separator: ", "))")
|
||||
|
||||
do {
|
||||
// 执行迁移
|
||||
@@ -85,11 +86,11 @@ final class DataMigrationManager {
|
||||
// 标记迁移完成
|
||||
markMigrationCompleted()
|
||||
|
||||
debugInfo("✅ 数据迁移完成")
|
||||
debugInfoSync("✅ 数据迁移完成")
|
||||
return .completed
|
||||
|
||||
} catch {
|
||||
debugError("❌ 数据迁移失败: \(error)")
|
||||
debugErrorSync("❌ 数据迁移失败: \(error)")
|
||||
return .failed(error)
|
||||
}
|
||||
}
|
||||
@@ -157,9 +158,9 @@ final class DataMigrationManager {
|
||||
do {
|
||||
let accountModel = try JSONDecoder().decode(AccountModel.self, from: accountModelData)
|
||||
try keychain.store(accountModel, forKey: "account_model")
|
||||
debugInfo("✅ AccountModel 迁移成功")
|
||||
debugInfoSync("✅ AccountModel 迁移成功")
|
||||
} catch {
|
||||
debugError("❌ AccountModel 迁移失败: \(error)")
|
||||
debugErrorSync("❌ AccountModel 迁移失败: \(error)")
|
||||
// 如果 AccountModel 迁移失败,尝试从独立字段重建
|
||||
try migrateAccountModelFromIndependentFields(legacyData)
|
||||
}
|
||||
@@ -173,9 +174,9 @@ final class DataMigrationManager {
|
||||
do {
|
||||
let userInfo = try JSONDecoder().decode(UserInfo.self, from: userInfoData)
|
||||
try keychain.store(userInfo, forKey: "user_info")
|
||||
debugInfo("✅ UserInfo 迁移成功")
|
||||
debugInfoSync("✅ UserInfo 迁移成功")
|
||||
} catch {
|
||||
debugError("❌ UserInfo 迁移失败: \(error)")
|
||||
debugErrorSync("❌ UserInfo 迁移失败: \(error)")
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -183,7 +184,7 @@ final class DataMigrationManager {
|
||||
// 迁移语言设置
|
||||
if let appLanguage = legacyData[LegacyStorageKeys.appLanguage] as? String {
|
||||
try keychain.storeString(appLanguage, forKey: "AppLanguage")
|
||||
debugInfo("✅ 语言设置迁移成功")
|
||||
debugInfoSync("✅ 语言设置迁移成功")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,7 +192,7 @@ final class DataMigrationManager {
|
||||
private func migrateAccountModelFromIndependentFields(_ legacyData: [String: Any]) throws {
|
||||
guard let userId = legacyData[LegacyStorageKeys.userId] as? String,
|
||||
let accessToken = legacyData[LegacyStorageKeys.accessToken] as? String else {
|
||||
debugInfo("ℹ️ 没有足够的独立字段来重建 AccountModel")
|
||||
debugInfoSync("ℹ️ 没有足够的独立字段来重建 AccountModel")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -208,7 +209,7 @@ final class DataMigrationManager {
|
||||
)
|
||||
|
||||
try KeychainManager.shared.store(accountModel, forKey: "account_model")
|
||||
debugInfo("✅ 从独立字段重建 AccountModel 成功")
|
||||
debugInfoSync("✅ 从独立字段重建 AccountModel 成功")
|
||||
}
|
||||
|
||||
/// 验证迁移结果
|
||||
@@ -240,7 +241,7 @@ final class DataMigrationManager {
|
||||
}
|
||||
}
|
||||
|
||||
debugInfo("✅ 迁移数据验证成功")
|
||||
debugInfoSync("✅ 迁移数据验证成功")
|
||||
}
|
||||
|
||||
/// 清理旧数据
|
||||
@@ -249,11 +250,11 @@ final class DataMigrationManager {
|
||||
|
||||
for key in keys {
|
||||
userDefaults.removeObject(forKey: key)
|
||||
debugInfo("🗑️ 清理旧数据: \(key)")
|
||||
debugInfoSync("🗑️ 清理旧数据: \(key)")
|
||||
}
|
||||
|
||||
userDefaults.synchronize()
|
||||
debugInfo("✅ 旧数据清理完成")
|
||||
debugInfoSync("✅ 旧数据清理完成")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,13 +288,13 @@ extension DataMigrationManager {
|
||||
|
||||
switch migrationResult {
|
||||
case .completed:
|
||||
debugInfo("🎉 应用启动时数据迁移完成")
|
||||
debugInfoSync("🎉 应用启动时数据迁移完成")
|
||||
case .alreadyMigrated:
|
||||
break // 静默处理
|
||||
case .noDataToMigrate:
|
||||
break // 静默处理
|
||||
case .failed(let error):
|
||||
debugError("⚠️ 应用启动时数据迁移失败: \(error)")
|
||||
debugErrorSync("⚠️ 应用启动时数据迁移失败: \(error)")
|
||||
// 这里可以添加错误上报或降级策略
|
||||
}
|
||||
}
|
||||
@@ -307,9 +308,9 @@ extension DataMigrationManager {
|
||||
/// 调试:打印旧数据信息
|
||||
func debugPrintLegacyData() {
|
||||
let legacyData = collectLegacyData()
|
||||
debugInfo("🔍 旧版本数据:")
|
||||
debugInfoSync("🔍 旧版本数据:")
|
||||
for (key, value) in legacyData {
|
||||
debugInfo(" - \(key): \(type(of: value))")
|
||||
debugInfoSync(" - \(key): \(type(of: value))")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +323,7 @@ extension DataMigrationManager {
|
||||
userDefaults.set("zh-Hans", forKey: LegacyStorageKeys.appLanguage)
|
||||
userDefaults.synchronize()
|
||||
|
||||
debugInfo("🧪 已创建测试用的旧版本数据")
|
||||
debugInfoSync("🧪 已创建测试用的旧版本数据")
|
||||
}
|
||||
|
||||
/// 调试:清除所有迁移相关数据
|
||||
@@ -331,7 +332,7 @@ extension DataMigrationManager {
|
||||
do {
|
||||
try KeychainManager.shared.clearAll()
|
||||
} catch {
|
||||
debugError("❌ 清除 Keychain 数据失败: \(error)")
|
||||
debugErrorSync("❌ 清除 Keychain 数据失败: \(error)")
|
||||
}
|
||||
|
||||
// 清除 UserDefaults 数据
|
||||
@@ -350,7 +351,7 @@ extension DataMigrationManager {
|
||||
}
|
||||
userDefaults.synchronize()
|
||||
|
||||
debugInfo("🧪 已清除所有迁移相关数据")
|
||||
debugInfoSync("🧪 已清除所有迁移相关数据")
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user