2025年3月7日18:18:39
parent
431cf74b95
commit
7a34bb898b
|
|
@ -51,11 +51,12 @@ public class ApiUtils {
|
|||
return menuItems;
|
||||
}
|
||||
|
||||
public static List<Map<String, SimpleStringProperty>> getUserList(){
|
||||
public static DataView getUserList() {
|
||||
String userListData = HttpUtils.GET(API_URL + "/user/list");
|
||||
JSONObject jsonObject = JSON.parseObject(userListData);
|
||||
JSONArray data = jsonObject.getJSONArray("data");
|
||||
List<Map<String, SimpleStringProperty>> userMapList = new ArrayList<>();
|
||||
|
||||
for (Object datum : data) {
|
||||
JSONObject user = (JSONObject) datum;
|
||||
Map<String, SimpleStringProperty> userMap = new HashMap<>();
|
||||
|
|
@ -65,10 +66,10 @@ public class ApiUtils {
|
|||
userMap.put("手机号码", new SimpleStringProperty(user.getString("phone")));
|
||||
userMapList.add(userMap);
|
||||
}
|
||||
return userMapList;
|
||||
return new DataView(Arrays.asList("序号", "用户名", "电子邮箱", "手机号码"), userMapList);
|
||||
}
|
||||
|
||||
public static List<Map<String, SimpleStringProperty>> getRoleList() {
|
||||
public static DataView getRoleList() {
|
||||
String userListData = HttpUtils.GET(API_URL + "/role/list");
|
||||
JSONObject jsonObject = JSON.parseObject(userListData);
|
||||
JSONArray data = jsonObject.getJSONArray("data");
|
||||
|
|
@ -77,15 +78,15 @@ public class ApiUtils {
|
|||
JSONObject role = (JSONObject) datum;
|
||||
Map<String, SimpleStringProperty> roleMap = new HashMap<>();
|
||||
roleMap.put("序号", new SimpleStringProperty(role.getString("id")));
|
||||
roleMap.put("角色名称",new SimpleStringProperty( role.getString("name")));
|
||||
roleMap.put("描述",new SimpleStringProperty( role.getString("desc")));
|
||||
roleMap.put("角色类型",new SimpleStringProperty( role.getString("type_name")));
|
||||
roleMap.put("角色名称", new SimpleStringProperty(role.getString("name")));
|
||||
roleMap.put("描述", new SimpleStringProperty(role.getString("desc")));
|
||||
roleMap.put("角色类型", new SimpleStringProperty(role.getString("type_name")));
|
||||
roleMapList.add(roleMap);
|
||||
}
|
||||
return roleMapList;
|
||||
return new DataView(Arrays.asList("序号", "角色名称", "描述", "角色类型"), roleMapList);
|
||||
}
|
||||
|
||||
public static List<Map<String, SimpleStringProperty>> getPermissionList() {
|
||||
public static DataView getPermissionList() {
|
||||
|
||||
String userListData = HttpUtils.GET(API_URL + "/permission/list");
|
||||
JSONObject jsonObject = JSON.parseObject(userListData);
|
||||
|
|
@ -96,13 +97,61 @@ public class ApiUtils {
|
|||
JSONObject permission = (JSONObject) datum;
|
||||
Map<String, SimpleStringProperty> userMap = new HashMap<>();
|
||||
userMap.put("序号", new SimpleStringProperty(permission.getString("id")));
|
||||
userMap.put("权限名称",new SimpleStringProperty( permission.getString("name")));
|
||||
userMap.put("描述",new SimpleStringProperty( permission.getString("desc")));
|
||||
userMap.put("权限路径",new SimpleStringProperty( permission.getString("url")));
|
||||
userMap.put("权限名称", new SimpleStringProperty(permission.getString("name")));
|
||||
userMap.put("描述", new SimpleStringProperty(permission.getString("desc")));
|
||||
userMap.put("权限路径", new SimpleStringProperty(permission.getString("url")));
|
||||
permissionMapList.add(userMap);
|
||||
}
|
||||
return permissionMapList;
|
||||
return new DataView(Arrays.asList("序号", "权限名称", "描述", "权限路径"), permissionMapList);
|
||||
}
|
||||
|
||||
public static DataView getQuestionList() {
|
||||
|
||||
String userListData = HttpUtils.GET(API_URL + "/question/list");
|
||||
JSONObject jsonObject = JSON.parseObject(userListData);
|
||||
JSONArray data = jsonObject.getJSONArray("data");
|
||||
|
||||
List<Map<String, SimpleStringProperty>> questionMapList = new ArrayList<>();
|
||||
for (Object datum : data) {
|
||||
JSONObject permission = (JSONObject) datum;
|
||||
Map<String, SimpleStringProperty> userMap = new HashMap<>();
|
||||
userMap.put("序号", new SimpleStringProperty(permission.getString("id")));
|
||||
userMap.put("权限名称", new SimpleStringProperty(permission.getString("name")));
|
||||
userMap.put("描述", new SimpleStringProperty(permission.getString("desc")));
|
||||
userMap.put("权限路径", new SimpleStringProperty(permission.getString("url")));
|
||||
questionMapList.add(userMap);
|
||||
}
|
||||
return new DataView(Arrays.asList("序号", "权限名称", "描述", "权限路径"), questionMapList);
|
||||
}
|
||||
|
||||
public static class DataView {
|
||||
|
||||
private List<String> keys;
|
||||
|
||||
private List<Map<String, SimpleStringProperty>> dataList;
|
||||
|
||||
public DataView(List<String> keys, List<Map<String, SimpleStringProperty>> dataList) {
|
||||
this.keys = keys;
|
||||
this.dataList = dataList;
|
||||
}
|
||||
|
||||
public DataView() {
|
||||
}
|
||||
|
||||
public List<String> getKeys() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
public void setKeys(List<String> keys) {
|
||||
this.keys = keys;
|
||||
}
|
||||
|
||||
public List<Map<String, SimpleStringProperty>> getDataList() {
|
||||
return dataList;
|
||||
}
|
||||
|
||||
public void setDataList(List<Map<String, SimpleStringProperty>> dataList) {
|
||||
this.dataList = dataList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.zhangmeng.online.exam.ui.components;
|
||||
|
||||
import javafx.beans.property.SimpleMapProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
|
@ -11,6 +10,7 @@ import javafx.scene.control.cell.TextFieldTableCell;
|
|||
import javafx.scene.layout.VBox;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* 动态表格
|
||||
|
|
@ -22,14 +22,21 @@ import java.util.*;
|
|||
public class DynamicTableComponent extends VBox {
|
||||
private final ObservableList<Map<String, SimpleStringProperty>> data = FXCollections.observableArrayList();
|
||||
|
||||
public DynamicTableComponent(List<Map<String, SimpleStringProperty>> dataList) {
|
||||
public DynamicTableComponent(List<Map<String, SimpleStringProperty>> dataList,List<String> keys) {
|
||||
super();
|
||||
TableView<Map<String, SimpleStringProperty>> tableView = new TableView<>();
|
||||
tableView.setItems(data);
|
||||
tableView.setEditable(true);
|
||||
tableView.prefHeightProperty().bind(this.heightProperty());
|
||||
tableView.prefWidthProperty().bind(this.widthProperty());
|
||||
// 动态生成列(示例字段):ml-citation{ref="3,4" data="citationList"}
|
||||
List<String> columns = Arrays.asList(dataList.get(0).keySet().toArray(new String[0]));
|
||||
List<String> columns ;
|
||||
if (!dataList.isEmpty()){
|
||||
columns= Arrays.asList(dataList.get(0).keySet().toArray(new String[0]));
|
||||
}else {
|
||||
columns=keys;
|
||||
}
|
||||
List<String> finalColumns = columns;
|
||||
columns.forEach(col -> {
|
||||
TableColumn<Map<String,SimpleStringProperty>, String> column = new TableColumn<>(col);
|
||||
// 数据绑定:ml-citation{ref="1,3" data="citationList"}
|
||||
|
|
@ -41,7 +48,7 @@ public class DynamicTableComponent extends VBox {
|
|||
row.get(col).set(event.getNewValue());
|
||||
});
|
||||
|
||||
column.prefWidthProperty().bind(tableView.widthProperty().divide(columns.size()));
|
||||
column.prefWidthProperty().bind(tableView.widthProperty().divide(finalColumns.size()));
|
||||
tableView.getColumns().add(column);
|
||||
});
|
||||
data.addAll(dataList);
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ public class SideMenu extends VBox {
|
|||
case "/user/list" -> init_table(hbox, ApiUtils.getUserList());
|
||||
case "/role/list" -> init_table(hbox,ApiUtils.getRoleList());
|
||||
case "/permission/list" -> init_table(hbox,ApiUtils.getPermissionList());
|
||||
case "/question/list" -> init_table(hbox,ApiUtils.getQuestionList());
|
||||
}
|
||||
|
||||
});
|
||||
|
|
@ -159,10 +160,10 @@ public class SideMenu extends VBox {
|
|||
}
|
||||
|
||||
|
||||
private void init_table(HBox hbox, List<Map<String, SimpleStringProperty>> dataList) {
|
||||
private void init_table(HBox hbox, ApiUtils.DataView dataView) {
|
||||
Scene scene = hbox.getScene();
|
||||
IndexPage root = (IndexPage) scene.getRoot();
|
||||
DynamicTableComponent shortAnswerComponent = new DynamicTableComponent(dataList);
|
||||
DynamicTableComponent shortAnswerComponent = new DynamicTableComponent(dataView.getDataList(), dataView.getKeys());
|
||||
shortAnswerComponent.setPadding(new Insets(15));
|
||||
shortAnswerComponent.prefHeightProperty().bind(root.heightProperty().subtract(15));
|
||||
root.setCenter(shortAnswerComponent);
|
||||
|
|
|
|||
Loading…
Reference in New Issue