46 lines
1.2 KiB
Swift
46 lines
1.2 KiB
Swift
//
|
||
// 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)")
|
||
}
|
||
}
|
||
}
|