删除 2025年3月15日11:59:52
parent
2152c77ba2
commit
4459d3fe2a
|
|
@ -22,4 +22,5 @@ public interface DataLoad {
|
||||||
Map<String, Object> saveForm(Map<String, Object> map);
|
Map<String, Object> saveForm(Map<String, Object> map);
|
||||||
|
|
||||||
public void deleteData(String id);
|
public void deleteData(String id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ public class UserDataLoad implements DataLoad {
|
||||||
userMap.put("用户名", new SimpleStringProperty(user.getString("username")));
|
userMap.put("用户名", new SimpleStringProperty(user.getString("username")));
|
||||||
userMap.put("电子邮箱", new SimpleStringProperty(user.getString("email")));
|
userMap.put("电子邮箱", new SimpleStringProperty(user.getString("email")));
|
||||||
userMap.put("手机号码", new SimpleStringProperty(user.getString("phone")));
|
userMap.put("手机号码", new SimpleStringProperty(user.getString("phone")));
|
||||||
|
userMap.put("id", new SimpleStringProperty(user.getString("id")));
|
||||||
userMapList.add(userMap);
|
userMapList.add(userMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,6 +72,14 @@ public class UserDataLoad implements DataLoad {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteData(String id) {
|
public void deleteData(String id) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("id", id);
|
||||||
|
String result = HttpUtils.POST(ApiUtils.API_URL + "/user/delete", map);
|
||||||
|
JSONObject jsonObject = JSON.parseObject(result);
|
||||||
|
if (jsonObject.getIntValue("code") == 200){
|
||||||
|
AlertUtils.alert_msg("删除成功!");
|
||||||
|
}else {
|
||||||
|
AlertUtils.alert_warning("删除失败!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,7 @@ import javafx.event.ActionEvent;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.Pagination;
|
|
||||||
import javafx.scene.control.TableColumn;
|
|
||||||
import javafx.scene.control.TableView;
|
|
||||||
import javafx.scene.control.cell.MapValueFactory;
|
import javafx.scene.control.cell.MapValueFactory;
|
||||||
import javafx.scene.control.cell.TextFieldTableCell;
|
import javafx.scene.control.cell.TextFieldTableCell;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
|
|
@ -64,7 +61,7 @@ public class DynamicTableComponent extends VBox {
|
||||||
// 动态生成列(示例字段):ml-citation{ref="3,4" data="citationList"}
|
// 动态生成列(示例字段):ml-citation{ref="3,4" data="citationList"}
|
||||||
List<String> columns ;
|
List<String> columns ;
|
||||||
if (!dataList.isEmpty()){
|
if (!dataList.isEmpty()){
|
||||||
columns= Arrays.asList(dataList.get(0).keySet().toArray(new String[0]));
|
columns= Arrays.asList(dataList.get(0).keySet().toArray(new String[0])).stream().filter(key -> !key.equals("id")).toList();
|
||||||
}else {
|
}else {
|
||||||
columns=keys;
|
columns=keys;
|
||||||
}
|
}
|
||||||
|
|
@ -81,10 +78,29 @@ public class DynamicTableComponent extends VBox {
|
||||||
});
|
});
|
||||||
|
|
||||||
column.prefWidthProperty().bind(tableView.widthProperty().divide(finalColumns.size()));
|
column.prefWidthProperty().bind(tableView.widthProperty().divide(finalColumns.size()));
|
||||||
|
|
||||||
tableView.getColumns().add(column);
|
tableView.getColumns().add(column);
|
||||||
});
|
});
|
||||||
data.addAll(dataList);
|
data.addAll(dataList);
|
||||||
|
|
||||||
|
ContextMenu contextMenu = new ContextMenu();
|
||||||
|
MenuItem menuItem = new MenuItem("删除");
|
||||||
|
menuItem.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
Map<String, SimpleStringProperty> selectedItem = tableView.getSelectionModel().getSelectedItem();
|
||||||
|
if (selectedItem!= null) {
|
||||||
|
SimpleStringProperty id = selectedItem.get("id");
|
||||||
|
if (id!= null) {
|
||||||
|
callBack.delete(id.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.remove(tableView.getSelectionModel().getSelectedItem());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
contextMenu.getItems().add(menuItem);
|
||||||
|
tableView.setContextMenu(contextMenu);
|
||||||
|
|
||||||
///添加按钮
|
///添加按钮
|
||||||
Button button = new Button("新增");
|
Button button = new Button("新增");
|
||||||
button.setOnAction(event -> {
|
button.setOnAction(event -> {
|
||||||
|
|
|
||||||
|
|
@ -24,4 +24,7 @@ public interface DynamicTableComponentCallBack {
|
||||||
public void Add(Parent node, Stage primaryStage, DynamicTableComponent dynamicTableComponent);
|
public void Add(Parent node, Stage primaryStage, DynamicTableComponent dynamicTableComponent);
|
||||||
|
|
||||||
public Parent getAddForm();
|
public Parent getAddForm();
|
||||||
|
|
||||||
|
void delete(String s);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,11 @@ public class DynamicTableComponentCallBackImpl implements DynamicTableComponentC
|
||||||
return this.node;
|
return this.node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(String s) {
|
||||||
|
dataLoad.deleteData(s);
|
||||||
|
}
|
||||||
|
|
||||||
public DataLoad getDataLoad() {
|
public DataLoad getDataLoad() {
|
||||||
return dataLoad;
|
return dataLoad;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue