123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- //
- // KMUserInfoVCModel.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2024/10/31.
- //
- import Foundation
- import Combine
- @objc enum KMUserState : Int {
- case unPay_UnTrial = 0 // 未付费且未试用
- case permanentAccount // 永久账户用户
- case unAutomatic_RemainValid// 取消自动续费,但仍在有效期内
- case expired // 已到期用户
- }
- typealias UserInfoComplete = (_ success: Bool,_ msg: String) -> Void
- class KMUserInfoVCModel: ObservableObject {
-
- /**
- @abstract 刷新个人权益
- @param
- */
- func refreshUserInfo(_ complete: @escaping UserInfoComplete) -> Void {
- KMMemberCenterManager.manager.userInfo { success, result in
- guard let result = result else { return }
- let resultDict = result as KMMemberCenterResult
- let msg = resultDict.msg
- if success {
- let userInfo = resultDict.userInfo
- guard let userInfo = resultDict.userInfo else { return }
- KMMemberInfo.shared.memberUserInfo(model: userInfo)
- complete(true, "")
- } else {
- complete(false, "")
- }
- }
- }
-
- /**
- @abstract 刷新用户状态 0(未付费且未试用)、1(永久账户用户)、2(取消自动续费,但仍在有效期内)、3(已到期用户)
- @param
- */
- func refreshUserState() -> KMUserState {
-
- return .unPay_UnTrial
- }
-
- /**
- @abstract 根据用户支持的平台返回外部视图需要的平台图片数组
- @param
- */
- func getPlatformsImages() -> [NSImage] {
- var images: [NSImage] = []
- for platform in userPlatforms() {
- if refreshUserState() == .permanentAccount ||
- refreshUserState() == .unAutomatic_RemainValid {
- if platform == "mac" {
- images.append(NSImage(named: "MacOSPlatformImage2")!)
- } else if platform == "ios" {
- images.append(NSImage(named: "iOSPlatformImage2")!)
- } else if platform == "windows" {
- images.append(NSImage(named: "WindowsPlatformImage2")!)
- } else if platform == "android" {
- images.append(NSImage(named: "AndroidPlatformImage2")!)
- }
- } else {
- if platform == "mac" {
- images.append(NSImage(named: "MacOSPlatformImage")!)
- } else if platform == "ios" {
- images.append(NSImage(named: "iOSPlatformImage")!)
- } else if platform == "windows" {
- images.append(NSImage(named: "WindowsPlatformImage")!)
- } else if platform == "android" {
- images.append(NSImage(named: "AndroidPlatformImage")!)
- }
- }
- }
- return images
- }
-
- /**
- @abstract 跳转官网用户中心;1、官网未登录,则跳转到登录页面;2、官网已登录,则跳转到官网-个人中心;
- */
- func skipAccountCenter() -> Void {
-
- }
-
- /**
- @abstract 退出登录;
- */
- func signOutAction() -> Void {
- NotificationCenter.default.post(name: NSNotification.Name("CloseMenuNotification"), object: nil)
- KMMemberPromptWC.shared.tipType = .logout
- KMMemberPromptWC.shared.showWindow(nil)
- }
-
- /**
- @abstract 注销账户;
- */
- func closeAccountAction() -> Void {
- if KMMemberInfo.shared.vip_status == 1 {
- NotificationCenter.default.post(name: NSNotification.Name("CloseMenuNotification"), object: nil)
- KMMemberPromptWC.shared.tipType = .unsubscribe
- KMMemberPromptWC.shared.showWindow(nil)
- } else {
- NotificationCenter.default.post(name: NSNotification.Name("CloseMenuNotification"), object: nil)
- KMMemberPromptWC.shared.tipType = .signout
- KMMemberPromptWC.shared.showWindow(nil)
- }
- }
-
- /**
- @abstract 展开个人中心;
- */
- func expandPersonalCenter() -> Void {
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "ExpandPersonalCenter"), object: nil)
- }
-
- /**
- @abstract 确认退出;
- */
- func confirmExitAction() -> Void {
- KMMemberCenterManager.manager.userLogout { success, result in
- guard let result = result else { return }
- let resultDict = result as KMMemberCenterResult
- let msg = resultDict.msg
- if success {
- let islogout: Bool = resultDict.result!
- if islogout {
- KMMemberInfo.shared.isLogin = false
- KMMemberInfo.shared.access_token = ""
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "MemberCenterLogoutSuccess"), object: nil)
- }
- } else {
- print(msg as Any)
- }
- }
- }
-
- /**
- @abstract 注销账户 警告弹窗;
- */
- func closeAccountWarningWC() -> Void {
- KMCloseAccountWC.shared.showWindow(nil)
- }
-
- /**
- @abstract 删除我的账户 弹窗;
- */
- func deleteAccountWC() -> Void {
- KMCloseVerificationWC.shared.showWindow(nil)
- }
-
- /**
- @abstract 注销账户申请 弹窗;
- */
- func closeAccountApplyWC(code: String) -> Void {
- KMMemberCenterManager.manager.userLogOffForUser(code: code) { success, result in
- guard let result = result else { return }
- let resultDict = result as KMMemberCenterResult
- let msg = resultDict.msg
- if success {
- let logOff: KMMemberLogOff = resultDict.logOff!
- if let token = logOff.currentTime { KMCloseApplyWC.shared.currentTime = token }
- if let token = logOff.logOffTime { KMCloseApplyWC.shared.logOffTime = token }
- KMCloseApplyWC.shared.showWindow(nil)
- } else {
- print(msg as Any)
- }
- }
- }
-
- // MARK: Private Method
-
- /**
- @abstract 获取用户支持的最大设备数
- @param
- */
- private func maxDeviceNum() -> Int {
-
- return 4
- // return 0
- }
-
- /**
- @abstract 用户支持的平台
- @param
- */
- private func userPlatforms() -> [String] {
- let platforms = "android, ios, mac, windows"
- let platformsArray = platforms
- .components(separatedBy: ",")
- .map { $0.trimmingCharacters(in: .whitespaces) }
- return platformsArray
- }
- }
|