feat(ui): 添加全局图标配置并优化弹窗图标显示
将图标加载逻辑提取到 GlobalConfig 中统一管理,并在登录失败弹窗及 Cookie更新完成弹窗中设置应用图标。同时修复了部分弹窗文本描述不一致的问题。
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.fantaibao;
|
package com.fantaibao;
|
||||||
|
|
||||||
|
import com.fantaibao.config.GlobalConfig;
|
||||||
import com.fantaibao.page.LoginView;
|
import com.fantaibao.page.LoginView;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
@@ -34,8 +35,7 @@ public class DesktopApplication extends Application {
|
|||||||
// 添加窗口关闭事件监听器
|
// 添加窗口关闭事件监听器
|
||||||
primaryStage.setOnCloseRequest(this::handleCloseEvent);
|
primaryStage.setOnCloseRequest(this::handleCloseEvent);
|
||||||
// 添加多个尺寸的图标
|
// 添加多个尺寸的图标
|
||||||
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/icon16.png")));
|
GlobalConfig.addIcon(primaryStage);
|
||||||
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("/icon32.png")));
|
|
||||||
// 直接启动登录界面
|
// 直接启动登录界面
|
||||||
new LoginView(primaryStage);
|
new LoginView(primaryStage);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
package com.fantaibao.config;
|
package com.fantaibao.config;
|
||||||
|
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import org.springframework.util.ResourceUtils;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
public class GlobalConfig {
|
public class GlobalConfig {
|
||||||
/**
|
/**
|
||||||
* 基础网络地址
|
* 基础网络地址
|
||||||
@@ -46,4 +53,23 @@ public class GlobalConfig {
|
|||||||
*/
|
*/
|
||||||
public static String dyLoginPage;
|
public static String dyLoginPage;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static final Image icon16;
|
||||||
|
public static final Image icon32;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
icon16 = new Image(new FileInputStream(ResourceUtils.getFile("classpath:icon16.png")));
|
||||||
|
icon32 = new Image(new FileInputStream(ResourceUtils.getFile("classpath:icon32.png")));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addIcon(Stage stage) {
|
||||||
|
stage.getIcons().add(GlobalConfig.icon16);
|
||||||
|
stage.getIcons().add(GlobalConfig.icon32);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ import javafx.scene.control.Label;
|
|||||||
import javafx.scene.control.PasswordField;
|
import javafx.scene.control.PasswordField;
|
||||||
import javafx.scene.control.ProgressIndicator;
|
import javafx.scene.control.ProgressIndicator;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class LoginView {
|
public class LoginView {
|
||||||
|
|
||||||
@@ -94,6 +96,12 @@ public class LoginView {
|
|||||||
alert.setTitle("登录失败");
|
alert.setTitle("登录失败");
|
||||||
alert.setHeaderText(null);
|
alert.setHeaderText(null);
|
||||||
alert.setContentText(jsonResultObject.getString("msg"));
|
alert.setContentText(jsonResultObject.getString("msg"));
|
||||||
|
// 设置弹窗图标
|
||||||
|
Stage alertStage = (Stage) alert.getDialogPane().getScene().getWindow();
|
||||||
|
InputStream iconStream = getClass().getResourceAsStream("/icon16.png");
|
||||||
|
if (iconStream != null) {
|
||||||
|
alertStage.getIcons().add(new Image(iconStream));
|
||||||
|
}
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -119,6 +127,9 @@ public class LoginView {
|
|||||||
alert.setTitle("登录失败");
|
alert.setTitle("登录失败");
|
||||||
alert.setHeaderText(null);
|
alert.setHeaderText(null);
|
||||||
alert.setContentText("登录过程中发生错误: " + ex.getMessage());
|
alert.setContentText("登录过程中发生错误: " + ex.getMessage());
|
||||||
|
// 设置弹窗图标
|
||||||
|
Stage alertStage = (Stage) alert.getDialogPane().getScene().getWindow();
|
||||||
|
GlobalConfig.addIcon(alertStage);
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.microsoft.playwright.Request;
|
|||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.ButtonType;
|
import javafx.scene.control.ButtonType;
|
||||||
|
import javafx.stage.Stage;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -60,8 +61,10 @@ public abstract class AbstractFtbCrawlNetBase {
|
|||||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
alert.setTitle("Cookie更新完成");
|
alert.setTitle("Cookie更新完成");
|
||||||
alert.setHeaderText(null);
|
alert.setHeaderText(null);
|
||||||
alert.setContentText(platformName+"Cookie已更新完成,请点击\"我已知晓\"关闭页面");
|
alert.setContentText(platformName+"Cookie已更新完成,请点击\"我已知晓\"关闭");
|
||||||
|
// 设置弹窗图标
|
||||||
|
Stage alertStage = (Stage) alert.getDialogPane().getScene().getWindow();
|
||||||
|
GlobalConfig.addIcon(alertStage);
|
||||||
// 添加自定义按钮
|
// 添加自定义按钮
|
||||||
ButtonType acknowledgeButton = new ButtonType("我已知晓");
|
ButtonType acknowledgeButton = new ButtonType("我已知晓");
|
||||||
alert.getButtonTypes().setAll(acknowledgeButton);
|
alert.getButtonTypes().setAll(acknowledgeButton);
|
||||||
|
|||||||
Reference in New Issue
Block a user