无故事王国
2025-08-10 9d8138cb1690c4c1990535d0507eb17cdbe497f9
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
//
//  UserLoginOffVC.swift
//  DolphinEnglishLearnStudent
//
//  Created by 无故事王国 on 2024/7/19.
//
 
import UIKit
import WebKit
 
class UserLoginOffVC: BaseVC {
 
    private var btn_loginOff:UIButton!
    private var webView:WKWebView!
    private var timer:Timer?
    private var times = 10
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
        yy_popBlock = {[weak self] () in
            guard let weakSelf = self else { return }
            var toVC:UIViewController?
            for subVC in weakSelf.navigationController?.viewControllers ?? []{
                if subVC.isKind(of: HomeListenV2VC.self){
                    toVC = subVC;break
                }
            }
 
            if toVC != nil{
                weakSelf.navigationController?.popToViewController(toVC!, animated: true)
            }else{
                weakSelf.navigationController?.popViewController(animated: true)
            }
        }
 
        Services.getAgreement(type: .logout).subscribe(onNext: {data in
            if let stringHTML = data.data{
                self.webView.loadHTMLString(stringHTML.jq_wrapHtml(edge: UIEdgeInsets(top: 0, left: 10, bottom: 3, right: 0)), baseURL: nil)
            }
        }).disposed(by: disposeBag)
 
        timer =    Timer(timeInterval: 1, repeats: true) {[weak self] timer in
            guard let weakSelf = self else { return }
            weakSelf.times -= 1
            weakSelf.btn_loginOff.setTitle("注销账号(\(weakSelf.times)s)", for: .normal)
 
            if weakSelf.times <= 0{
                print("----进入")
                weakSelf.btn_loginOff.isEnabled = true
                weakSelf.btn_loginOff.setTitle("注销账号", for: .normal)
                weakSelf.btn_loginOff.backgroundColor = UIColor(hexStr: "#41A2EB")
                weakSelf.timer?.invalidate()
            }
        }
        timer?.fire()
        RunLoop.current.add(timer!, forMode: .common)
    }
 
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        self.timer?.invalidate()
        self.timer = nil
    }
 
    override func setUI() {
 
        view.backgroundColor = .white
        webView = WKWebView(frame: .zero)
        view.addSubview(webView)
        webView.snp.makeConstraints { make in
            make.left.right.top.equalToSuperview()
            make.bottom.equalToSuperview().offset(-150)
        }
 
 
        btn_loginOff = UIButton(type: .custom)
        btn_loginOff.setTitle("注销账号", for: .normal)
        btn_loginOff.setTitleColor(.white, for: .normal)
        btn_loginOff.isEnabled = false
        btn_loginOff.backgroundColor = UIColor(hexStr: "#41A2EB")
        btn_loginOff.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium)
        btn_loginOff.addTarget(self, action: #selector(loginOffAction), for: .touchUpInside)
        btn_loginOff.jq_cornerRadius = 8
        view.addSubview(btn_loginOff)
        btn_loginOff.snp.makeConstraints { make in
            make.width.equalTo(316)
            make.height.equalTo(49)
            make.bottom.equalTo(-91)
            make.centerX.equalToSuperview()
        }
    }
 
    @objc func loginOffAction(){
        CommonAlertView.show(content: "确认注销当前登录账户吗?", completeTitle: "确认") {[weak self] () in
            guard let weakSelf = self else { return }
            Services.loginOff().subscribe(onNext: {data in
                sceneDelegate?.needLogin()
            }).disposed(by: weakSelf.disposeBag)
        } cancelClouse: {
 
        }
    }
}