fix(training): 兼容后台 training 权限标识
This commit is contained in:
@@ -18,7 +18,7 @@ final class HomeCommonMenuStore {
|
||||
func savedCommonURIs(accountScope: String, roleCode: String) -> [String] {
|
||||
guard let key = storageKey(accountScope: accountScope, roleCode: roleCode) else { return [] }
|
||||
let saved = defaults.stringArray(forKey: key) ?? []
|
||||
let sanitized = saved.filter(HomeMenuCatalog.isCustomizable(uri:))
|
||||
let sanitized = Self.normalizedCommonURIs(saved)
|
||||
if sanitized != saved {
|
||||
defaults.set(sanitized, forKey: key)
|
||||
}
|
||||
@@ -28,12 +28,12 @@ final class HomeCommonMenuStore {
|
||||
/// 保存常用 URI 列表。
|
||||
func saveCommonURIs(_ uris: [String], accountScope: String, roleCode: String) {
|
||||
guard let key = storageKey(accountScope: accountScope, roleCode: roleCode) else { return }
|
||||
defaults.set(uris.filter(HomeMenuCatalog.isCustomizable(uri:)), forKey: key)
|
||||
defaults.set(Self.normalizedCommonURIs(uris), forKey: key)
|
||||
}
|
||||
|
||||
/// 根据权限生成默认常用 URI(最多 4 个)。
|
||||
static func defaultCommonURIs(from permissions: [HomePermissionItem]) -> [String] {
|
||||
let uris = permissions.map(\.uri).filter(HomeMenuCatalog.isCustomizable(uri:))
|
||||
let uris = normalizedCommonURIs(permissions.map(\.uri))
|
||||
return uris.count > 4 ? Array(uris.prefix(4)) : uris
|
||||
}
|
||||
|
||||
@@ -55,13 +55,17 @@ final class HomeCommonMenuStore {
|
||||
from allMenus: [HomeMenuItem],
|
||||
commonURIs: [String]
|
||||
) -> (common: [HomeMenuItem], more: [HomeMenuItem]) {
|
||||
let commonSet = Set(commonURIs)
|
||||
let commonSet = Set(normalizedCommonURIs(commonURIs))
|
||||
let customizableMenus = allMenus.filter { HomeMenuCatalog.isCustomizable(uri: $0.uri) }
|
||||
let common = customizableMenus.filter { commonSet.contains($0.uri) }
|
||||
let more = customizableMenus.filter { !commonSet.contains($0.uri) }
|
||||
return (common, more)
|
||||
}
|
||||
|
||||
private static func normalizedCommonURIs(_ uris: [String]) -> [String] {
|
||||
HomeMenuCatalog.canonicalURIs(uris).filter(HomeMenuCatalog.isCustomizable(uri:))
|
||||
}
|
||||
|
||||
private func storageKey(accountScope: String, roleCode: String) -> String? {
|
||||
let normalizedScope = accountScope.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let normalizedRoleCode = roleCode.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
Reference in New Issue
Block a user