feat(register): 实现用户注册功能
- 添加注册接口地址配置 - 创建注册用户数据传输对象(LoginUserRegisterDTO) - 实现注册页面逻辑,包括表单验证和接口调用 - 集成HTTP客户端发送注册请求 - 添加注册成功和失败的提示弹窗 - 优化注册表单字段验证逻辑
This commit is contained in:
@@ -15,6 +15,11 @@ public class GlobalConfig {
|
||||
*/
|
||||
public static final String loginInterfaceAddress = BASE_NET_URL+"/user/login";
|
||||
|
||||
/**
|
||||
* 注册接口地址
|
||||
*/
|
||||
public static final String registerInterfaceAddress = BASE_NET_URL+"/user/register";
|
||||
|
||||
/**
|
||||
* 更新cookie地址
|
||||
*/
|
||||
|
||||
23
src/main/java/com/fantaibao/model/LoginUserRegisterDTO.java
Normal file
23
src/main/java/com/fantaibao/model/LoginUserRegisterDTO.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.fantaibao.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LoginUserRegisterDTO {
|
||||
|
||||
/**
|
||||
* 账号
|
||||
*/
|
||||
private String account;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/** 租户id */
|
||||
private String tenantId;
|
||||
|
||||
/** 租户名称 */
|
||||
private String tenantName;
|
||||
|
||||
}
|
||||
@@ -1,13 +1,21 @@
|
||||
package com.fantaibao.page;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fantaibao.config.GlobalConfig;
|
||||
import com.fantaibao.model.LoginUserRegisterDTO;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class RegisterView {
|
||||
|
||||
public RegisterView(Stage primaryStage) {
|
||||
@@ -75,7 +83,7 @@ public class RegisterView {
|
||||
String password = passwordField.getText();
|
||||
|
||||
// 基本验证
|
||||
if (tenantName.isEmpty() || tenantId.isEmpty() || account.isEmpty() || password.isEmpty()) {
|
||||
if (tenantName.isEmpty() || account.isEmpty() || password.isEmpty()) {
|
||||
showAlert(Alert.AlertType.WARNING, "注册失败", "请填写所有字段");
|
||||
return;
|
||||
}
|
||||
@@ -88,7 +96,14 @@ public class RegisterView {
|
||||
try {
|
||||
// 这里应该调用实际的注册接口,目前我们模拟注册成功
|
||||
Thread.sleep(1000); // 模拟网络请求
|
||||
|
||||
LoginUserRegisterDTO loginUserRegisterDTO = new LoginUserRegisterDTO();
|
||||
loginUserRegisterDTO.setAccount(account);
|
||||
loginUserRegisterDTO.setPassword(password);
|
||||
loginUserRegisterDTO.setTenantId(tenantId);
|
||||
loginUserRegisterDTO.setTenantName(tenantName);
|
||||
String result = HttpUtil.post(GlobalConfig.registerInterfaceAddress, JSON.toJSONString(loginUserRegisterDTO));
|
||||
// 解析返回结果
|
||||
JSONObject jsonResultObject = JSON.parseObject(result);
|
||||
// 在JavaFX主线程中更新UI
|
||||
Platform.runLater(() -> {
|
||||
// 隐藏加载指示器,启用注册按钮
|
||||
@@ -96,6 +111,21 @@ public class RegisterView {
|
||||
registerButton.setDisable(false);
|
||||
registerButton.setText("注 册");
|
||||
|
||||
if (jsonResultObject.getInteger("code") != 200) {
|
||||
// 显示错误提示弹窗
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setTitle("注册失败");
|
||||
alert.setHeaderText(null);
|
||||
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();
|
||||
return;
|
||||
}
|
||||
// 显示成功提示弹窗
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
alert.setTitle("注册成功");
|
||||
|
||||
Reference in New Issue
Block a user