pushdeer/ios/PushDeer-iOS/PushDeer/View/KeyItemView.swift
hext 2136883536 支持微信登录, 修复一些bug:
支持微信登录, 支持同时绑定微信和苹果账号;
解决markdown标题文字显示不全的问题;
markdown中的链接支持内嵌浏览器打开;
增加是否使用内置浏览器的设置项;
改名输入框, 失去焦点的时候也保存;
2022-02-27 23:02:58 +08:00

99 lines
3.0 KiB
Swift

//
// KeyItemView.swift
// PushDeer
//
// Created by HEXT on 2021/12/27.
//
import SwiftUI
/// Key View
struct KeyItemView: View {
@State var keyItem: KeyItem
@EnvironmentObject private var store: AppState
var body: some View {
VStack(spacing: 20) {
HStack(alignment: .bottom) {
Image("avatar2")
.resizable()
.scaledToFit()
.frame(width: 38, height: 38)
EditableText(placeholder: NSLocalizedString("输入key名称", comment: ""), value: keyItem.name) { value in
if keyItem.name == value {
return
}
Task {
//
_ = try await HttpRequest.renameKey(id: keyItem.id, name: value)
HToast.showSuccess(NSLocalizedString("已修改key名称", comment: ""))
keyItem.name = value
// keyItem
let index = store.keys.firstIndex { $0.id == keyItem.id }
if let index = index {
// keyItem
store.keys[index].name = value
}
}
}
Spacer()
Image(systemName: "calendar")
.font(.system(size: 14))
.foregroundColor(Color.gray)
Text(keyItem.createdDateStr)
.font(.system(size: 14))
.foregroundColor(Color.gray)
}
TextField("Key", text: .constant(keyItem.key) )
.font(.system(size: 14))
.disabled(true)
.padding(12)
.overlay(RoundedRectangle(cornerRadius: 4).stroke(Color("borderColor")))
.foregroundColor(Color.gray)
HLine().stroke(Color.gray, style: StrokeStyle(lineWidth: 1, dash: [5]))
HStack {
Button(NSLocalizedString("重置", comment: "重置key的按钮标题")) {
print("点击重置")
Task {
do {
_ = try await HttpRequest.regenKey(id: keyItem.id)
HttpRequest.loadKeys()
HToast.showSuccess(NSLocalizedString("已重置", comment: "已重置key的提示"))
} catch {
}
}
}
.font(.system(size: 20))
.frame(width: 90, height: 42)
.overlay(RoundedRectangle(cornerRadius: 4).stroke())
.foregroundColor(Color.accentColor)
Spacer()
Button(NSLocalizedString("复制", comment: "复制按钮的标题")) {
print("点击复制")
UIPasteboard.general.string = keyItem.key
HToast.showSuccess(NSLocalizedString("已复制", comment: ""))
}
.font(.system(size: 20))
.frame(width: 90, height: 42)
.foregroundColor(Color.white)
.background(Color("BtnBgColor"))
.cornerRadius(8)
}
}
.padding()
}
}
struct KeyItemView_Previews: PreviewProvider {
static var previews: some View {
KeyItemView(keyItem: KeyItem(id: 1, name: "name", uid: "1", key: "Key", created_at: "1111"))
.environmentObject(AppState.shared)
}
}