feat(ui): 添加数据抓取配置界面
- 新增 DataCrawlView 类用于数据抓取配置 - 实现平台选择下拉框(美团、大众点评) - 添加日期选择器用于设置抓取时间范围 - 创建开始抓取按钮并绑定点击事件 - 实现表单验证和用户提示功能 - 修改平台选择页面,新增美团数据抓取选项 - 调整原有平台选项的按钮文字和逻辑
This commit is contained in:
151
src/main/java/com/fantaibao/page/DataCrawlView.java
Normal file
151
src/main/java/com/fantaibao/page/DataCrawlView.java
Normal file
@@ -0,0 +1,151 @@
|
||||
package com.fantaibao.page;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class DataCrawlView {
|
||||
|
||||
private ComboBox<String> platformComboBox;
|
||||
private DatePicker startDatePicker;
|
||||
private DatePicker endDatePicker;
|
||||
private Button crawlButton;
|
||||
|
||||
public DataCrawlView(Stage primaryStage) {
|
||||
initialize(primaryStage);
|
||||
}
|
||||
|
||||
private void initialize(Stage primaryStage) {
|
||||
// 设置窗口标题
|
||||
primaryStage.setTitle("数据抓取配置");
|
||||
|
||||
// 创建主容器
|
||||
VBox root = new VBox();
|
||||
root.setAlignment(Pos.CENTER);
|
||||
root.setSpacing(20);
|
||||
root.setPadding(new Insets(30));
|
||||
root.setStyle("-fx-background-color: #f5f5f5;");
|
||||
|
||||
// 标题
|
||||
Label titleLabel = new Label("数据抓取配置");
|
||||
titleLabel.setStyle("-fx-font-size: 24px; -fx-font-weight: bold; -fx-text-fill: #333333;");
|
||||
|
||||
// 创建表单容器
|
||||
GridPane formPane = new GridPane();
|
||||
formPane.setAlignment(Pos.CENTER);
|
||||
formPane.setHgap(15);
|
||||
formPane.setVgap(20);
|
||||
formPane.setPadding(new Insets(20));
|
||||
formPane.setStyle("-fx-background-color: white; -fx-border-radius: 10px; -fx-background-radius: 10px; " +
|
||||
"-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.1), 10, 0, 0, 0);");
|
||||
|
||||
// 平台选择
|
||||
Label platformLabel = new Label("选择平台:");
|
||||
platformLabel.setStyle("-fx-font-size: 14px; -fx-text-fill: #333333;");
|
||||
|
||||
platformComboBox = new ComboBox<>();
|
||||
platformComboBox.getItems().addAll("美团", "大众点评");
|
||||
platformComboBox.setValue("美团");
|
||||
platformComboBox.setPrefWidth(200);
|
||||
platformComboBox.setStyle("-fx-font-size: 14px;");
|
||||
|
||||
// 开始时间选择
|
||||
Label startDateLabel = new Label("开始时间:");
|
||||
startDateLabel.setStyle("-fx-font-size: 14px; -fx-text-fill: #333333;");
|
||||
|
||||
startDatePicker = new DatePicker();
|
||||
startDatePicker.setValue(LocalDate.now().minusDays(7)); // 默认一周前
|
||||
startDatePicker.setPrefWidth(200);
|
||||
startDatePicker.setStyle("-fx-font-size: 14px;");
|
||||
|
||||
// 结束时间选择
|
||||
Label endDateLabel = new Label("结束时间:");
|
||||
endDateLabel.setStyle("-fx-font-size: 14px; -fx-text-fill: #333333;");
|
||||
|
||||
endDatePicker = new DatePicker();
|
||||
endDatePicker.setValue(LocalDate.now()); // 默认今天
|
||||
endDatePicker.setPrefWidth(200);
|
||||
endDatePicker.setStyle("-fx-font-size: 14px;");
|
||||
|
||||
// 添加到表单
|
||||
formPane.add(platformLabel, 0, 0);
|
||||
formPane.add(platformComboBox, 1, 0);
|
||||
formPane.add(startDateLabel, 0, 1);
|
||||
formPane.add(startDatePicker, 1, 1);
|
||||
formPane.add(endDateLabel, 0, 2);
|
||||
formPane.add(endDatePicker, 1, 2);
|
||||
|
||||
// 开始抓取按钮
|
||||
crawlButton = new Button("开始抓取");
|
||||
crawlButton.setStyle("-fx-background-color: #4CAF50; -fx-text-fill: white; " +
|
||||
"-fx-font-size: 16px; -fx-font-weight: bold; -fx-padding: 12px 36px; " +
|
||||
"-fx-border-radius: 30px; -fx-background-radius: 30px; " +
|
||||
"-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 10, 0, 0, 0);");
|
||||
crawlButton.setCursor(javafx.scene.Cursor.HAND);
|
||||
crawlButton.setOnMouseEntered(e -> crawlButton.setStyle("-fx-background-color: #45a049; " +
|
||||
"-fx-text-fill: white; -fx-font-size: 16px; -fx-font-weight: bold; " +
|
||||
"-fx-padding: 12px 36px; -fx-border-radius: 30px; -fx-background-radius: 30px; " +
|
||||
"-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 15, 0, 0, 0);"));
|
||||
crawlButton.setOnMouseExited(e -> crawlButton.setStyle("-fx-background-color: #4CAF50; " +
|
||||
"-fx-text-fill: white; -fx-font-size: 16px; -fx-font-weight: bold; " +
|
||||
"-fx-padding: 12px 36px; -fx-border-radius: 30px; -fx-background-radius: 30px; " +
|
||||
"-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 10, 0, 0, 0);"));
|
||||
|
||||
// 为按钮添加点击事件
|
||||
crawlButton.setOnAction(e -> handleCrawlAction());
|
||||
|
||||
// 将组件添加到主容器
|
||||
root.getChildren().addAll(titleLabel, formPane, crawlButton);
|
||||
|
||||
// 设置场景并显示窗口
|
||||
Scene scene = new Scene(root, 500, 450);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
private void handleCrawlAction() {
|
||||
// 获取选择的平台值
|
||||
String selectedPlatform = platformComboBox.getValue();
|
||||
int platformValue = 0; // 默认美团
|
||||
|
||||
if ("大众点评".equals(selectedPlatform)) {
|
||||
platformValue = 5;
|
||||
}
|
||||
|
||||
LocalDate startDate = startDatePicker.getValue();
|
||||
LocalDate endDate = endDatePicker.getValue();
|
||||
|
||||
// 验证日期
|
||||
if (startDate == null || endDate == null) {
|
||||
showAlert(Alert.AlertType.WARNING, "警告", "请选择完整的日期范围");
|
||||
return;
|
||||
}
|
||||
|
||||
if (startDate.isAfter(endDate)) {
|
||||
showAlert(Alert.AlertType.WARNING, "警告", "开始时间不能晚于结束时间");
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示成功提示
|
||||
showAlert(Alert.AlertType.INFORMATION, "抓取成功",
|
||||
"平台: " + selectedPlatform + "\n" +
|
||||
"平台值: " + platformValue + "\n" +
|
||||
"开始时间: " + startDate + "\n" +
|
||||
"结束时间: " + endDate + "\n" +
|
||||
"数据抓取任务已启动!");
|
||||
}
|
||||
|
||||
private void showAlert(Alert.AlertType alertType, String title, String content) {
|
||||
Alert alert = new Alert(alertType);
|
||||
alert.setTitle(title);
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText(content);
|
||||
alert.showAndWait();
|
||||
}
|
||||
}
|
||||
@@ -62,14 +62,14 @@ public class PlatformSelectionView {
|
||||
"#FFD700","ftbCrawlNetFirstMt"
|
||||
);
|
||||
|
||||
// 抖音来客选项
|
||||
VBox douyinOption = createPlatformDyOption(
|
||||
"抖音来客",
|
||||
GlobalConfig.dyLogo,
|
||||
"#4A90E2"
|
||||
// 美团数据抓取选项
|
||||
VBox meituanCrawlOption = createPlatformMtCrawlOption(
|
||||
"美团数据抓取",
|
||||
GlobalConfig.mtLogo,
|
||||
"#FF6B35"
|
||||
);
|
||||
|
||||
platformOptions.getChildren().addAll(meituanOption,meituanFirstOption, douyinOption);
|
||||
platformOptions.getChildren().addAll(meituanOption, meituanFirstOption, meituanCrawlOption);
|
||||
|
||||
// 添加组件到主容器
|
||||
root.getChildren().addAll(titleLabel, infoLabel, platformOptions);
|
||||
@@ -110,8 +110,8 @@ public class PlatformSelectionView {
|
||||
|
||||
return option;
|
||||
}
|
||||
|
||||
private VBox createPlatformDyOption(String title, Image imageUrl, String buttonColor) {
|
||||
|
||||
private VBox createPlatformMtCrawlOption(String title, Image imageUrl, String buttonColor) {
|
||||
VBox option = new VBox();
|
||||
option.setAlignment(Pos.CENTER);
|
||||
option.setSpacing(10);
|
||||
@@ -125,16 +125,12 @@ public class PlatformSelectionView {
|
||||
Label titleLabel = new Label(title);
|
||||
titleLabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
|
||||
|
||||
Button connectButton = new Button("立即连接");
|
||||
Button connectButton = new Button("立即进入");
|
||||
connectButton.setCursor(javafx.scene.Cursor.HAND);
|
||||
connectButton.setStyle("-fx-background-color: " + buttonColor + "; -fx-text-fill: white; -fx-padding: 10px 20px; -fx-border-radius: 4px;");
|
||||
|
||||
connectButton.setOnAction(event -> {
|
||||
FtbCrawlNetBase ftbCrawlNetMt = SpringContext.getBean("ftbCrawlNetDy");
|
||||
ThreadPoolTaskExecutor poolTaskExecutor = SpringContext.getBean(ThreadPoolTaskExecutor.class);
|
||||
poolTaskExecutor.execute(() -> {
|
||||
ftbCrawlNetMt.executeCookieIntercept();
|
||||
});
|
||||
new DataCrawlView(primaryStage);
|
||||
});
|
||||
|
||||
option.getChildren().addAll(imageView, titleLabel, connectButton);
|
||||
|
||||
Reference in New Issue
Block a user