表格便捷更新 2025年3月18日16:02:15
parent
9097ae4925
commit
c597ae17df
|
|
@ -26,4 +26,5 @@ public interface DataLoad {
|
|||
|
||||
public void editData(String s, Stage stage);
|
||||
|
||||
public void updateData(String id, String name, String oldValue, String newValue);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,4 +105,9 @@ public class OptionDataLoad implements DataLoad {
|
|||
AlertUtils.alert("编辑用户信息", (Parent) userForm, stage);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateData(String id, String name, String oldValue, String newValue) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,4 +67,10 @@ public class PermissionDataLoad implements DataLoad {
|
|||
public void editData(String id, Stage stage) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateData(String id, String name, String oldValue, String newValue) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,4 +68,9 @@ public class QuestionDataLoad implements DataLoad {
|
|||
public void editData(String s, Stage stage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateData(String id, String name, String oldValue, String newValue) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,5 +106,8 @@ public class QuestionOptionDataLoad implements DataLoad {
|
|||
AlertUtils.alert("编辑用户信息", (Parent) userForm, stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateData(String id, String name, String oldValue, String newValue) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,4 +69,9 @@ public class RoleDataLoad implements DataLoad {
|
|||
public void editData(String id, Stage stage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateData(String id, String name, String oldValue, String newValue) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,5 +105,8 @@ public class SubjectDataLoad implements DataLoad {
|
|||
AlertUtils.alert("编辑用户信息", (Parent) userForm, stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateData(String id, String name, String oldValue, String newValue) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@ public class UserDataLoad implements DataLoad {
|
|||
userMap.put("用户名", new SimpleStringProperty(user.getString("username")));
|
||||
userMap.put("手机号码", new SimpleStringProperty(user.getString("phone")));
|
||||
userMap.put("电子邮箱", new SimpleStringProperty(user.getString("email")));
|
||||
|
||||
userMap.put("用户名_username", new SimpleStringProperty(user.getString("username")));
|
||||
userMap.put("手机号码_phone", new SimpleStringProperty(user.getString("phone")));
|
||||
userMap.put("电子邮箱_email", new SimpleStringProperty(user.getString("email")));
|
||||
|
||||
userMap.put("id", new SimpleStringProperty(user.getString("id")));
|
||||
userMapList.add(userMap);
|
||||
}
|
||||
|
|
@ -105,4 +110,23 @@ public class UserDataLoad implements DataLoad {
|
|||
userForm.getPassword_field().setText(password);
|
||||
AlertUtils.alert("编辑用户信息", (Parent) userForm, stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateData(String id, String name, String oldValue, String newValue) {
|
||||
// System.out.println("修改前:" + oldValue + ",修改后:" + newValue);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
map.put("fieldName", name);
|
||||
map.put("oldValue", oldValue);
|
||||
map.put("newValue", newValue);
|
||||
String result = HttpUtils.POST(ApiUtils.API_URL + "/user/update", map);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
if (jsonObject.getIntValue("code") == 200){
|
||||
AlertUtils.alert_msg("更新成功!");
|
||||
}else {
|
||||
AlertUtils.alert_warning("更新失败!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.zhangmeng.online.exam.ui.components;
|
|||
|
||||
import com.zhangmeng.online.exam.ui.api.ApiUtils;
|
||||
import com.zhangmeng.online.exam.ui.components.callBack.DynamicTableComponentCallBack;
|
||||
import com.zhangmeng.online.exam.ui.utils.AlertUtils;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
|
@ -73,7 +74,28 @@ public class DynamicTableComponent extends VBox {
|
|||
column.setCellFactory(TextFieldTableCell.forTableColumn());
|
||||
column.setOnEditCommit(event -> {
|
||||
Map<String, SimpleStringProperty> row = event.getRowValue();
|
||||
Set<Map.Entry<String, SimpleStringProperty>> entries = row.entrySet();
|
||||
String name = null;
|
||||
for (Map.Entry<String, SimpleStringProperty> entry : entries) {
|
||||
String key = entry.getKey();
|
||||
SimpleStringProperty value = entry.getValue();
|
||||
if (key.startsWith(col+"_")){
|
||||
name = key.split("_")[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (name != null){
|
||||
// 刷新数据
|
||||
String newValue = event.getNewValue();
|
||||
String oldValue = event.getOldValue();
|
||||
// 调用接口修改数据
|
||||
callBack.update(DynamicTableComponent.this,row.get("id").get(),name, oldValue, newValue);
|
||||
// 刷新界面
|
||||
row.get(col).set(event.getNewValue());
|
||||
|
||||
}else {
|
||||
AlertUtils.alert_msg("该列不允许修改!");
|
||||
}
|
||||
});
|
||||
|
||||
column.prefWidthProperty().bind(tableView.widthProperty().divide(columns.size()));
|
||||
|
|
@ -115,6 +137,7 @@ public class DynamicTableComponent extends VBox {
|
|||
});
|
||||
contextMenu.getItems().addAll(editItem,deleteItem);
|
||||
tableView.setContextMenu(contextMenu);
|
||||
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);//允许一次选择一个或多个连续的索引范围。
|
||||
|
||||
///添加按钮
|
||||
Button button = new Button("新增");
|
||||
|
|
|
|||
|
|
@ -29,4 +29,5 @@ public interface DynamicTableComponentCallBack {
|
|||
|
||||
void edit(String s,DynamicTableComponent dynamicTableComponent);
|
||||
|
||||
void update(DynamicTableComponent dynamicTableComponent, String id, String name, String oldValue, String newValue);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,11 @@ public class DynamicTableComponentCallBackImpl implements DynamicTableComponentC
|
|||
dataLoad.editData(id, stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(DynamicTableComponent dynamicTableComponent, String id, String name, String oldValue, String newValue) {
|
||||
dataLoad.updateData(id, name, oldValue, newValue);
|
||||
}
|
||||
|
||||
public DataLoad getDataLoad() {
|
||||
return dataLoad;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue