Bladeren bron

【编辑工具】压缩设置界面PPI参数设置限制逻辑添加

lizhe 2 dagen geleden
bovenliggende
commit
e5e1eb0d75

+ 52 - 27
PDF Office/PDF Master/Class/Batch/WindowController/VC/Compress/SettingView/View/KMCompressImagesPanelTableCellView.swift

@@ -12,10 +12,8 @@ class KMCompressImagesPanelTableCellView: KMBaseCompressTableCellView, NibLoadab
     @IBOutlet weak var imagePPITextField: NSTextField!
     @IBOutlet weak var imageAbovePPITextField: NSTextField!
     @IBOutlet weak var comboBox: NSComboBox!
-    
-    // 允许输入的数字范围
-    let minValue = 10
-    let maxValue = 100
+    @IBOutlet weak var imagePPIAlertLabel: NSTextField!
+    @IBOutlet weak var imageAbovePPIAlertLabel: NSTextField!
     
     override var model: KMCompressSettingModel? {
         didSet {
@@ -43,20 +41,19 @@ class KMCompressImagesPanelTableCellView: KMBaseCompressTableCellView, NibLoadab
         // 设置 NumberFormatter
         var formatter = NumberFormatter()
         formatter.numberStyle = .decimal
-//        formatter.minimum = 10 // 设置最小值(可选)
-//        formatter.maximum = 24000 // 设置最大值(可选)
-
-//        let formatter = TextFieldFormatter.init()
-//        formatter.allowedCharacterSet = "-"
-//        self.angleTextF.formatter = formatter
-        
         imagePPITextField.formatter = formatter
         
         formatter = NumberFormatter()
         formatter.numberStyle = .decimal
-//        formatter.minimum = 10 // 设置最小值(可选)
-//        formatter.maximum = 24000 // 设置最大值(可选)
         imageAbovePPITextField.formatter = formatter
+        
+        self.imagePPIAlertLabel.textColor = NSColor(hex: "#E73861");
+        self.imageAbovePPIAlertLabel.textColor = NSColor(hex: "#E73861");
+        
+        self.comboBox.backgroundColor(NSColor(hex: "#6E6D70"))
+        
+        self.hiddenPPIAlert()
+        self.hiddenAbovePPIAlert()
     }
     
     override func reloadData() {
@@ -74,9 +71,13 @@ extension KMCompressImagesPanelTableCellView {
 
         // 仅保留数字字符
         let filtered = textField.stringValue.filter { $0.isNumber }
-//        if textField.stringValue != filtered {
-            textField.stringValue = filtered
-//        }
+        textField.stringValue = filtered
+        
+        if textField == imagePPITextField {
+            self.hiddenPPIAlert()
+        } else if textField == imageAbovePPITextField {
+            self.hiddenAbovePPIAlert()
+        }
     }
 
     // 检查输入范围并提示
@@ -85,19 +86,43 @@ extension KMCompressImagesPanelTableCellView {
               let value = Int(textField.stringValue) else { return }
 
         // 检查是否超出范围
-        if value < minValue || value > maxValue {
-            showAlert(message: "请输入范围 \(minValue) 到 \(maxValue) 的数字")
-            textField.stringValue = "" // 清空无效输入
+        
+        if textField == imagePPITextField {
+            if value < 10 || value > 2400 {
+                self.showPPIAlert()
+            }
+        }
+        
+        let tempValue = Int(self.imagePPITextField.stringValue) ?? 10
+        if value < tempValue || value > tempValue * 10 {
+            self.showAbovePPIAlert()
         }
     }
+}
+
+extension KMCompressImagesPanelTableCellView {
+    func showPPIAlert() {
+        self.imagePPIAlertLabel.isHidden = false
+        self.imagePPITextField.layer?.borderColor = NSColor(hex: "#E73861").cgColor;
+        self.imagePPITextField.backgroundColor(NSColor(hex: "#393C3E"))
+    }
+    
+    func hiddenPPIAlert() {
+        self.imagePPIAlertLabel.isHidden = true
+        self.imagePPITextField.layer?.borderColor = NSColor(hex: "#FFFFFF").withAlphaComponent(0.08).cgColor;
+        self.imagePPITextField.backgroundColor(NSColor(hex: "#6E6D70"))
 
-    // 显示警告提示
-    private func showAlert(message: String) {
-        let alert = NSAlert()
-        alert.messageText = "输入无效"
-        alert.informativeText = message
-        alert.alertStyle = .warning
-        alert.addButton(withTitle: "确定")
-        alert.runModal()
+    }
+    
+    func showAbovePPIAlert() {
+        self.imageAbovePPIAlertLabel.isHidden = false
+        self.imageAbovePPITextField.layer?.borderColor = NSColor(hex: "#E73861").cgColor;
+        self.imageAbovePPITextField.backgroundColor(NSColor(hex: "#393C3E"))
+    }
+    
+    func hiddenAbovePPIAlert() {
+        self.imageAbovePPIAlertLabel.isHidden = true
+        self.imageAbovePPITextField.layer?.borderColor = NSColor(hex: "#FFFFFF").withAlphaComponent(0.08).cgColor;
+        self.imageAbovePPITextField.backgroundColor(NSColor(hex: "#6E6D70"))
     }
 }