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