|
|
@@ -237,7 +237,6 @@ class LoginViewController: BaseTableViewController<LsLoginUserModel>, UITextFiel
|
|
|
|
|
|
/// 登录方法
|
|
|
func startLogin() {
|
|
|
-
|
|
|
/// 异常
|
|
|
guard checkValue(),
|
|
|
let accountManager = MTP2BusinessCore.shared.accountManager,
|
|
|
@@ -271,48 +270,54 @@ class LoginViewController: BaseTableViewController<LsLoginUserModel>, UITextFiel
|
|
|
guard let trade_address = MTP2BusinessCore.shared.address?.tradeHost,
|
|
|
let trade_port = MTP2BusinessCore.shared.address?.tradePort,
|
|
|
let intPort = UInt16(trade_port) else { return }
|
|
|
-
|
|
|
- /// 获取登录ID
|
|
|
- accountManager.getUserLoginID(account) { (isSuccess, err, loginId) in
|
|
|
- if !isSuccess {
|
|
|
- faidBlock(err)
|
|
|
+ /// 每次登录前重新请求地址信息
|
|
|
+ MTP2BusinessCore.shared.requestAppAdress(true) { (isAddress, er) in
|
|
|
+ if !isAddress {
|
|
|
+ faidBlock(er)
|
|
|
return
|
|
|
}
|
|
|
- DispatchQueue.main.async {
|
|
|
- accountManager.login(address: trade_address, port: intPort, userName: loginId!, password: password, deviceID: NSUUID().uuidString, version: app_Version) { isCompleted, error in
|
|
|
- if isCompleted {
|
|
|
- /// 用户与商品信息统一查询
|
|
|
- accountManager.queryAccountAndGoods(callback: { (isCompleted, error) in
|
|
|
- if isCompleted {
|
|
|
- DispatchQueue.main.async {
|
|
|
- /// 如果有 先删除
|
|
|
- if let _ = try? DatabaseHelper.getUser(userID: MTP2BusinessCore.shared.getUserID(), type: Int16(0)) {
|
|
|
- try? DatabaseHelper.deleteUser(userID: MTP2BusinessCore.shared.getUserID())
|
|
|
- }
|
|
|
- DispatchQueue.global().asyncAfter(deadline: DispatchTime.now()+0.5, execute: {
|
|
|
- /// 记录本地用户信息
|
|
|
- try? DatabaseHelper.addUser(userID: MTP2BusinessCore.shared.getUserID(), loginID: account, loginDate: Date(), type: Int16(0))
|
|
|
- })
|
|
|
- if self.savePwd.isOn {
|
|
|
- /// 记住密码和时间
|
|
|
- UserDefaultsUtils.setSavePwd(password)
|
|
|
- UserDefaultsUtils.setSavePwdTime(Date())
|
|
|
- }
|
|
|
- self._anim?.stopAnimating()
|
|
|
- self.view.isUserInteractionEnabled = true
|
|
|
- self.loginButton.isEnabled = true
|
|
|
- /// 进入主界面
|
|
|
- if let mainTabBarController: UITabBarController = self.storyboard?.instantiateViewController(withIdentifier: "MainTabBarController") as? UITabBarController {
|
|
|
- /// 设置根视图
|
|
|
- (UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController = mainTabBarController
|
|
|
+ /// 获取登录ID
|
|
|
+ accountManager.getUserLoginID(account) { (isSuccess, err, loginId) in
|
|
|
+ if !isSuccess {
|
|
|
+ faidBlock(err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ accountManager.login(address: trade_address, port: intPort, userName: loginId!, password: password, deviceID: NSUUID().uuidString, version: app_Version) { isCompleted, error in
|
|
|
+ if isCompleted {
|
|
|
+ /// 用户与商品信息统一查询
|
|
|
+ accountManager.queryAccountAndGoods(callback: { (isCompleted, error) in
|
|
|
+ if isCompleted {
|
|
|
+ DispatchQueue.main.async {
|
|
|
+ /// 如果有 先删除
|
|
|
+ if let _ = try? DatabaseHelper.getUser(userID: MTP2BusinessCore.shared.getUserID(), type: Int16(0)) {
|
|
|
+ try? DatabaseHelper.deleteUser(userID: MTP2BusinessCore.shared.getUserID())
|
|
|
+ }
|
|
|
+ DispatchQueue.global().asyncAfter(deadline: DispatchTime.now()+0.5, execute: {
|
|
|
+ /// 记录本地用户信息
|
|
|
+ try? DatabaseHelper.addUser(userID: MTP2BusinessCore.shared.getUserID(), loginID: account, loginDate: Date(), type: Int16(0))
|
|
|
+ })
|
|
|
+ if self.savePwd.isOn {
|
|
|
+ /// 记住密码和时间
|
|
|
+ UserDefaultsUtils.setSavePwd(password)
|
|
|
+ UserDefaultsUtils.setSavePwdTime(Date())
|
|
|
+ }
|
|
|
+ self._anim?.stopAnimating()
|
|
|
+ self.view.isUserInteractionEnabled = true
|
|
|
+ self.loginButton.isEnabled = true
|
|
|
+ /// 进入主界面
|
|
|
+ if let mainTabBarController: UITabBarController = self.storyboard?.instantiateViewController(withIdentifier: "MainTabBarController") as? UITabBarController {
|
|
|
+ /// 设置根视图
|
|
|
+ (UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController = mainTabBarController
|
|
|
+ }
|
|
|
}
|
|
|
+ } else {
|
|
|
+ faidBlock(error)
|
|
|
}
|
|
|
- } else {
|
|
|
- faidBlock(error)
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- faidBlock(error)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ faidBlock(error)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -406,11 +411,12 @@ class LoginViewController: BaseTableViewController<LsLoginUserModel>, UITextFiel
|
|
|
|
|
|
// MARK: - UITableViewDelegate
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
-
|
|
|
super.tableView(tableView, didSelectRowAt: indexPath)
|
|
|
-
|
|
|
+ /// 显示选中的账户信息
|
|
|
usernameTextField.text = tableCellModels[indexPath.row].loginID
|
|
|
userTableView.isHidden = true
|
|
|
+ /// 清空密码输入框
|
|
|
+ passwordTextField.text = ""
|
|
|
}
|
|
|
}
|
|
|
|