JLChen
2021-05-18 a869383e163a18cdedcf587383c1eca043129754
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
//  Copyright © 2018年 Zhejiang Dahua Technology Co.,Ltd. All rights reserved.
//  密码检验界面解释器:普通设备
 
import UIKit
 
protocol DHAuthPasswordPresenterProtocol {
    var container: DHAuthPasswordViewController? {
        set get
    }
    
    init(container: DHAuthPasswordViewController)
    
    /// 下一步验证密码响应
    ///
    /// - Parameters:
    ///   - password: 密码
    ///   - device: 局域网搜索到的设备
    ///   - deviceId: 序列号
    func nextStepAction(password: String, device: ISearchDeviceNetInfo?, deviceId: String)
}
 
class DHAuthPasswordPresenter: NSObject, DHAuthPasswordPresenterProtocol {
    weak var container: DHAuthPasswordViewController?
 
    /// 是否已经进行过登录验证【暂缓实现】
    private var isLoginAuthed: Bool = false
    
    private lazy var bindPresenter: DHBindPresenter = {
        let presenter = DHBindPresenter()
        return presenter
    }()
    
    required init(container: DHAuthPasswordViewController) {
        self.container = container
    }
    
    func nextStepAction(password: String, device: ISearchDeviceNetInfo?, deviceId: String) {
        //【*】支持SC码的,直接进行绑定; 不支持的,进入旧的分支处理
        if DHAddDeviceManager.sharedInstance.isSupportSC {
            self.bind(password: password, isPasswordAuthed: false)
            return
        }
        
        //【*】国内、SMB:直接绑定
        self.bind(password: password, isPasswordAuthed: false)
    }
    
    func showDeviceLockVC() {
        let controller = DHDeviceLockViewController()
        self.container?.navigationController?.pushViewController(controller, animated: true)
    }
    
    func bind(password: String, isPasswordAuthed: Bool, showLoading: Bool = true) {
        bindPresenter.setup(container: self.container)
        bindPresenter.bindDevice(devicePassword: password, isPasswordAuthed: isPasswordAuthed, code: nil, deviceKey: nil, showLoading: showLoading, showErrorTip: true, complete: nil)
    }
}