110 lines
3.5 KiB
Swift
110 lines
3.5 KiB
Swift
//
|
|
// MyProfileVC.swift
|
|
// QuickLocation
|
|
//
|
|
// Created by 八条 on 2026/6/11.
|
|
//
|
|
|
|
import UIKit
|
|
import RxSwift
|
|
import RxCocoa
|
|
|
|
class MyProfileVC: BaseViewController {
|
|
|
|
fileprivate var rootView: MyProfileView!
|
|
|
|
override func loadView() {
|
|
rootView = MyProfileView(frame: UIScreen.main.bounds)
|
|
view = rootView
|
|
}
|
|
|
|
private var headPic: Int = AppContextManager.shared.head_pic.integer {
|
|
didSet {
|
|
self.rootView.avatarImgView.image = UIImage(named: "UserIcon/\(headPic)")
|
|
}
|
|
}
|
|
|
|
private var nickName: String = AppContextManager.shared.name {
|
|
didSet {
|
|
self.rootView.nickNameLab.text = nickName
|
|
}
|
|
}
|
|
|
|
private var sex: Int = AppContextManager.shared.sex {
|
|
didSet {
|
|
rootView.maleCheckbox.isSelected = rootView.maleCheckbox.tag == sex
|
|
rootView.femaleCheckbox.isSelected = rootView.femaleCheckbox.tag == sex
|
|
}
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
// Do any additional setup after loading the view.
|
|
reactiveAction()
|
|
}
|
|
|
|
private func reactiveAction() {
|
|
// 头像
|
|
rootView.avatarView.rx.tapGesture.subscribe(onNext: { _ in
|
|
let vc = AvatarIconListVC(iconIndex: self.headPic.string)
|
|
vc.onSelectIcon = { index in
|
|
self.requestSetHeadPic(index: index)
|
|
}
|
|
self.navigationController?.pushViewController(vc, animated: true)
|
|
}).disposed(by: disposeBag)
|
|
|
|
// 昵称
|
|
rootView.nickNameView.rx.tapGesture.subscribe { _ in
|
|
let vc = TextInputViewController(title: "昵称", maxLength: 10, initialText: self.nickName) { text in
|
|
self.requestSetNickName(text)
|
|
}
|
|
self.present(vc, animated: true, completion: nil)
|
|
}.disposed(by: disposeBag)
|
|
|
|
// 性别
|
|
rootView.maleCheckbox.rx.tap.subscribe(onNext: { [weak self] in
|
|
guard let self = self else { return }
|
|
self.requestSetGender(1)
|
|
})
|
|
.disposed(by: disposeBag)
|
|
|
|
rootView.femaleCheckbox.rx.tap.subscribe(onNext: { [weak self] in
|
|
guard let self = self else { return }
|
|
self.requestSetGender(2)
|
|
})
|
|
.disposed(by: disposeBag)
|
|
}
|
|
|
|
// MARK: - API 设置头像
|
|
private func requestSetHeadPic(index: Int) {
|
|
DLToast.showLoading()
|
|
UserService.setHeadPic(index: index).subscribe(onNext: { response in
|
|
DLToast.show(text: "更换成功")
|
|
self.headPic = index
|
|
// 通知各页面刷新头像
|
|
NotificationCenter.default.post(name: .RefreshUserConfigNotification, object: nil)
|
|
}, onError: { _ in }).disposed(by: disposeBag)
|
|
}
|
|
|
|
// MARK: - API 设置昵称
|
|
private func requestSetNickName(_ name: String) {
|
|
DLToast.showLoading()
|
|
UserService.setNickName(nick: name).subscribe(onNext: { response in
|
|
DLToast.show(text: "修改成功")
|
|
self.nickName = name
|
|
|
|
NotificationCenter.default.post(name: .RefreshUserConfigNotification, object: nil)
|
|
}, onError: { _ in }).disposed(by: disposeBag)
|
|
}
|
|
|
|
// MARK: - API 设置性别
|
|
private func requestSetGender(_ sex: Int) {
|
|
DLToast.showLoading()
|
|
UserService.setGender(sex: sex).subscribe(onNext: { response in
|
|
DLToast.show(text: "修改成功")
|
|
self.sex = sex
|
|
}, onError: { _ in }).disposed(by: disposeBag)
|
|
}
|
|
}
|