// // RolePermissionModels.swift // suixinkan // import Foundation /// 角色权限接口根节点,对齐 Android `RolePermissionResponse`。 struct RolePermissionResponse: Codable, Equatable, Sendable { let role: RoleInfo let scenic: [ScenicInfo] init(role: RoleInfo, scenic: [ScenicInfo] = []) { self.role = role self.scenic = scenic } } /// 角色信息与顶层权限列表。 struct RoleInfo: Codable, Equatable, Sendable { let id: Int let name: String let roleCode: String let notes: String? let permission: [PermissionItem] enum CodingKeys: String, CodingKey { case id case name case roleCode = "role_code" case notes case permission } init( id: Int = 0, name: String = "", roleCode: String = "", notes: String? = nil, permission: [PermissionItem] = [] ) { self.id = id self.name = name self.roleCode = roleCode self.notes = notes self.permission = permission } } /// 权限树节点。 struct PermissionItem: Codable, Equatable, Sendable { let id: Int let pid: Int let name: String let uri: String let iconSrc: String? let children: [PermissionItem]? enum CodingKeys: String, CodingKey { case id case pid case name case uri case iconSrc = "icon_src" case children } init( id: Int = 0, pid: Int = 0, name: String = "", uri: String = "", iconSrc: String? = nil, children: [PermissionItem]? = nil ) { self.id = id self.pid = pid self.name = name self.uri = uri self.iconSrc = iconSrc self.children = children } } /// 角色绑定的景区信息。 struct ScenicInfo: Codable, Equatable, Sendable, Hashable { let id: Int let name: String let status: Int let location: ScenicLocationInfo? let coverImg: String? enum CodingKeys: String, CodingKey { case id case name case status case location case coverImg = "cover_img" } init( id: Int = 0, name: String = "", status: Int = 0, location: ScenicLocationInfo? = nil, coverImg: String? = nil ) { self.id = id self.name = name self.status = status self.location = location self.coverImg = coverImg } } /// 景区位置信息。 struct ScenicLocationInfo: Codable, Equatable, Sendable, Hashable { let lng: Double let lat: Double let address: String } /// 扁平化后的权限项,供首页菜单与本地缓存使用。 struct HomePermissionItem: Codable, Equatable, Sendable, Hashable { let id: String let name: String let uri: String let pid: Int init(id: String, name: String, uri: String, pid: Int = 0) { self.id = id self.name = name self.uri = uri self.pid = pid } init(from item: PermissionItem) { self.id = String(item.id) self.name = item.name self.uri = item.uri self.pid = item.pid } }