瀏覽代碼

Merge branch 'develop' of git.kdan.cc:Mac_PDF/PDF_Office into develop

tangchao 1 年之前
父節點
當前提交
224b7d64aa

+ 4 - 0
PDF Office/PDF Office/Class/Home/Category/String+KMExtensions.swift

@@ -32,6 +32,10 @@ extension String {
         return fileURL.deletingPathExtension().path
     }
     
+    var deletingLastPathComponent: String {
+        return fileURL.deletingLastPathComponent().path
+    }
+    
     func stringByAppendingPathExtension(_ pathExtension: String) -> String {
         return fileURL.appendingPathExtension(pathExtension).path
     }

+ 34 - 19
PDF Office/PDF Office/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -192,7 +192,7 @@ extension KMHomeViewController {
                                 (type == "pict") ||
                                 (type == "sgi") ||
                                 (type == "heic") {
-                        imageUrl.append(url)
+                        openImageFile(url: url)
                     } else if (type == "doc") ||
                                 (type == "docx") ||
                                 (type == "xls") ||
@@ -203,12 +203,6 @@ extension KMHomeViewController {
                         self.openOfficeFile(url: url)
                     }
                 }
-                if imageUrl.count > 0 {
-                    let imageToPDFWindow: KMImageToPDFWindowController = KMImageToPDFWindowController.init(windowNibName: "KMImageToPDFWindowController")
-                    imageToPDFWindow.showWindow(NSApp.mainWindow)
-                    imageToPDFWindow.batchPrecessingView.inputData = imageUrl
-                    imageToPDFWindow.inputType = .ImageToPDF
-                }
             }
         }
     }
@@ -406,10 +400,7 @@ extension KMHomeViewController {
                   (type == "pict") ||
                   (type == "sgi") ||
                   (type == "heic") {
-            let imageToPDFWindow: KMImageToPDFWindowController = KMImageToPDFWindowController.init(windowNibName: "KMImageToPDFWindowController")
-            imageToPDFWindow.showWindow(NSApp.mainWindow)
-            imageToPDFWindow.batchPrecessingView.inputData = [path]
-            imageToPDFWindow.inputType = .ImageToPDF
+            openImageFile(url: path)
         } else if (type == "doc") ||
                   (type == "docx") ||
                   (type == "xls") ||
@@ -420,18 +411,42 @@ extension KMHomeViewController {
             let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
             let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath())
             openOfficeFile(url: path)
-//            CPDFKit.sharedInstance().convertFilePath(path.path, toPath: savePath) { success in
-//                if success {
-//                    NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
-//
-//                    }
-//
-//                }
-//            }
         }
 
     }
     
+    func openImageFile(url: URL) -> Void {
+        let filePath = url.path
+        
+        let fileName: NSString = url.lastPathComponent as NSString
+        let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath()).deletingLastPathComponent
+
+        let imageName = NSString(string: NSString(string: filePath).lastPathComponent).deletingPathExtension
+        
+        let path = self.fetchDifferentFilePath(filePath: savePath + "/" + imageName + ".pdf")
+        let document = CPDFDocument.init()
+        var success = false
+        
+        //FIXME: 无法插入图片
+        let image = NSImage(contentsOfFile: filePath)
+        let insertPageSuccess = document?.insertPage(image!.size, withImage: filePath, at: document!.pageCount)
+        if insertPageSuccess != nil {
+            //信号量控制异步
+            let semaphore = DispatchSemaphore(value: 0)
+            DispatchQueue.global().async {
+                success = ((document?.write(toFile: path)) != nil)
+                semaphore.signal()
+            }
+            semaphore.wait()
+        } else {
+        }
+        if success {
+            NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: path), display: true) { document, documentWasAlreadyOpen, error in
+
+            }
+        }
+    }
+    
     func openOfficeFile(url: URL) -> Void {
         let filePath = url.path
         let folderPath = "convertToPDF.pdf"

+ 12 - 0
PDF Office/PDF Office/Class/Home/ViewController/KMHomeViewController.swift

@@ -380,6 +380,18 @@ import KMAdvertisement
             self.product_active_spacing.constant = 24.0
         }
     }
