浏览代码

切换账号完成 up

openlockPPP 1 年之前
父节点
当前提交
c4c588ab0a

+ 12 - 0
JiaPeiManage.xcodeproj/project.pbxproj

@@ -26,6 +26,7 @@
 		903B4E6A2A73A49D00FD7320 /* SwitchAccountCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 903B4E692A73A49D00FD7320 /* SwitchAccountCell.swift */; };
 		903B4E6C2A73A4B000FD7320 /* SwitchAccountCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 903B4E6B2A73A4B000FD7320 /* SwitchAccountCell.xib */; };
 		903B4E6E2A73C5D800FD7320 /* NYAccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 903B4E6D2A73C5D800FD7320 /* NYAccountManager.swift */; };
+		903B4E712A778EFF00FD7320 /* SwitchAccountViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 903B4E702A778EFF00FD7320 /* SwitchAccountViewModel.swift */; };
 		903C04AA2A651B1200935764 /* NYIDFA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 903C04A92A651B1200935764 /* NYIDFA.swift */; };
 		903C04AC2A651DBC00935764 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 903C04AB2A651DBC00935764 /* AdSupport.framework */; };
 		9043AD9B2A542267005F6F81 /* StatisticsOfficialPageHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9043AD9A2A542267005F6F81 /* StatisticsOfficialPageHeaderView.swift */; };
