mirror of
https://github.com/easychen/pushdeer.git
synced 2024-11-01 16:19:19 +08:00
2136883536
支持微信登录, 支持同时绑定微信和苹果账号; 解决markdown标题文字显示不全的问题; markdown中的链接支持内嵌浏览器打开; 增加是否使用内置浏览器的设置项; 改名输入框, 失去焦点的时候也保存;
109 lines
3.1 KiB
Swift
109 lines
3.1 KiB
Swift
//
|
|
// DeviceItemView.swift
|
|
// PushDeer
|
|
//
|
|
// Created by HEXT on 2021/12/26.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
/// 每个设备项的 View
|
|
struct DeviceItemView: View {
|
|
@State var deviceItem: DeviceItem
|
|
@EnvironmentObject private var store: AppState
|
|
|
|
var body: some View {
|
|
CardView {
|
|
HStack{
|
|
ZStack{
|
|
Image(systemName: getSystemName(deviceName: deviceItem.name))
|
|
.resizable()
|
|
.scaledToFit()
|
|
.frame(width: 40, height: 40, alignment: .center)
|
|
if deviceItem.is_clip == 1 {
|
|
Image(systemName: "appclip")
|
|
.resizable()
|
|
.scaledToFit()
|
|
.frame(width: 12, height: 12, alignment: .center)
|
|
}
|
|
}
|
|
.padding(EdgeInsets(top: 0, leading: 18, bottom: 0, trailing: 8))
|
|
|
|
EditableText(placeholder: NSLocalizedString("输入设备名称", comment: ""), value: deviceItem.name) { value in
|
|
if deviceItem.name == value {
|
|
return
|
|
}
|
|
Task {
|
|
// 调用接口修改
|
|
_ = try await HttpRequest.renameDevice(id: deviceItem.id, name: value)
|
|
HToast.showSuccess(NSLocalizedString("已修改设备名称", comment: ""))
|
|
deviceItem.name = value
|
|
// 在此 Item 在列表中的下标
|
|
let index = store.devices.firstIndex { $0.id == deviceItem.id }
|
|
if let index = index {
|
|
// 更新列表中相应的 Item
|
|
store.devices[index].name = value
|
|
}
|
|
}
|
|
}
|
|
Text(getInfo(deviceItem: deviceItem))
|
|
.font(.system(size: 20))
|
|
Spacer(minLength: 12)
|
|
}
|
|
.frame(height: 80)
|
|
}
|
|
}
|
|
|
|
func getInfo(deviceItem: DeviceItem) -> String {
|
|
var name = ""
|
|
// if deviceItem.is_clip == 1 {
|
|
// name += " [Clip]"
|
|
// }
|
|
if deviceItem.device_id == store.deviceToken {
|
|
name += NSLocalizedString("(当前设备)", comment: "在设备列表中标识当前设备")
|
|
}
|
|
return name
|
|
}
|
|
|
|
func getSystemName(deviceName: String) -> String {
|
|
var deviceName = deviceName.lowercased()
|
|
deviceName = deviceName.replacingOccurrences(of: " ", with: "")
|
|
|
|
// if deviceName.contains("clip") {
|
|
// return "appclip"
|
|
// }
|
|
if deviceName.contains("iphone") {
|
|
return "iphone"
|
|
}
|
|
if deviceName.contains("ipad") {
|
|
return "ipad.landscape"
|
|
}
|
|
if deviceName.contains("macbook") {
|
|
return "laptopcomputer"
|
|
}
|
|
if deviceName.contains("imac") {
|
|
return "desktopcomputer"
|
|
}
|
|
if deviceName.contains("macpro") {
|
|
return "macpro.gen3"
|
|
}
|
|
if deviceName.contains("macmini") {
|
|
return "macmini"
|
|
}
|
|
if deviceName.contains("mac") {
|
|
return "macwindow"
|
|
}
|
|
if #available(iOS 15.0, *) {
|
|
return "ipad.and.iphone"
|
|
}
|
|
return "laptopcomputer.and.iphone"
|
|
}
|
|
}
|
|
|
|
struct DeviceItemView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
DeviceItemView(deviceItem: DeviceItem(id: 0, uid: "", name: "Hext's iPhone 11", type: "", device_id: "", is_clip: 1))
|
|
.environmentObject(AppState.shared)
|
|
}
|
|
}
|