+    
+    func fetchDifferentFilePath(filePath: String) -> String {
+        var resultFilePath = filePath
+        var index: Int = 0
+        while (FileManager.default.fileExists(atPath: resultFilePath)) {
+            index += 1
+            let path = NSString(string: filePath).deletingPathExtension + "(" + String(index) + ")"
+            resultFilePath = NSString(string: path).appendingPathExtension(NSString(string: filePath).pathExtension)!
+        }
+        
+        return resultFilePath;
+    }
 
     // MARK: Common methods
     

+ 21 - 15
PDF Office/PDF Office/Class/KMLightMember/Controller/Login&Register/KMLoginWindowController.swift

@@ -121,7 +121,7 @@ class KMLoginWindowController: NSWindowController {
         //verificationCodeView
         //验证码界面点击取消按钮
         self.verificationCodeView.cancelAction = { [unowned self] view in
-            self.logType = .resetPassword
+            self.logType = view.inputType
         }
         
         //验证码界面点击完成按钮
@@ -137,13 +137,14 @@ class KMLoginWindowController: NSWindowController {
                         self.verificationCodeView.showAlert(result: result)
                     }
                 }
-            } else if view.inputType == .resetPassword {
-                KMRequestServerManager.manager.resetPassword(account: data.email, firstPassword: data.password, secondPassword: data.rePassword, verifyCode: data.verifyCode) {[unowned self] (success, result) in
+            } else if view.inputType == .loginInputPassword {
+                KMRequestServerManager.manager.verificationCode(account: data.email, verifyCode: data.verifyCode, verifyCodeType: .resetPassword) { success, result in
                     if success {
-                        self.model.email = data.email
-                        self.logType = .login
+                        self.resetPasswordView.model.verifyCode = data.verifyCode
+                        self.resetPasswordView.model.email = data.email
+                        self.logType = .resetPassword
                     } else {
-                        self.verificationCodeView.showAlert(result: result!)
+                        self.verificationCodeView.showAlert(result: result)
                     }
                 }
             }
@@ -202,7 +203,16 @@ class KMLoginWindowController: NSWindowController {
         
         //登录输入密码界面点击忘记密码按钮
         self.loginInputPasswordView.forgotPasswordAction = { [unowned self] (view, data) in
-            self.logType = .resetPassword
+            KMRequestServerManager.manager.getVerifyCode(verifyCodeType: .resetPassword, email: data.email) { success, result in
+                if success {
+                    self.verificationCodeView.inputType = .loginInputPassword
+                    self.verificationCodeView.model.email = data.email
+                    self.verificationCodeView.beginTimer()
+                    self.logType = .verificationCode
+                } else {
+                    self.loginInputPasswordView.showAlert(result: result)
+                }
+            }
         }
         
         //登录输入密码界面点击调整邮箱按钮
@@ -213,16 +223,12 @@ class KMLoginWindowController: NSWindowController {
         //resetPasswordView
         //重置密码界面点击完成按钮
         self.resetPasswordView.doneAction = { [unowned self] (view, data) in
-            KMRequestServerManager.manager.getVerifyCode(verifyCodeType: .resetPassword, email: data.email) { success, result in
+            KMRequestServerManager.manager.resetPassword(account: data.email, firstPassword: data.password, secondPassword: data.rePassword, verifyCode: data.verifyCode) {[unowned self] (success, result) in
                 if success {
-                    self.verificationCodeView.inputType = .resetPassword
-                    self.verificationCodeView.model.email = data.email
-                    self.verificationCodeView.model.password = data.password
-                    self.verificationCodeView.model.rePassword = data.rePassword
-                    self.verificationCodeView.beginTimer()
-                    self.logType = .verificationCode
+                    self.model.email = data.email
+                    self.logType = .login
                 } else {
-                    self.resetPasswordView.showAlert(result: result)
+                    self.verificationCodeView.showAlert(result: result!)
                 }
             }
         }

+ 2 - 0
PDF Office/PDF Office/Class/KMLightMember/Controller/Login&Register/View/KMLoginInputPasswordView.swift

@@ -52,6 +52,8 @@ class KMLoginInputPasswordView: KMBaseXibView {
         
         self.emailTextView.delegate = self
         self.emailTextView.isEditable = false
+        self.emailTextView.frame = (self.emailTextView.enclosingScrollView?.contentView.bounds)!
+        self.emailTextView.autoresizingMask = [.width, .height]
         
         self.describeLable.textColor = NSColor(hex: "#252629")
         self.describeLable.font = NSFont.SFProTextRegular(14.0)

+ 12 - 1
PDF Office/PDF Office/Class/KMLightMember/Controller/VerificationCode/View/KMLightMemberAlertView.swift

@@ -14,6 +14,7 @@ class KMLightMemberAlertView: KMBaseXibView {
     
     var result: Result = Result() {
         didSet {
+            self.alphaValue = 1.0
             self.reloadData()
         }
     }
@@ -46,9 +47,19 @@ class KMLightMemberAlertView: KMBaseXibView {
             self.contentView.isHidden = false
         }
         
-        self.titleLabel.stringValue = NSLocalizedString(KMRequestServerErrorCodeType.typeOfMessage(type: KMRequestServerErrorCodeType(rawValue: result.code)!), comment: "")
+        self.titleLabel.stringValue = NSLocalizedString(KMRequestServerErrorCodeType.typeOfMessage(type: KMRequestServerErrorCodeType(rawValue: result.code)), comment: "")
+        
+        DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { [unowned self] in
+            self.fadeOut()
+        }
     }
     
+    func fadeOut() {
+        NSAnimationContext.runAnimationGroup({ (context) in
+            context.duration = 1
+            animator().alphaValue = 0.0
+        }, completionHandler: nil)
+    }
     override func updateLanguage() {
         super.updateLanguage()
     }

+ 1 - 1
PDF Office/PDF Office/Class/KMLightMember/Controller/VerificationCode/View/KMVerificationCodeView.swift

@@ -65,7 +65,7 @@ class KMVerificationCodeView: KMBaseXibView {
             switch self.inputType {
             case .register:
                 self.verifyCodeType = .register
-            case .resetPassword:
+            case .loginInputPassword:
                 self.verifyCodeType = .resetPassword
             case .accountInfo:
                 self.verifyCodeType = .logOff

+ 12 - 7
PDF Office/PDF Office/Class/KMLightMember/Manager/KMRequestServerManager.swift

@@ -37,7 +37,7 @@ enum KMRequestServerErrorCodeType: Int, CaseIterable {
     case EXCEPTION_TIME_TRANSFER_ERROR = 326
     case EMAIL_VERIFY_CODE_KEY_ERROR2 = 700
     
-    static func typeOfMessage(type: KMRequestServerErrorCodeType) -> String{
+    static func typeOfMessage(type: KMRequestServerErrorCodeType?) -> String {
         var result: String = ""
         switch type {
         case .EXCEPTION_MSG_IMAGE_CODE_ERROR:
@@ -375,14 +375,19 @@ class KMRequestServerManager: NSObject {
                                      "type": verifyCodeType.rawValue,
                                      "appId": "16"]
 
-        KMRequestServer.requestServer.request(urlString: urlString, method: .post, params: params) { requestSerializer in
+        KMRequestServer.requestServer.request(urlString: urlString, method: .get, params: params) { requestSerializer in
             requestSerializer.setValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
         } completion: { task, responseObject, error in
-//            if (error == nil && responseObject != nil) {
-//                complete((responseObject as! NSDictionary), nil)
-//            } else {
-//                complete(nil, error!)
-//            }
+            if (error == nil && responseObject != nil) {
+                let result = self.dealData(responseObject: responseObject as! NSDictionary)
+                if result.code == 200 {
+                    complete(true, result)
+                } else {
+                    complete(false, result)
+                }
+            } else {
+                complete(false, Result(error: error as NSError?))
+            }
         }
     }
     

+ 2 - 2
PDF Office/PDF Office/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.xib

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21225" 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="21225"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>