2021-12-27 22:33:27 +08:00
|
|
|
//
|
|
|
|
// SettingsView.swift
|
|
|
|
// PushDeer
|
|
|
|
//
|
|
|
|
// Created by HEXT on 2021/12/25.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2022-01-10 00:26:29 +08:00
|
|
|
//import StoreKit
|
2021-12-27 22:33:27 +08:00
|
|
|
|
|
|
|
/// 设置界面
|
|
|
|
struct SettingsView: View {
|
2022-01-10 00:26:29 +08:00
|
|
|
@EnvironmentObject private var store: AppState
|
|
|
|
|
2021-12-27 22:33:27 +08:00
|
|
|
var body: some View {
|
|
|
|
BaseNavigationView(title: "设置") {
|
|
|
|
VStack {
|
2022-01-30 01:02:44 +08:00
|
|
|
SettingsItemView(title: NSLocalizedString("登录为", comment: "") + " " + userName(), button: NSLocalizedString("退出", comment: "退出登录按钮上的文字")) {
|
2022-01-10 00:26:29 +08:00
|
|
|
store.token = ""
|
2021-12-27 22:33:27 +08:00
|
|
|
}
|
|
|
|
.padding(EdgeInsets(top: 18, leading: 20, bottom: 0, trailing: 20))
|
|
|
|
|
2022-01-15 22:13:23 +08:00
|
|
|
SettingsItemView(title: NSLocalizedString("自定义服务器", comment: ""), button: NSLocalizedString("扫码", comment: "")) {
|
2021-12-27 22:33:27 +08:00
|
|
|
}
|
2022-01-10 00:26:29 +08:00
|
|
|
.disabled(true)
|
2021-12-27 22:33:27 +08:00
|
|
|
.padding(EdgeInsets(top: 18, leading: 20, bottom: 0, trailing: 20))
|
|
|
|
|
2022-01-15 22:13:23 +08:00
|
|
|
SettingsItemView(title: NSLocalizedString("喜欢PushDeer?", comment: ""), button: NSLocalizedString("评分", comment: "")) {
|
2022-01-10 00:26:29 +08:00
|
|
|
let urlStr = "itms-apps://itunes.apple.com/app/id\(1596771139)?action=write-review"
|
|
|
|
UIApplication.shared.open(URL(string: urlStr)!, options: [:], completionHandler: nil)
|
|
|
|
// 直接弹出系统评分控件, 不过一年最多3次, 用户还可以在系统设置里面关
|
|
|
|
// SKStoreReviewController.requestReview()
|
2021-12-27 22:33:27 +08:00
|
|
|
}
|
|
|
|
.padding(EdgeInsets(top: 18, leading: 20, bottom: 0, trailing: 20))
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
}
|
2022-01-10 00:26:29 +08:00
|
|
|
.onAppear {
|
|
|
|
if store.userInfo != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
Task {
|
|
|
|
store.userInfo = try await HttpRequest.getUserInfo()
|
|
|
|
}
|
|
|
|
}
|
2021-12-27 22:33:27 +08:00
|
|
|
}
|
2022-01-30 01:02:44 +08:00
|
|
|
|
|
|
|
func userName() -> String {
|
|
|
|
if let name = store.userInfo?.name {
|
|
|
|
if name.isEmpty {
|
|
|
|
return NSLocalizedString("苹果用户", comment: "")
|
|
|
|
} else {
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return "--"
|
|
|
|
}
|
|
|
|
}
|
2021-12-27 22:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct SettingsView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2022-01-10 00:26:29 +08:00
|
|
|
SettingsView().environmentObject(AppState.shared)
|
2021-12-27 22:33:27 +08:00
|
|
|
}
|
|
|
|
}
|