JLChen
2021-04-30 a5247b61d585627a1a7b1e1f35f34de9f0af9fba
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
//  Copyright © 2018年 Zhejiang Dahua Technology Co.,Ltd. All rights reserved.
//    通用错误界面:适用于按钮固定的场景
 
import UIKit
 
class DHErrorBaseViewController: DHAddBaseViewController, DHCommonErrorViewDelegate, DHErrorBaseVCProtocol {
 
    public var errorView: DHCommonErrorView = DHCommonErrorView.xibInstance()
    
    override func viewDidLoad() {
        super.viewDidLoad()
 
        // Do any additional setup after loading the view.
        setupErrorView()
    }
 
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func setupErrorView() {
        errorView.delegate = self
        view.addSubview(errorView)
        
        errorView.snp.makeConstraints { make in
            make.edges.equalTo(self.view)
        }
        
        errorView.imageView.image = UIImage(named: errorImageName())
        errorView.contentLabel.dh_setAttributedText(text: errorContent(), font: UIFont.dhFont_t2())
        errorView.detailLabel.dh_setAttributedText(text: errorDescription(), font: UIFont.dhFont_t4())
        errorView.contentLabel.textColor = UIColor.dhcolor_c2()
        errorView.detailLabel.textColor = UIColor.dhcolor_c5()
        errorView.confrimButton.setTitle(confirmText(), for: .normal)
        errorView.confrimButton.isHidden = icConfirmHidden()
        errorView.confrimButton.setTitleColor(UIColor.dhcolor_c43(), for: .normal)
        errorView.quitButton.setTitle(quitText(), for: .normal)
        errorView.quitButton.setTitleColor(UIColor.dhcolor_c2(), for: .normal)
        errorView.quitButton.isHidden = isQuitHidden()
        
        if dh_screenHeight < 667 {
            errorView.contentLabel.dh_setAttributedText(text: errorContent(), font: UIFont.systemFont(ofSize: 13))
        } else {
            errorView.contentLabel.dh_setAttributedText(text: errorContent(), font: UIFont.dhFont_t2())
        }
    }
    
    public func dismiss() {
        self.view.removeFromSuperview()
        self.parent?.view.lc_transitionAnimation(type: .fade, direction: .fromBottom, duration: 0.3)
        self.removeFromParentViewController()
    }
    
    public func showOnParent(controller: UIViewController) {
        controller.addChildViewController(self)
        controller.view.addSubview(self.view)
        self.view.frame = controller.view.bounds
        
        controller.view.lc_transitionAnimation(type: .fade, direction: .fromBottom, duration: 0.3)
    }
    
    // MARK: DHAddBaseVCProtocol
    override func leftActionType() -> DHAddBaseLeftAction {
        return .quit
    }
    
    override func isLeftActionShowAlert() -> Bool {
        return true
    }
    
    override func rightActionType() -> [DHAddBaseRightAction] {
        return [.restart]
    }
    
    // MARK: DHErrorBaseVCProtocol
    func errorImageName() -> String {
        return "adddevice_fail_configurationfailure"
    }
    
    func errorContent() -> String {
        return "Please input content"
    }
    
    func errorDescription() -> String? {
        return nil
    }
    
    func icConfirmHidden() -> Bool {
        return false
    }
    
    func confirmText() -> String {
        return "add_device_confirm".lc_T
    }
    
    func quitText() -> String {
        return "add_device_quit".lc_T
    }
    
    func isQuitHidden() -> Bool {
        return true
    }
    
    func doConfirm() {
        baseBackToAddDeviceRoot()
    }
    
    func doQuit() {
        baseExitAddDevice()
    }
    
    func doFAQ() {
        basePushToFAQ()
    }
    
    func doBackRoot() {
        baseBackToAddDeviceRoot()
    }
}
 
extension DHErrorBaseViewController {
    // MARK: DHCommonErrorViewDelegate
    func errorViewOnConfirm(errorView: DHCommonErrorView) {
        doConfirm()
    }
    
    func errorViewOnFAQ(errorView: DHCommonErrorView) {
        doFAQ()
    }
    
    func errorViewOnQuit(errorView: DHCommonErrorView) {
        doQuit()
    }
    
    func errorViewOnBackRoot(errorView: DHCommonErrorView) {
        doBackRoot()
    }
}