fix(training): 按后台权限控制培训中心入口
This commit is contained in:
@@ -46,9 +46,10 @@ final class AppPermissionStore {
|
||||
load([RolePermissionResponse].self, for: .rolePermissionList) ?? []
|
||||
}
|
||||
|
||||
/// 保存当前角色扁平权限。
|
||||
/// 保存当前角色扁平权限,写入后通知入口页面读取最新快照。
|
||||
func savePermissionItems(_ items: [HomePermissionItem]) {
|
||||
save(items, for: .permissionItems)
|
||||
guard save(items, for: .permissionItems) else { return }
|
||||
NotificationCenter.default.post(name: NotificationName.permissionItemsDidChange, object: self)
|
||||
}
|
||||
|
||||
/// 读取当前角色扁平权限。
|
||||
@@ -82,10 +83,12 @@ final class AppPermissionStore {
|
||||
Key.allCases.forEach { defaults.removeObject(forKey: "\(accountScope)_\($0.rawValue)") }
|
||||
}
|
||||
|
||||
private func save<Value: Encodable>(_ value: Value, for key: Key) {
|
||||
@discardableResult
|
||||
private func save<Value: Encodable>(_ value: Value, for key: Key) -> Bool {
|
||||
guard let scopedKey = scopedKey(key),
|
||||
let data = try? JSONEncoder().encode(value) else { return }
|
||||
let data = try? JSONEncoder().encode(value) else { return false }
|
||||
defaults.set(data, forKey: scopedKey)
|
||||
return true
|
||||
}
|
||||
|
||||
private func load<Value: Decodable>(_ type: Value.Type, for key: Key) -> Value? {
|
||||
|
||||
Reference in New Issue
Block a user