IOS_Boss/IOS_study/Auth/SignInPhoneView+.swift
2025-07-27 12:33:06 +08:00

46 lines
1.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// SignInPhoneView+.swift
// IOS_study
//
// Created by CC-star on 2025/7/10.
//
import Foundation
extension SignInPhoneView {
func stopTimer() { timer?.upstream.connect().cancel(); timer = nil }//
func getVerCode() async {//async ->
guard vm.phoneNum.isPhoneNum else { return }
do {
//todo
try await vm.getVerCode(phoneNum: "+86\(vm.phoneNum)", tName: "login", sName: "名称")
} catch {
print("获取验证码失败:\(error)")
hud.show("获取验证码失败:\(error)")
}
}
func preLogin() {
focusedField = nil
if isAgree {
Task { await login() }
} else {
showAgreeSheet = true
}
}
//+8613123456789 797687
func login() async {
guard vm.phoneNum.isPhoneNum, vm.verCode.isVerCode else { hud.show("手机号或验证码错误"); return }
vm.isLogining = true
defer { vm.isLogining = false }
do {
try await vm.login()
stopTimer()
hud.show("登录成功")
} catch {
print("登录失败:\(error)")
hud.show("登录失败:\(error)")
}
}
}