Browse Source

【fix】【登录界面 】未点击协议的确认弹窗参考高保真

tangchao 4 months ago
parent
commit
7885ffe5f8

+ 14 - 0
PDF Office/PDF Master/Class/Batch/WindowController/VC/KMToolbarItemPopViewController.swift

@@ -10,6 +10,20 @@ import Cocoa
 class KMToolbarItemPopViewController: NSViewController{
     @IBOutlet var toolbarHelpTipLabel: NSTextField!
     
+    @IBOutlet weak var topConst: NSLayoutConstraint!
+    @IBOutlet weak var leftConst: NSLayoutConstraint!
+    @IBOutlet weak var rightConst: NSLayoutConstraint!
+    @IBOutlet weak var bottomConst: NSLayoutConstraint!
+    
+    var contentInset: NSEdgeInsets = .init(top: 5, left: 5, bottom: 5, right: 5) {
+        didSet {
+            topConst.constant = contentInset.top
+            leftConst.constant = contentInset.left
+            rightConst.constant = contentInset.right
+            bottomConst.constant = contentInset.bottom
+        }
+    }
+    
     convenience init() {
         self.init(nibName: "KMToolbarItemPopViewController", bundle: nil)
         

+ 7 - 3
PDF Office/PDF Master/Class/Batch/WindowController/VC/KMToolbarItemPopViewController.xib

@@ -1,14 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22155" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22155"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="KMToolbarItemPopViewController" customModule="PDF_Reader_Pro" customModuleProvider="target">
             <connections>
+                <outlet property="bottomConst" destination="pgE-Je-WDF" id="nbE-mW-Vj6"/>
+                <outlet property="leftConst" destination="TC0-WL-8ct" id="1ub-0I-SsO"/>
+                <outlet property="rightConst" destination="Vvb-Qb-5dD" id="hCZ-bs-ehU"/>
                 <outlet property="toolbarHelpTipLabel" destination="Anw-6R-RbF" id="Ra3-8V-bZf"/>
+                <outlet property="topConst" destination="I9x-u0-py7" id="z4m-m7-8Sg"/>
                 <outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
             </connections>
         </customObject>
@@ -18,7 +22,7 @@
             <rect key="frame" x="0.0" y="0.0" width="10" height="24"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
-                <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Anw-6R-RbF">
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Anw-6R-RbF">
                     <rect key="frame" x="3" y="5" width="4" height="14"/>
                     <constraints>
                         <constraint firstAttribute="width" relation="lessThanOrEqual" constant="300" id="jFH-vi-FyE"/>

+ 55 - 1
PDF Office/PDF Master/MemberCenter/View/KMSignUpView.swift

@@ -42,6 +42,8 @@ class KMSignUpView: KMBaseXibView {
     private var viewModel = KMSignUpViewModel()
     private var cancellables = Set<AnyCancellable>()
     
+    private var popOver_: NSPopover?
+    
     convenience init(model: KMSignUpViewModel, superView: NSView) {
         self.init(frame: superView.bounds)
         viewModel = model
@@ -308,6 +310,39 @@ class KMSignUpView: KMBaseXibView {
         }
     }
     
+    private func _showPop() {
+        guard let _ = self.window else {
+            return
+        }
+        
+        if (self.popOver_ != nil) {
+            return
+        }
+        let popViewController = KMToolbarItemPopViewController()
+        self.popOver_ = NSPopover()
+        self.popOver_?.contentViewController = popViewController
+        self.popOver_?.animates = false
+        self.popOver_?.behavior = .semitransient
+        self.popOver_?.contentSize = popViewController.view.frame.size
+        self.popOver_?.delegate = self
+
+        // 0.8
+        var color = NSColor(hex: "#273C62").withAlphaComponent(1)
+        if KMAppearance.isDarkMode() {
+            color = NSColor(hex: "#4E7FDB").withAlphaComponent(1)
+        }
+        popViewController.view.wantsLayer = true
+        popViewController.view.layer?.backgroundColor = color.cgColor
+        self.popOver_?.setBackgroundColor(color)
+        popViewController.toolbarHelpTipLabel.textColor = .white
+        popViewController.toolbarHelpTipLabel.font = .SFProTextRegularFont(13)
+        
+        popViewController.contentInset  = .init(top: 12, left: 8, bottom: 12, right: 8)
+        
+        popViewController.updateWithHelpTip(helpTip: NSLocalizedString("Please agree and check the agreement first.", tableName: "MemberCenterLocalizable", comment: ""))
+        self.popOver_?.show(relativeTo: NSMakeRect(0, 0, 0, 12), of: privacyCheckButton, preferredEdge: .maxY)
+    }
+    
     // MARK: Bind Method
     
     func bindViewModel() -> Void {
@@ -327,6 +362,7 @@ class KMSignUpView: KMBaseXibView {
             .receive(on: RunLoop.main)
             .sink { [weak self] newValue in
                 self?.checkStateChange(button: self?.privacyCheckButton, state: newValue)
+                self?.popOver_?.close()
             }
             .store(in: &cancellables)
         viewModel.$signUpState
@@ -386,8 +422,18 @@ class KMSignUpView: KMBaseXibView {
                 }
             }
             .store(in: &cancellables)
+        
+        viewModel.$privacyPopShow
+            .receive(on: RunLoop.main)
+            .sink { [weak self] newValue in
+                if newValue {
+                    KMMainThreadExecute {
+                        self?._showPop()
+                    }
+                }
+            }
+            .store(in: &cancellables)
     }
-    
         
     // MARK: Action Method
     
@@ -501,3 +547,11 @@ extension KMSignUpView: NSTextFieldDelegate {
         resetTextFileData()
     }
 }
+
+extension KMSignUpView: NSPopoverDelegate {
+    func popoverDidClose(_ notification: Notification) {
+        if let data = self.popOver_?.isEqual(to: notification.object), data {
+            self.popOver_ = nil
+        }
+    }
+}

+ 9 - 15
PDF Office/PDF Master/MemberCenter/ViewModel/KMSignUpViewModel.swift

@@ -41,6 +41,11 @@ class KMSignUpViewModel: ObservableObject {
      是否同意隐私权限
      */
     @Published var privacyState: Bool = false
+    /**
+     隐私权限显示Pop提示
+     */
+    @Published var privacyPopShow: Bool = false
+    
     /**
      登录界面是验证码验证还是邮箱验证
      */
@@ -253,19 +258,9 @@ class KMSignUpViewModel: ObservableObject {
             code = password
         }
         if !privacyState {
-            DispatchQueue.main.async {
-                
-                let alert = NSAlert()
-                alert.messageText = NSLocalizedString("Please agree and check the agreement first.", tableName: "MemberCenterLocalizable", comment: "")
-                alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
-                //            alert.beginSheetModal(for: NSApp.mainWindow!)
-                let result = alert.runModal()
-                if (result == .alertFirstButtonReturn) {
-                    self.privacyState = true
-                }
-                
-                callback?(nil)
-            }
+            callback?(nil)
+            
+            self.privacyPopShow = true
             return
         }
         KMMemberCenterManager.manager.emailLogin(email: email, code: code, type: signUpState) { [weak self] success, wrapper  in
@@ -440,8 +435,7 @@ class KMSignUpViewModel: ObservableObject {
             if success {
                 print("验证邮箱成功")
             } else {
-                self.emailErrorMessage = NSLocalizedString("Please enter the correct email format", tableName: "MemberCenterLocalizable", comment: "")
-                
+//                self.emailErrorMessage = NSLocalizedString("Please enter the correct email format", tableName: "MemberCenterLocalizable", comment: "")
                 KMMemberCenterManager.showAlert(code: .init(rawValue: wrapper?.code ?? 0), message: wrapper?.msg, callback: nil)
             }
         }