@@ -204,6 +205,7 @@
 		903B4E692A73A49D00FD7320 /* SwitchAccountCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchAccountCell.swift; sourceTree = "<group>"; };
 		903B4E6B2A73A4B000FD7320 /* SwitchAccountCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SwitchAccountCell.xib; sourceTree = "<group>"; };
 		903B4E6D2A73C5D800FD7320 /* NYAccountManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NYAccountManager.swift; sourceTree = "<group>"; };
+		903B4E702A778EFF00FD7320 /* SwitchAccountViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchAccountViewModel.swift; sourceTree = "<group>"; };
 		903C04A92A651B1200935764 /* NYIDFA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NYIDFA.swift; sourceTree = "<group>"; };
 		903C04AB2A651DBC00935764 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; };
 		9043AD9A2A542267005F6F81 /* StatisticsOfficialPageHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatisticsOfficialPageHeaderView.swift; sourceTree = "<group>"; };
@@ -415,6 +417,14 @@
 			path = Views;
 			sourceTree = "<group>";
 		};
+		903B4E6F2A778E8800FD7320 /* ViewModel */ = {
+			isa = PBXGroup;
+			children = (
+				903B4E702A778EFF00FD7320 /* SwitchAccountViewModel.swift */,
+			);
+			path = ViewModel;
+			sourceTree = "<group>";
+		};
 		9043AD9E2A554BF9005F6F81 /* 二维码 */ = {
 			isa = PBXGroup;
 			children = (
@@ -1011,6 +1021,7 @@
 		90CE52E52A36E7D00033BD06 /* Mine */ = {
 			isa = PBXGroup;
 			children = (
+				903B4E6F2A778E8800FD7320 /* ViewModel */,
 				903B4E682A73A46000FD7320 /* Views */,
 				9076C5D52A38694000E5E33F /* Controllers */,
 			);
@@ -1316,6 +1327,7 @@
 				90BC4BD92A3B0F98006FD683 /* TraineeDataModel.swift in Sources */,
 				90CE52F12A36ECC80033BD06 /* NYWebViewController.swift in Sources */,
 				90CE52AD2A36E59A0033BD06 /* UIView+CornerRadius.swift in Sources */,
+				903B4E712A778EFF00FD7320 /* SwitchAccountViewModel.swift in Sources */,
 				90CE52792A36E5460033BD06 /* LWPlayerUtils.swift in Sources */,
 				90BC4BDC2A3C2556006FD683 /* TVHeaderAnimator.swift in Sources */,
 				90CE527B2A36E5460033BD06 /* LWPlayerEnum.swift in Sources */,

+ 3 - 3
JiaPeiManage/Sources/Models/UserInfoModel.swift

@@ -141,7 +141,7 @@ struct CoachJsonInfo :ImmutableMappable,Codable{
 }
 
 
-struct UserInfo :ImmutableMappable{
+struct UserInfo :ImmutableMappable,Codable{
    
 
     var id:Int = 0
@@ -284,8 +284,8 @@ struct UserInfo :ImmutableMappable{
         occupationNo = try map.value("occupationNo") ?? ""
         occupationLevel = try map.value("occupationLevel") ?? ""
         dripermitted = try map.value("dripermitted") ?? ""
-        teachpermitted = try map.value("teachpermitted")
-        employStatus = try map.value("employStatus")
+        teachpermitted = try map.value("teachpermitted") ?? ""
+        employStatus = try map.value("employStatus") ?? ""
         hireDate = try map.value("hireDate") ?? ""
         leaveDate = try map.value("leaveDate") ?? ""
         createDate = try map.value("createDate") ?? ""

+ 1 - 0
JiaPeiManage/Sources/Modulars/Login/Controllers/LoginViewController.swift

@@ -154,6 +154,7 @@ final class LoginViewController: BaseViewController {
                                 NYTips.hide()
                                 LocalManager.userInfo = userinfo
                                 LocalManager.userInfo.isLogin = true //设置已经登录
+                                NYAccountManager.shared.addUserinfo(user: userinfo)//添加用户信息
                                 print("登录成功:%@", userinfo)
                                 self.dismiss(animated: true)
                             }, onError: { error in

+ 5 - 2
JiaPeiManage/Sources/Modulars/Mine/Controllers/MineViewController.swift

@@ -44,7 +44,11 @@ final class MineViewController: BaseViewController {
     override func viewDidLoad() {
         super.viewDidLoad()
         setupUI()
-        
+        biandView()
+    }
+    
+    override func viewWillAppear(_ animated: Bool) {
+        super.viewWillAppear(animated)
         self.cocahService.coachInfoRequest(id:String("\(LocalManager.userInfo.id)"), city: LocalManager.userInfo.city!)
             .subscribe(onSuccess: { userinfo in
                 LocalManager.userInfo = userinfo
@@ -52,7 +56,6 @@ final class MineViewController: BaseViewController {
             }, onError: { error in
             })
             .disposed(by: disposeBag)
-        biandView()
     }
     
     // MARK: 私有方法

+ 40 - 30
JiaPeiManage/Sources/Modulars/Mine/Controllers/SwitchAccountViewController.swift

@@ -13,9 +13,6 @@ import RxCocoa
 final class SwitchAccountViewController: BaseTableViewController {
     
     let cellIdentifier:String = "_SwitchAccountCellID"
-    // MARK: 服务属性
-    private let cocahService: CoachServiceType = CoachService(networking: CoachNetworking())
-    
     // MARK: UI let
     let statusBar = UIView().then {
         $0.backgroundColor = UIColor.db_theme
@@ -26,9 +23,9 @@ final class SwitchAccountViewController: BaseTableViewController {
     }
     
     //edit
-    
     var edit:Bool = false
-
+    //切换viewmodel
+    let switchAccountViewModel = SwitchAccountViewModel()
     
     override func setupConstraints() {
         
@@ -66,46 +63,59 @@ final class SwitchAccountViewController: BaseTableViewController {
         self.navBar.search_button.setImage(nil, for: .normal)
         self.navBar.search_button.setTitle("编辑", for: .normal)
         self.navBar.search_button.titleLabel?.font = NYFont.SysFont.sys_14
-        self.navBar.search_button.rx.tap.subscribe ({ [unowned self] (_)  in
-            self.edit = !self.edit
-            
-            self.tableView.reloadData()
-        }).disposed(by: disposeBag)
-        //self.navBar.search_button.addTarget(self, action: #selector(jumpSearchdo), for: .touchUpInside)
+        self.switchAccountViewModel.vc = self
+        
     }
     //绑定-rx
     func biandView(){
-        tableView.dataSource = self
+        
         tableView.delegate = self
         tableView.separatorStyle = .none //去除分割线
         tableView.register(UINib(nibName: "SwitchAccountCell", bundle: nil), forCellReuseIdentifier: cellIdentifier)
         tableView.rowHeight = 96.f
         tableView.alwaysBounceVertical = false
         tableView.bounces = false
+        tableView.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 20, right: 0)
         self.isEmptyDisplay = true
         self.hideLoadAnimation()
+        //编辑事件
+        self.navBar.search_button.rx.tap.subscribe ({ [unowned self] (_)  in
+            self.edit = !self.edit
+            let title = self.edit ? "完成":"编辑"
+            self.navBar.search_button.setTitle(title, for: .normal)
+            self.switchAccountViewModel.getAccountsRead()
+        }).disposed(by: disposeBag)
+        //RX 绑定
+        self.switchAccountViewModel.items
+            .bind(to: tableView.rx.items(cellIdentifier: cellIdentifier,cellType:SwitchAccountCell.self)) {[unowned self] (row, model, cell) in
+                cell.sacontentView.backgroundColor = ((row%2) != 0) ? UIColor("#113357") : UIColor("#0B2B4D")
+                cell.setIsEdit(edit: self.edit)
+                cell.setUserinfo(userinfo: model)
+                cell.index = row
+                cell.viewModel = self.switchAccountViewModel
+            }
+            .disposed(by: disposeBag)
+        // 单独处理删除按钮的点击事件,不与 tableView.rx.items 的绑定混合
+        self.switchAccountViewModel.deleteButtonTapped
+            .subscribe(onNext: { [unowned self] row in
+                // 在这里处理点击事件,row 表示点击的单元格的索引
+                self.switchAccountViewModel.deleteAccount(row: row)
+            })
+            .disposed(by: disposeBag)
+        // tableView点击事件
+        tableView.rx.itemSelected.throttle(.seconds(1), scheduler: MainScheduler.instance)
+            .subscribe(onNext: { [unowned self]indexPath in
+                print("点击\(indexPath)行")
+                if !self.edit{
+                    self.switchAccountViewModel.switchAccount(row: indexPath.row)
+                }
+        }).disposed(by: disposeBag)
+        self.switchAccountViewModel.getAccountsRead()
     }
     
-    
-}
-
-
-//数据源
-extension SwitchAccountViewController:UITableViewDataSource {
-
-    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        return 5
-    }
-
-    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-        let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! SwitchAccountCell
-        cell.sacontentView.backgroundColor = ((indexPath.row%2) != 0) ? UIColor("#113357") : UIColor("#0B2B4D")
-        cell.setIsEdit(edit: edit)
-//        cell.setRowInfo(rowInfo: self.meTraineeSearchViewModel.rows[indexPath.row])
-        return cell
-    }
 }
 
 //事件
 extension SwitchAccountViewController:UITableViewDelegate {
+    
 }

+ 113 - 0
JiaPeiManage/Sources/Modulars/Mine/ViewModel/SwitchAccountViewModel.swift

@@ -0,0 +1,113 @@
+//
+//  SwitchAccountViewModel.swift
+//  JiaPeiManage
+//
+//  Created by Ning.ge on 2023/7/31.
+//
+
+import UIKit
+import RxSwift
+
+class SwitchAccountViewModel: NSObject {
+    
+    // MARK: 服务属性
+    private let loginService: LoginServiceType = LoginService(networking: LoginNetworking())
+    
+    private let itemsSubject = BehaviorSubject<[AccountInfo]>(value: [])
+    //删除的PublishSubject
+    let deleteButtonTapped = PublishSubject<Int>()
+    
+    var items: Observable<[AccountInfo]> {
+        return itemsSubject.asObservable()
+    }
+    
+    @objc weak var vc:SwitchAccountViewController? = nil
+    
+    // MARK: 数据
+    var rows:[AccountInfo] = []
+
+    
+    override init() {
+        super.init()
+//        searchCoachInfoList()
+    }
+    
+    //获取用户并刷新
+    func getAccountsRead(){
+        self.rows = NYAccountManager.shared.getAccounts()
+        itemsSubject.onNext(self.rows)//消息rx
+    }
+    
+    //切换事件
+    func switchAccount(row:Int){
+        let userinfo = self.rows[row];
+        if userinfo.idcard == LocalManager.userInfo.idcard {
+            NYTips.showMsg(txt: "您已经登录")
+            return
+        }
+        let action1 = QMUIAlertAction(title: "取消", style: .cancel, handler: nil)
+        let action2 = QMUIAlertAction(title: "切换", style: .destructive) { [unowned self] vc, action in
+            self.switchLogindo(userinfo: userinfo)
+        }
+        let alertController = QMUIAlertController(title: "提示", message: "确认切换身份?", preferredStyle: .alert)
+        alertController.addAction(action1)
+        alertController.addAction(action2)
+        let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
+        visualEffectView.qmui_foregroundColor = UIColor(255, 255, 255,0.7) // UIColorMakeWithRGBA(255, 255, 255, 0.7) // Use the default value in most cases, only demonstrate how to set here
+        alertController.mainVisualEffectView = visualEffectView
+        alertController.alertHeaderBackgroundColor = nil // Remove these background colors when you need to use the blur effect
+        alertController.alertButtonBackgroundColor = nil
+        alertController.showWith(animated: true)
+        
+    }
+    //切换登录逻辑
+    private func switchLogindo(userinfo:AccountInfo){
+        //登录逻辑
+        //保存用户信息
+        let account:String = userinfo.idcard
+        let password:String = userinfo.password
+        let city:String = userinfo.dqbh
+        let cityPower:String = userinfo.cityPower
+        LocalManager.userInfo.userAccount = account
+        LocalManager.userInfo.password = password
+        LocalManager.userInfo.city = city
+        LocalManager.userInfo.cityPower = cityPower
+        //登录api RX 订阅 观察 销毁 三部曲
+        NYTips.show()
+        self.loginService.loginRequest(user_name: account, user_password: password,city: city)
+            .subscribe(onSuccess: { userinfo in
+                NYTips.hide()
+                LocalManager.userInfo = userinfo
+                LocalManager.userInfo.isLogin = true //设置已经登录
+                print("登录成功:%@", userinfo)
+                NYTips.showMsg(txt: "切换成功")
+            }, onError: { error in
+                NYTips.hide()
+                NYTips.showErr(txt: (error as! RequestError).errorDescription)
+                print("%@",error)
+            })
+            .disposed(by: vc!.disposeBag)
+    }
+    
+    //删除用户
+    func deleteAccount(row:Int){
+        let action1 = QMUIAlertAction(title: "取消", style: .cancel, handler: nil)
+        
+        let alertController = QMUIAlertController(title: "提示", message: "确认删除这个用户信息?", preferredStyle: .alert)
+        let action2 = QMUIAlertAction(title: "删除", style: .default) { [unowned self] vc, action in
+            NYAccountManager.shared.deleteAccount(at: row)
+            self.getAccountsRead()
+        }
+        alertController.addAction(action1)
+        alertController.addAction(action2)
+        let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
+        visualEffectView.qmui_foregroundColor = UIColor(255, 255, 255,0.7) // UIColorMakeWithRGBA(255, 255, 255, 0.7) // Use the default value in most cases, only demonstrate how to set here
+        alertController.mainVisualEffectView = visualEffectView
+        alertController.alertHeaderBackgroundColor = nil // Remove these background colors when you need to use the blur effect
+        alertController.alertButtonBackgroundColor = nil
+        alertController.showWith(animated: true)
+        print("deleteAccount2")
+    }
+    
+}
+

+ 20 - 1
JiaPeiManage/Sources/Modulars/Mine/Views/SwitchAccountCell.swift

@@ -25,7 +25,9 @@ final class SwitchAccountCell: UITableViewCell,NibLoadable {
     //地址
     @IBOutlet weak var adderss_label: UILabel!
     
-    
+    var viewModel: SwitchAccountViewModel?
+    var userinfo:AccountInfo?
+    var index:Int = 0
     override func awakeFromNib() {
         super.awakeFromNib()
         self.backgroundColor = .db_theme
@@ -43,5 +45,22 @@ final class SwitchAccountCell: UITableViewCell,NibLoadable {
             del_layout_w.constant = 0.f
         }
     }
+    
+    func setUserinfo(userinfo:AccountInfo){
+        self.userinfo = userinfo
+        if userinfo != nil {
+            //用户头像
+            self.user_imageview.sd_setImage(with: userinfo.photoPath.urlValue, placeholderImage: userinfo.sex == "2" ? NYImage.Home.userfemale:NYImage.Home.usermale)
+            self.username_label.text = userinfo.name
+            self.idcart_label.text = userinfo.idcard
+            self.adderss_label.text = userinfo.address
+        }
+    }
+    
+    //点击del
+    @IBAction func buttonActionDeldo(_ sender: UIButton) {
+        viewModel!.deleteButtonTapped.onNext(index)
+    }
+    
 }
 

+ 9 - 1
JiaPeiManage/Sources/Modulars/Mine/Views/SwitchAccountCell.xib

@@ -28,6 +28,9 @@
                                     </constraints>
                                     <state key="normal" title="Button"/>
                                     <buttonConfiguration key="configuration" style="plain" image="btn_del_red"/>
+                                    <connections>
+                                        <action selector="buttonActionDeldo:" destination="iN0-l3-epB" eventType="touchUpInside" id="gx7-PI-NBi"/>
+                                    </connections>
                                 </button>
                             </subviews>
                             <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
@@ -55,12 +58,17 @@
                             <color key="textColor" red="0.83137254900000002" green="0.86666666670000003" blue="0.90196078430000004" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                             <nil key="highlightedColor"/>
                         </label>
-                        <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="mine-coach-male" translatesAutoresizingMaskIntoConstraints="NO" id="zc3-75-pkU">
+                        <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="mine-coach-male" translatesAutoresizingMaskIntoConstraints="NO" id="zc3-75-pkU">
                             <rect key="frame" x="55" y="15" width="40" height="40"/>
                             <constraints>
                                 <constraint firstAttribute="width" constant="40" id="SIN-yr-a5x"/>
                                 <constraint firstAttribute="height" constant="40" id="jBc-0J-4ER"/>
                             </constraints>
+                            <userDefinedRuntimeAttributes>
+                                <userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
+                                    <real key="value" value="20"/>
+                                </userDefinedRuntimeAttribute>
+                            </userDefinedRuntimeAttributes>
                         </imageView>
                         <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="addaddaddaddaddadd限公司addaddad9999" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VzU-VX-Ktx">
                             <rect key="frame" x="110" y="55" width="220" height="36"/>

+ 175 - 20
JiaPeiManage/Sources/Utils/NYAccountManager.swift

@@ -4,25 +4,179 @@
 //
 //  Created by Ning.ge on 2023/7/28.
 //
-
+import ObjectMapper
+import SwiftyUserDefaults
 import Foundation
+import SwiftyJSON
+
+struct AccountInfo :ImmutableMappable,Codable{
+   
+    var coachNum:String = ""
+    var recordDate:String = ""
+    var schoolId:Int = 0
+    var schoolName = ""
+    var name:String  = ""
+    var sex:String  = ""
+    var idcard:String  = ""
+    var mobile:String  = ""
+    var address:String  = ""
+    var photo:Int  = 0
+    var fingerPrint:String  = ""
+    var drilicence:Int  = 0
+    var expireTime:String  = ""
+    var fstdrilicDate:String  = ""
+    var occupationNo:String  = ""
+    var occupationLevel:String  = ""
+    var dripermitted:String  = ""
+    var hireDate:String  = ""
+    var leaveDate:String  = ""
+    var createDate:String  = ""
+    var createUser:Int  = 0
+    var createUserName:String  = ""
+    var photoPath:String  = ""
+    var updateDate:String  = ""
+    var updateUser:Int  = 0
+    var updateUserName:String  = ""
+    var cardType:String  = ""
+    var cardId:String  = ""
+    var logout:String  = ""
+    var sync:String  = ""
+    var syncTime:String  = ""
+    var groupId:String  = ""
+    var lockStatus:String  = ""
+    var protocolPath:String  = ""
+    var auditStatus:String  = ""
+    var type:String  = ""
+    var isIllegal:String  = ""
+    var healthState:String  = ""
+    var origo:String  = ""
+    var educationLevel:String  = ""
+    var isAgree:Int  = 0
+    var classType:Int  = 0
+    var dqbh:String  = ""
+    var password:String = ""
+    var city:String = ""
+    var cityPower:String = ""
+    
+    // Implement the encode(to:) method to specify how the object should be encoded
+    func encode(to encoder: Encoder) throws {
+        var container = encoder.container(keyedBy: CodingKeys.self)
+        try container.encode(idcard, forKey: .idcard)
+        try container.encode(password, forKey: .password)
+        try container.encode(name, forKey: .name)
+        try container.encode(sex, forKey: .sex)
+        try container.encode(photoPath, forKey: .photoPath)
+        try container.encode(address, forKey: .address)
+        try container.encode(city, forKey: .city)
+        try container.encode(cityPower, forKey: .cityPower)
+        try container.encode(dqbh, forKey: .dqbh)
+    }
 
-struct Account {
-    let username: String
-    let password: String
+    enum CodingKeys: String, CodingKey {
+        case idcard
+        case password
+        case name
+        case sex
+        case photoPath
+        case address
+        case city
+        case cityPower
+        case dqbh
+    }
+    
+    init(from decoder: Decoder) throws {
+        let container = try decoder.container(keyedBy: CodingKeys.self)
+        idcard = try container.decode(String.self, forKey: .idcard)
+        password = try container.decode(String.self, forKey: .password)
+        name = try container.decode(String.self, forKey: .name)
+        sex = try container.decode(String.self, forKey: .sex)
+        photoPath = try container.decode(String.self, forKey: .photoPath)
+        address = try container.decode(String.self, forKey: .address)
+        city = try container.decode(String.self, forKey: .city)
+        cityPower = try container.decode(String.self, forKey: .cityPower)
+        dqbh = try container.decode(String.self, forKey: .dqbh)
+    }
+    
+    init(){}
+    init(map: Map) throws {
+        
+        coachNum = try map.value("coachNum") ?? ""
+        recordDate = try map.value("recordDate") ?? ""
+        schoolId = try map.value("schoolId") ?? 0
+        schoolName = try map.value("schoolName") ?? ""
+        name = try map.value("name") ?? ""
+        sex = try map.value("sex") ?? ""
+        idcard = try map.value("idcard") ?? ""
+        mobile = try map.value("mobile") ?? ""
+        address = try map.value("address") ?? ""
+        photo = try map.value("photo") ?? 0
+        fingerPrint = try map.value("fingerPrint") ?? ""
+        drilicence = try map.value("drilicence") ?? 0
+        expireTime = try map.value("expireTime") ?? ""
+        fstdrilicDate = try map.value("fstdrilicDate") ?? ""
+        occupationNo = try map.value("occupationNo") ?? ""
+        occupationLevel = try map.value("occupationLevel") ?? ""
+        dripermitted = try map.value("dripermitted") ?? ""
+        hireDate = try map.value("hireDate") ?? ""
+        leaveDate = try map.value("leaveDate") ?? ""
+        createDate = try map.value("createDate") ?? ""
+        createUser = try map.value("createUser") ?? 0
+        createUserName = try map.value("createUserName") ?? ""
+        photoPath = try map.value("photoPath") ?? ""
+        updateDate = try map.value("updateDate") ?? ""
+        updateUser = try map.value("updateUser") ?? 0
+        updateUserName = try map.value("updateUserName") ?? ""
+        cardType = try map.value("cardType") ?? ""
+        cardId = try map.value("cardId") ?? ""
+        logout = try map.value("logout") ?? ""
+        sync = try map.value("sync") ?? ""
+        syncTime = try map.value("syncTime") ?? ""
+        groupId = try map.value("groupId") ?? ""
+        lockStatus = try map.value("lockStatus") ?? ""
+        protocolPath = try map.value("protocolPath") ?? ""
+        auditStatus = try map.value("auditStatus") ?? ""
+        type = try map.value("type") ?? ""
+        isIllegal = try map.value("isIllegal") ?? ""
+        healthState = try map.value("healthState") ?? ""
+        origo = try map.value("origo") ?? ""
+        educationLevel = try map.value("educationLevel") ?? ""
+        isAgree = try map.value("isAgree") ?? 0
+        classType = try map.value("classType") ?? 0
+        dqbh = try map.value("dqbh") ?? ""
+        password = try map.value("password") ?? ""
+    }
 }
 
 class NYAccountManager {
-    private var accounts: [Account] = []
+    private var accounts: [AccountInfo] = []
     private let maxAccountCount = 5
     
-    func addAccount(username: String, password: String) {
-        let account = Account(username: username, password: password)
+    func addUserinfo(user : UserInfo) {
+        let encoder = JSONEncoder()
+        encoder.outputFormatting = .prettyPrinted // Optional: To get pretty-printed JSON
+        let jsonData = try? encoder.encode(user)
+        // Convert JSON data to a JSON string
+        let json = try? JSON(data:jsonData!)
+        if var accountInfo = Mapper<AccountInfo>().map(JSON: (json?.dictionaryObject)!) {
+            accountInfo.password = user.password!
+            accountInfo.cityPower = LocalManager.userInfo.cityPower!
+            addAccount(user: accountInfo)//添加用户信息
+        }
+    }
+    
+    func addAccount(user : AccountInfo) {
+        if accounts.count>0 {
+            for (index, userInfo) in accounts.enumerated() {
+                if userInfo.idcard == user.idcard {
+                    return
+                }
+            }
+        }
         if accounts.count < maxAccountCount {
-            accounts.append(account)
+            accounts.append(user)
         } else {
             accounts.removeFirst()
-            accounts.append(account)
+            accounts.append(user)
         }
         saveAccounts()
     }
@@ -35,28 +189,29 @@ class NYAccountManager {
         saveAccounts()
     }
     
-    func getAccounts() -> [Account] {
+    func getAccounts() -> [AccountInfo] {
         return accounts
     }
     
     private func saveAccounts() {
         // Convert the accounts array to a JSON representation and save it to UserDefaults or any other persistent storage of your choice
         let jsonEncoder = JSONEncoder()
-//        if let data = try? jsonEncoder.encode(accounts) {
-//            UserDefaults.standard.set(data, forKey: "savedAccounts")
-//        }
+        if let data = try? jsonEncoder.encode(accounts) {
+            UserDefaults.standard.set(data, forKey: "savedAccounts")
+        }
     }
     
     private func loadAccounts() {
         // Load the accounts from UserDefaults or any other persistent storage
-//        if let data = UserDefaults.standard.data(forKey: "savedAccounts") {
-//            let jsonDecoder = JSONDecoder()
-//            if let savedAccounts = try? jsonDecoder.decode([Account].self, from: data) {
-//                accounts = savedAccounts
-//            }
-//        }
+        if let data = UserDefaults.standard.data(forKey: "savedAccounts") {
+            let jsonDecoder = JSONDecoder()
+            if let savedAccounts = try? jsonDecoder.decode([AccountInfo].self, from: data) {
+                accounts = savedAccounts
+            }
+        }
     }
-    
+    // 静态属性,用于存储单例实例
+    static let shared = NYAccountManager()
     init() {
         loadAccounts()
     }