无故事王国
2024-05-23 efc3ee1d65062b2fc0ef83df06df18509661180e
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
//
//  CommonWebVC.swift
//  DolphinEnglishLearnManager
//
//  Created by 无故事王国 on 2024/5/14.
//
 
import UIKit
import WebKit
 
class CommonWebVC: BaseVC {
 
                enum CommonWebType{
                                case logoff
                                case userAgreement
                                case privacyAgreement
                                case userGuide
                }
 
                private var type:CommonWebType!
 
                init(type:CommonWebType) {
                                super.init(nibName: nil, bundle: nil)
                                self.type = type
                }
                
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
                
                override func viewDidLoad() {
                                super.viewDidLoad()
 
                }
 
                override func setUI() {
                                super.setUI()
 
 
                                if type == .logoff{
                                                let completeBtn = UIButton(type: .custom)
                                                completeBtn.jq_cornerRadius = 8
                                                completeBtn.addTarget(self, action: #selector(handleAction), for: .touchUpInside)
                                                completeBtn.setTitleColor(.white, for: .normal)
                                                completeBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .medium)
                                                completeBtn.setTitle("确认(10s)", for: .normal)
                                                completeBtn.backgroundColor = UIColor(hexStr: "#41A2EB")
                                                view.addSubview(completeBtn)
                                                completeBtn.snp.makeConstraints { make in
                                                                make.width.equalTo(316)
                                                                make.centerX.equalToSuperview()
                                                                make.bottom.equalToSuperview().offset(-91)
                                                                make.height.equalTo(47)
                                                }
 
                                                var time = 10 //倒计时时间
                                                let queue = DispatchQueue.global()
                                                let timer = DispatchSource.makeTimerSource(flags: [], queue: queue)
                                                timer.schedule(wallDeadline: DispatchWallTime.now(), repeating: .seconds(1));
                                                timer.setEventHandler(handler: {
                                                                if time <= 0 {
                                                                                timer.cancel()
                                                                                DispatchQueue.main.async(execute: {
                                                                                                completeBtn.setTitle("确认", for: .normal)
                                                                                                completeBtn.isUserInteractionEnabled = true
                                                                                                completeBtn.backgroundColor = UIColor(hexStr: "#41A2EB")
                                                                                });
                                                                }else {
                                                                                DispatchQueue.main.async(execute: {
                                                                                                completeBtn.setTitle("确认\(time)s", for: .normal)
                                                                                                completeBtn.isUserInteractionEnabled = false
                                                                                                completeBtn.backgroundColor = .gray
                                                                                });
                                                                }
                                                                time -= 1
                                                });
                                                timer.resume()
                                }
                }
 
                @objc func handleAction(sender:UIButton){
                                CommonAlertView.show(content:"确认注销当前登录账户吗?") {
 
                                }
                }
}