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

101 lines
2.7 KiB
Swift

//
// LoginView.swift
// PushDeer
//
// Created by HEXT on 2021/12/25.
//
import SwiftUI
import AuthenticationServices
///
struct LoginView: View {
@EnvironmentObject private var store: AppState
@State private var showLoading = false
var body: some View {
VStack{
Spacer()
Image("logo.with.space")
.resizable()
.scaledToFit()
if Env.isSelfHosted {
Button("重置API endpoint") {
store.api_endpoint = ""
}
}
Spacer()
if showLoading {
ProgressView()
.scaleEffect(1.5)
.frame(height: 64)
} else {
//
AppleSignInButton(
onRequest: { request in
request.requestedScopes = [.fullName, .email]
},
onCompletion: { result in
do {
showLoading = true
store.token = try await store.appleIdLogin(result).token
//
} catch {
showLoading = false
if (error as NSError).code == 1001 {
//
HToast.showWarning(error.localizedDescription)
return
}
HToast.showError(error.localizedDescription)
}
}
)
.overlay(RoundedRectangle(cornerRadius: 6).stroke(Color.white))
.frame(maxWidth: 375, minHeight: 64, maxHeight: 64)
.padding()
#if !targetEnvironment(macCatalyst) && !APPCLIP && !SELFHOSTED
if WXApi.isWXAppInstalled() {
//
Button {
let req = SendAuthReq()
req.scope = "snsapi_userinfo";
req.state = "login";
WXApi.send(req) { b in
print("WXApi.send:", b)
}
// AppDelegate onResp
} label: {
HStack {
Image("weixin-login")
.resizable()
.renderingMode(.template)
.scaledToFit()
.frame(height:20)
Text("通过微信登录")
}
.font(.system(size: 26, weight: .semibold))
.foregroundColor(Color("weixinFgColor"))
.frame(maxWidth: 375, minHeight: 64, maxHeight: 64)
}
.background(Color("weixinBgColor"))
.cornerRadius(6)
.overlay(RoundedRectangle(cornerRadius: 6).stroke(Color("weixinFgColor")))
.padding()
}
#endif
}
Spacer()
}
.padding()
}
}
struct LoginView_Previews: PreviewProvider {
static var previews: some View {
LoginView()
}
}