2025年4月6日18:18:40
parent
64b2a44c41
commit
0e04d2fbfe
|
|
@ -65,7 +65,7 @@ public class ApiUtils {
|
|||
|
||||
public static DataView getUserList() {
|
||||
DataLoad dataLoad = new UserDataLoad();
|
||||
dataLoad.setForm(new UserForm(true));
|
||||
dataLoad.setForm(new UserForm());
|
||||
return dataLoad.loadData(PAGE_NUM,PAGE_SIZE);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.zhangmeng.online.exam.ui.api.form.base.Form;
|
|||
import com.zhangmeng.online.exam.ui.api.model.UserDataLoad;
|
||||
import com.zhangmeng.online.exam.ui.components.DynamicTableComponent;
|
||||
import com.zhangmeng.online.exam.ui.components.callBack.DynamicTableComponentCallBack;
|
||||
import com.zhangmeng.online.exam.ui.controller.UserEditController;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
|
|
@ -28,142 +29,25 @@ import java.util.Map;
|
|||
*/
|
||||
public class UserForm extends Form {
|
||||
|
||||
private TextField username_field;
|
||||
private PasswordField password_field;
|
||||
private TextField phone_field;
|
||||
private TextField email_field;
|
||||
private UserEditController controller;
|
||||
|
||||
private boolean isfxml = true;
|
||||
|
||||
public UserForm(boolean isfxml) {
|
||||
this.isfxml = isfxml;
|
||||
|
||||
public UserForm() {
|
||||
try {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/user-edit.fxml"));
|
||||
this.getChildren().add(fxmlLoader.load());
|
||||
this.controller = fxmlLoader.getController();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public UserForm() {
|
||||
|
||||
Label username_label = new Label("用户名:");
|
||||
username_label.setLayoutX(83.0);
|
||||
username_label.setLayoutY(64.0);
|
||||
|
||||
username_field = new TextField();
|
||||
username_field.setLayoutX(162.0);
|
||||
username_field.setLayoutY(60.0);
|
||||
username_field.setPrefHeight(23.0);
|
||||
username_field.setPrefWidth(289.0);
|
||||
username_field.setPromptText("请输入用户名");
|
||||
|
||||
password_field = new PasswordField();
|
||||
password_field.setLayoutX(162.0);
|
||||
password_field.setLayoutY(117.0);
|
||||
password_field.setPrefHeight(23.0);
|
||||
password_field.setPrefWidth(289.0);
|
||||
password_field.setPromptText("请输入密码");
|
||||
|
||||
Label password_label = new Label("密码:");
|
||||
password_label.setLayoutX(87.0);
|
||||
password_label.setLayoutY(121.0);
|
||||
|
||||
Label phone_label = new Label("手机号:");
|
||||
phone_label.setLayoutX(87.0);
|
||||
phone_label.setLayoutY(169.0);
|
||||
|
||||
phone_field = new TextField();
|
||||
phone_field.setLayoutX(162.0);
|
||||
phone_field.setLayoutY(165.0);
|
||||
phone_field.setPrefHeight(23.0);
|
||||
phone_field.setPrefWidth(289.0);
|
||||
phone_field.setPromptText("请输入手机号");
|
||||
|
||||
Label email_label = new Label("邮箱:");
|
||||
email_label.setLayoutX(87.0);
|
||||
email_label.setLayoutY(224.0);
|
||||
|
||||
email_field = new TextField();
|
||||
email_field.setLayoutX(162.0);
|
||||
email_field.setLayoutY(220.0);
|
||||
email_field.setPrefHeight(23.0);
|
||||
email_field.setPrefWidth(289.0);
|
||||
email_field.setPromptText("请输入邮箱");
|
||||
|
||||
Button submit_button = new Button("提交");
|
||||
submit_button.setLayoutX(263.0);
|
||||
submit_button.setLayoutY(288.0);
|
||||
|
||||
submit_button.setOnAction(e -> {
|
||||
|
||||
DataLoad formDataLoad = new UserDataLoad();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("username", username_field.getText());
|
||||
map.put("password", password_field.getText());
|
||||
map.put("phone", phone_field.getText());
|
||||
map.put("email", email_field.getText());
|
||||
formDataLoad.saveForm(map);
|
||||
|
||||
Stage stage = (Stage) this.getScene().getWindow();
|
||||
stage.close();
|
||||
|
||||
DynamicTableComponentCallBack callBack = getTableComponent().getCallBack();
|
||||
ObservableList<Map<String, SimpleStringProperty>> data = getTableComponent().getData();
|
||||
data.clear();
|
||||
data.addAll(callBack.flushData(1, ApiUtils.PAGE_SIZE).getDataList());
|
||||
|
||||
});
|
||||
|
||||
this.getChildren().addAll(username_label,
|
||||
username_field,
|
||||
password_field,
|
||||
phone_label,
|
||||
phone_field,
|
||||
email_label,
|
||||
email_field,
|
||||
submit_button,
|
||||
password_label);
|
||||
public UserEditController getController() {
|
||||
return controller;
|
||||
}
|
||||
|
||||
|
||||
public TextField getUsername_field() {
|
||||
return username_field;
|
||||
}
|
||||
|
||||
public void setUsername_field(TextField username_field) {
|
||||
this.username_field = username_field;
|
||||
}
|
||||
|
||||
public PasswordField getPassword_field() {
|
||||
return password_field;
|
||||
}
|
||||
|
||||
public void setPassword_field(PasswordField password_field) {
|
||||
this.password_field = password_field;
|
||||
}
|
||||
|
||||
public TextField getPhone_field() {
|
||||
return phone_field;
|
||||
}
|
||||
|
||||
public void setPhone_field(TextField phone_field) {
|
||||
this.phone_field = phone_field;
|
||||
}
|
||||
|
||||
public TextField getEmail_field() {
|
||||
return email_field;
|
||||
}
|
||||
|
||||
public void setEmail_field(TextField email_field) {
|
||||
this.email_field = email_field;
|
||||
}
|
||||
|
||||
public boolean isIsfxml() {
|
||||
return isfxml;
|
||||
}
|
||||
|
||||
public void setIsfxml(boolean isfxml) {
|
||||
this.isfxml = isfxml;
|
||||
public void setController(UserEditController controller) {
|
||||
this.controller = controller;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,22 +93,7 @@ public class AnswerDataLoad implements DataLoad {
|
|||
@Override
|
||||
public void editData(String id, Stage stage) {
|
||||
|
||||
UserForm userForm = new UserForm();
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
String result = HttpUtils.GET(ApiUtils.API_URL + "/user/getUser", map);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
String username = data.getString("username");
|
||||
userForm.getUsername_field().setText(username);
|
||||
String email = data.getString("email");
|
||||
userForm.getEmail_field().setText(email);
|
||||
String phone = data.getString("phone");
|
||||
userForm.getPhone_field().setText(phone);
|
||||
String password = data.getString("password");
|
||||
userForm.getPassword_field().setText(password);
|
||||
AlertUtils.alert("编辑用户信息", (Parent) userForm, stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -88,22 +88,7 @@ public class OptionDataLoad implements DataLoad {
|
|||
@Override
|
||||
public void editData(String id, Stage stage) {
|
||||
|
||||
UserForm userForm = new UserForm();
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
String result = HttpUtils.GET(ApiUtils.API_URL + "/user/getUser", map);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
String username = data.getString("username");
|
||||
userForm.getUsername_field().setText(username);
|
||||
String email = data.getString("email");
|
||||
userForm.getEmail_field().setText(email);
|
||||
String phone = data.getString("phone");
|
||||
userForm.getPhone_field().setText(phone);
|
||||
String password = data.getString("password");
|
||||
userForm.getPassword_field().setText(password);
|
||||
AlertUtils.alert("编辑用户信息", (Parent) userForm, stage);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -100,22 +100,7 @@ public class PaperDataLoad implements DataLoad {
|
|||
@Override
|
||||
public void editData(String id, Stage stage) {
|
||||
|
||||
UserForm userForm = new UserForm();
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
String result = HttpUtils.GET(ApiUtils.API_URL + "/user/getUser", map);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
String username = data.getString("username");
|
||||
userForm.getUsername_field().setText(username);
|
||||
String email = data.getString("email");
|
||||
userForm.getEmail_field().setText(email);
|
||||
String phone = data.getString("phone");
|
||||
userForm.getPhone_field().setText(phone);
|
||||
String password = data.getString("password");
|
||||
userForm.getPassword_field().setText(password);
|
||||
AlertUtils.alert("编辑用户信息", (Parent) userForm, stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -87,22 +87,7 @@ public class ProfessionDataLoad implements DataLoad {
|
|||
@Override
|
||||
public void editData(String id, Stage stage) {
|
||||
|
||||
UserForm userForm = new UserForm(true);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
String result = HttpUtils.GET(ApiUtils.API_URL + "/profession/getProfession", map);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
String username = data.getString("username");
|
||||
userForm.getUsername_field().setText(username);
|
||||
String email = data.getString("email");
|
||||
userForm.getEmail_field().setText(email);
|
||||
String phone = data.getString("phone");
|
||||
userForm.getPhone_field().setText(phone);
|
||||
String password = data.getString("password");
|
||||
userForm.getPassword_field().setText(password);
|
||||
AlertUtils.alert("编辑用户信息", (Parent) userForm, stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ public class QuestionDataLoad implements DataLoad {
|
|||
questionMap.put("explanation", explanation);
|
||||
controller.setQuestion(questionMap);
|
||||
|
||||
FxUtils.alert("编辑用户信息", questionForm, stage,true);
|
||||
FxUtils.alert("编辑问题", questionForm, stage,true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -89,22 +89,7 @@ public class QuestionOptionDataLoad implements DataLoad {
|
|||
@Override
|
||||
public void editData(String id, Stage stage) {
|
||||
|
||||
UserForm userForm = new UserForm();
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
String result = HttpUtils.GET(ApiUtils.API_URL + "/user/getUser", map);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
String username = data.getString("username");
|
||||
userForm.getUsername_field().setText(username);
|
||||
String email = data.getString("email");
|
||||
userForm.getEmail_field().setText(email);
|
||||
String phone = data.getString("phone");
|
||||
userForm.getPhone_field().setText(phone);
|
||||
String password = data.getString("password");
|
||||
userForm.getPassword_field().setText(password);
|
||||
AlertUtils.alert("编辑用户信息", (Parent) userForm, stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -88,22 +88,7 @@ public class SubjectDataLoad implements DataLoad {
|
|||
@Override
|
||||
public void editData(String id,Stage stage) {
|
||||
|
||||
UserForm userForm = new UserForm();
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
String result = HttpUtils.GET(ApiUtils.API_URL + "/subject/getUser", map);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
String username = data.getString("username");
|
||||
userForm.getUsername_field().setText(username);
|
||||
String email = data.getString("email");
|
||||
userForm.getEmail_field().setText(email);
|
||||
String phone = data.getString("phone");
|
||||
userForm.getPhone_field().setText(phone);
|
||||
String password = data.getString("password");
|
||||
userForm.getPassword_field().setText(password);
|
||||
AlertUtils.alert("编辑用户信息", (Parent) userForm, stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONArray;
|
|||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.zhangmeng.online.exam.ui.api.DataLoad;
|
||||
import com.zhangmeng.online.exam.ui.api.form.UserForm;
|
||||
import com.zhangmeng.online.exam.ui.controller.UserEditController;
|
||||
import com.zhangmeng.online.exam.ui.utils.AlertUtils;
|
||||
import com.zhangmeng.online.exam.ui.utils.HttpUtils;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
|
|
@ -94,7 +95,8 @@ public class UserDataLoad implements DataLoad {
|
|||
@Override
|
||||
public void editData(String id,Stage stage) {
|
||||
|
||||
UserForm userForm = new UserForm(true);
|
||||
UserForm userForm = new UserForm();
|
||||
UserEditController controller = userForm.getController();
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
|
|
@ -102,13 +104,13 @@ public class UserDataLoad implements DataLoad {
|
|||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
String username = data.getString("username");
|
||||
userForm.getUsername_field().setText(username);
|
||||
controller.usernameField.setText(username);
|
||||
String email = data.getString("email");
|
||||
userForm.getEmail_field().setText(email);
|
||||
controller.emailField.setText(email);
|
||||
String phone = data.getString("phone");
|
||||
userForm.getPhone_field().setText(phone);
|
||||
controller.phoneField.setText(phone);
|
||||
String password = data.getString("password");
|
||||
userForm.getPassword_field().setText(password);
|
||||
controller.passwordField.setText(password);
|
||||
AlertUtils.alert("编辑用户信息", (Parent) userForm, stage);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.zhangmeng.online.exam.ui.controller;
|
|||
import com.zhangmeng.online.exam.ui.module.Role;
|
||||
import com.zhangmeng.online.exam.ui.module.User;
|
||||
import com.zhangmeng.online.exam.ui.service.LogService;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.collections.transformation.FilteredList;
|
||||
|
|
@ -18,6 +20,8 @@ import javafx.stage.Modality;
|
|||
import javafx.stage.Stage;
|
||||
import com.zhangmeng.online.exam.ui.service.RoleService;
|
||||
import com.zhangmeng.online.exam.ui.service.UserService;
|
||||
import javafx.util.Callback;
|
||||
import javafx.util.StringConverter;
|
||||
|
||||
/**
|
||||
* @author zm
|
||||
|
|
@ -26,25 +30,25 @@ import com.zhangmeng.online.exam.ui.service.UserService;
|
|||
*/
|
||||
public class UserEditController {
|
||||
@FXML
|
||||
private TextField usernameField;
|
||||
public TextField usernameField;
|
||||
|
||||
@FXML
|
||||
private TextField nameField;
|
||||
public TextField phoneField;
|
||||
|
||||
@FXML
|
||||
private PasswordField passwordField;
|
||||
public PasswordField passwordField;
|
||||
|
||||
@FXML
|
||||
private TextField emailField;
|
||||
public TextField emailField;
|
||||
|
||||
@FXML
|
||||
private ComboBox<String> statusComboBox;
|
||||
public ComboBox<String> statusComboBox;
|
||||
|
||||
@FXML
|
||||
private ListView<Role> roleListView;
|
||||
public ListView<Role> roleListView;
|
||||
|
||||
private User user;
|
||||
private boolean saveClicked = false;
|
||||
public boolean saveClicked = false;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
|
|
@ -54,16 +58,41 @@ public class UserEditController {
|
|||
|
||||
// 初始化角色列表
|
||||
roleListView.setItems(FXCollections.observableArrayList(RoleService.getAllRoles()));
|
||||
roleListView.setCellFactory(CheckBoxListCell.forListView(role -> {
|
||||
return role.selectedProperty();
|
||||
}));
|
||||
|
||||
Callback<ListView<Role>, ListCell<Role>> call = CheckBoxListCell.forListView(new Callback<Role, ObservableValue<Boolean>>() {
|
||||
@Override
|
||||
public ObservableValue<Boolean> call(Role param) {
|
||||
return param.selectedProperty();
|
||||
}
|
||||
}, new StringConverter<Role>() {
|
||||
@Override
|
||||
public String toString(Role object) {
|
||||
return object.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Role fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
roleListView.setCellFactory(call);
|
||||
roleListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Role>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Role> observable, Role oldValue, Role newValue) {
|
||||
System.out.println("姓名:" + newValue.getName() + " 是否选择:" + newValue.isSelected());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
|
||||
usernameField.setText(user.getUsername());
|
||||
nameField.setText(user.getName());
|
||||
phoneField.setText(user.getPhone());
|
||||
emailField.setText(user.getEmail());
|
||||
statusComboBox.setValue(user.getStatus());
|
||||
|
||||
|
|
@ -96,7 +125,7 @@ public class UserEditController {
|
|||
}
|
||||
|
||||
// 更新基本信息
|
||||
user.setName(nameField.getText());
|
||||
user.setPhone(phoneField.getText());
|
||||
user.setEmail(emailField.getText());
|
||||
user.setStatus(statusComboBox.getValue());
|
||||
|
||||
|
|
@ -134,16 +163,22 @@ public class UserEditController {
|
|||
if (usernameField.getText() == null || usernameField.getText().trim().isEmpty()) {
|
||||
errorMessage.append("用户名不能为空!\n");
|
||||
}
|
||||
if (nameField.getText() == null || nameField.getText().trim().isEmpty()) {
|
||||
errorMessage.append("姓名不能为空!\n");
|
||||
}
|
||||
if (user == null && (passwordField.getText() == null || passwordField.getText().trim().isEmpty())) {
|
||||
|
||||
if (passwordField.getText() == null || passwordField.getText().trim().isEmpty()) {
|
||||
errorMessage.append("密码不能为空!\n");
|
||||
}
|
||||
|
||||
if (phoneField.getText() == null || phoneField.getText().trim().isEmpty()) {
|
||||
errorMessage.append("手机号不能为空!\n");
|
||||
}
|
||||
|
||||
if (emailField.getText() == null || emailField.getText().trim().isEmpty()) {
|
||||
errorMessage.append("邮箱不能为空!\n");
|
||||
}
|
||||
if (roleListView.getItems().stream().noneMatch(Role::isSelected)) {
|
||||
|
||||
Role role = roleListView.getSelectionModel().getSelectedItem();
|
||||
|
||||
if (role == null) {
|
||||
errorMessage.append("至少选择一个角色!\n");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class Role {
|
|||
private String description;
|
||||
private String status;
|
||||
private List<Permission> permissions;
|
||||
private BooleanProperty selected;
|
||||
private SimpleBooleanProperty selected;
|
||||
|
||||
public Role(int id, String name, String description, String status) {
|
||||
this.id = id;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class FxUtils {
|
|||
|
||||
Form form = (Form) node;
|
||||
if (form instanceof UserForm) {
|
||||
form = new UserForm(true);
|
||||
form = new UserForm();
|
||||
}
|
||||
if (form instanceof RoleForm) {
|
||||
form = new RoleForm();
|
||||
|
|
@ -67,7 +67,7 @@ public class FxUtils {
|
|||
|
||||
Form form = (Form) node;
|
||||
if (form instanceof UserForm) {
|
||||
form = new UserForm(true);
|
||||
form = new UserForm();
|
||||
}
|
||||
if (form instanceof RoleForm) {
|
||||
form = new RoleForm();
|
||||
|
|
|
|||
|
|
@ -20,14 +20,14 @@
|
|||
<Label text="用户名:" GridPane.rowIndex="0" GridPane.columnIndex="0"/>
|
||||
<TextField fx:id="usernameField" GridPane.rowIndex="0" GridPane.columnIndex="1"/>
|
||||
|
||||
<!-- 姓名 -->
|
||||
<Label text="姓名:" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
|
||||
<TextField fx:id="nameField" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
|
||||
|
||||
<!-- 密码 -->
|
||||
<Label text="密码:" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
|
||||
<Label text="密码:" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
|
||||
<PasswordField fx:id="passwordField" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
|
||||
|
||||
<!-- 手机号 -->
|
||||
<Label text="姓名:" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
|
||||
<TextField fx:id="phoneField" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
|
||||
|
||||
<!-- 邮箱 -->
|
||||
<Label text="邮箱:" GridPane.rowIndex="3" GridPane.columnIndex="0"/>
|
||||
<TextField fx:id="emailField" GridPane.rowIndex="3" GridPane.columnIndex="1"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue