2025年4月9日18:19:04
parent
be73b40372
commit
474006abd5
|
|
@ -1,10 +1,7 @@
|
|||
package com.zhangmeng.online.exam.ui.api;
|
||||
|
||||
import com.zhangmeng.online.exam.ui.admin.IndexPage;
|
||||
import com.zhangmeng.online.exam.ui.api.form.PaperForm;
|
||||
import com.zhangmeng.online.exam.ui.api.form.QuestionForm;
|
||||
import com.zhangmeng.online.exam.ui.api.form.RoleForm;
|
||||
import com.zhangmeng.online.exam.ui.api.form.UserForm;
|
||||
import com.zhangmeng.online.exam.ui.api.form.*;
|
||||
import com.zhangmeng.online.exam.ui.api.model.*;
|
||||
import com.zhangmeng.online.exam.ui.components.DynamicTableComponent;
|
||||
import com.zhangmeng.online.exam.ui.components.callBack.DynamicTableComponentCallBack;
|
||||
|
|
@ -77,6 +74,7 @@ public class ApiUtils {
|
|||
|
||||
public static DataView getPermissionList() {
|
||||
DataLoad dataLoad = new PermissionDataLoad();
|
||||
dataLoad.setForm(new PermissionForm());
|
||||
return dataLoad.loadData(PAGE_NUM,PAGE_SIZE);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
package com.zhangmeng.online.exam.ui.api.form;
|
||||
|
||||
import com.zhangmeng.online.exam.ui.api.form.base.Form;
|
||||
import com.zhangmeng.online.exam.ui.controller.PermissionEditController;
|
||||
import com.zhangmeng.online.exam.ui.controller.UserEditController;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author zm
|
||||
* @date 2025/4/8 12:22
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class PermissionForm extends Form {
|
||||
private PermissionEditController controller;
|
||||
|
||||
public PermissionForm() {
|
||||
|
||||
try {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/permission-edit.fxml"));
|
||||
this.getChildren().add(fxmlLoader.load());
|
||||
this.controller = fxmlLoader.getController();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public PermissionEditController getController() {
|
||||
return controller;
|
||||
}
|
||||
|
||||
public void setController(PermissionEditController controller) {
|
||||
this.controller = controller;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,9 @@ import static com.zhangmeng.online.exam.ui.api.ApiUtils.API_URL;
|
|||
* @version: 1.0
|
||||
*/
|
||||
public class PermissionDataLoad implements DataLoad {
|
||||
|
||||
private Parent form;
|
||||
|
||||
@Override
|
||||
public ApiUtils.DataView loadData(Integer pageNum, Integer pageSize) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
|
|
@ -46,12 +49,12 @@ public class PermissionDataLoad implements DataLoad {
|
|||
|
||||
@Override
|
||||
public void setForm(Parent view) {
|
||||
|
||||
this.form = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parent getForm() {
|
||||
return null;
|
||||
return this.form;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,104 @@
|
|||
package com.zhangmeng.online.exam.ui.controller;
|
||||
|
||||
import com.zhangmeng.online.exam.ui.module.Permission;
|
||||
import com.zhangmeng.online.exam.ui.module.SubjectType;
|
||||
import com.zhangmeng.online.exam.ui.service.SubjectService;
|
||||
import com.zhangmeng.online.exam.ui.service.UserService;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.StringConverter;
|
||||
import com.zhangmeng.online.exam.ui.service.PermissionService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zm
|
||||
* @date 2025/4/8 14:07
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class PermissionEditController {
|
||||
|
||||
@FXML
|
||||
public TextField rolenameField;
|
||||
|
||||
@FXML
|
||||
public TextField descriptionField;
|
||||
|
||||
@FXML
|
||||
public TextField urlField;
|
||||
|
||||
@FXML
|
||||
public ComboBox<Permission> permissionComboBox;
|
||||
|
||||
private Permission editPermission;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
|
||||
permissionComboBox.getItems().addAll(PermissionService.getALLPermissions());
|
||||
//permissionComboBox.getSelectionModel().selectFirst();
|
||||
permissionComboBox.setConverter(new StringConverter<Permission>() {
|
||||
@Override
|
||||
public String toString(Permission object) {
|
||||
if (object == null){
|
||||
return null;
|
||||
}
|
||||
return object.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Permission fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void handleSave(ActionEvent actionEvent) {
|
||||
Permission permission = permissionComboBox.getSelectionModel().getSelectedItem();
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", editPermission == null? "" : editPermission.getId());
|
||||
params.put("name", rolenameField.getText());
|
||||
params.put("description", descriptionField.getText());
|
||||
params.put("url", urlField.getText());
|
||||
params.put("parent_id",permission == null? "" : permission.getId());
|
||||
params.put("token", UserService.getCurrentUser().getToken());
|
||||
|
||||
boolean flag = false;
|
||||
if (editPermission == null){
|
||||
flag = true;
|
||||
}
|
||||
|
||||
PermissionService.savePermission(params,flag);
|
||||
closeDialog();
|
||||
}
|
||||
|
||||
public void setEditPermission(Permission editPermission) {
|
||||
this.editPermission = editPermission;
|
||||
rolenameField.setText(editPermission.getName());
|
||||
descriptionField.setText(editPermission.getDescription());
|
||||
urlField.setText(editPermission.getUrl());
|
||||
ObservableList<Permission> items = permissionComboBox.getItems();
|
||||
for (Permission permission : items) {
|
||||
if (permission.getId() == editPermission.getParentId()){
|
||||
permissionComboBox.getSelectionModel().select(permission);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleCancel() {
|
||||
closeDialog();
|
||||
}
|
||||
|
||||
private void closeDialog() {
|
||||
Stage stage = (Stage) permissionComboBox.getScene().getWindow();
|
||||
stage.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,9 @@ public class Permission {
|
|||
private int parentId; // 父权限ID
|
||||
private String url; // 资源路径
|
||||
private int sort; // 排序号
|
||||
|
||||
private String description; // 描述
|
||||
|
||||
private List<Permission> children = new ArrayList<>();
|
||||
|
||||
public Permission(int id, String code, String name, String type, int parentId, String url, int sort) {
|
||||
|
|
@ -23,6 +26,9 @@ public class Permission {
|
|||
this.sort = sort;
|
||||
}
|
||||
|
||||
public Permission() {
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public int getId() {
|
||||
return id;
|
||||
|
|
@ -87,4 +93,12 @@ public class Permission {
|
|||
public void setChildren(List<Permission> children) {
|
||||
this.children = children;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
package com.zhangmeng.online.exam.ui.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.zhangmeng.online.exam.ui.api.ApiUtils;
|
||||
import com.zhangmeng.online.exam.ui.module.Permission;
|
||||
import com.zhangmeng.online.exam.ui.module.Role;
|
||||
import com.zhangmeng.online.exam.ui.utils.AlertUtils;
|
||||
import com.zhangmeng.online.exam.ui.utils.FxUtils;
|
||||
import com.zhangmeng.online.exam.ui.utils.HttpUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.zhangmeng.online.exam.ui.api.ApiUtils.API_URL;
|
||||
import static com.zhangmeng.online.exam.ui.utils.FxUtils.Permission_DynamicTableComponent;
|
||||
import static com.zhangmeng.online.exam.ui.utils.FxUtils.User_DynamicTableComponent;
|
||||
|
||||
/**
|
||||
* @author zm
|
||||
* @date 2025/4/8 14:23
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class PermissionService {
|
||||
|
||||
|
||||
public static List<Permission> getALLPermissions() {
|
||||
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("pageNum", ApiUtils.PAGE_NUM);
|
||||
params.put("pageSize", ApiUtils.PAGE_SIZE);
|
||||
params.put("isTop", true);
|
||||
|
||||
String userListData = HttpUtils.GET(API_URL + "/permission/list",params);
|
||||
JSONObject jsonObject = JSON.parseObject(userListData);
|
||||
JSONArray data = jsonObject.getJSONArray("data");
|
||||
Integer total = jsonObject.getInteger("total");
|
||||
List<Permission> roles = new ArrayList<>();
|
||||
for (Object datum : data) {
|
||||
JSONObject permissionmap = (JSONObject) datum;
|
||||
|
||||
String id = permissionmap.getString("id");
|
||||
String name = permissionmap.getString("name");
|
||||
String desc = permissionmap.getString("desc");
|
||||
String url = permissionmap.getString("url");
|
||||
String parentId = permissionmap.getString("parentId");
|
||||
String sort = permissionmap.getString("sort");
|
||||
|
||||
Permission permission = new Permission();
|
||||
permission.setId(Integer.parseInt(id));
|
||||
permission.setName(name);
|
||||
permission.setUrl(url);
|
||||
if (sort != null){
|
||||
permission.setSort(Integer.parseInt(sort));
|
||||
}
|
||||
permission.setParentId(Integer.parseInt(parentId));
|
||||
roles.add(permission);
|
||||
}
|
||||
|
||||
return roles;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void savePermission(Map<String, Object> params,boolean isEdit) {
|
||||
String result = HttpUtils.POST(ApiUtils.API_URL + "/permission/save", params);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
if (jsonObject.getIntValue("code") == 200){
|
||||
if (!isEdit){
|
||||
AlertUtils.alert_msg("保存成功!");
|
||||
FxUtils.FX_BEANS.get(Permission_DynamicTableComponent).flushData();
|
||||
}else {
|
||||
AlertUtils.alert_msg("更新成功!");
|
||||
FxUtils.FX_BEANS.get(Permission_DynamicTableComponent).flushData();
|
||||
}
|
||||
}else {
|
||||
AlertUtils.alert_warning("保存失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,6 @@
|
|||
package com.zhangmeng.online.exam.ui.utils;
|
||||
|
||||
import com.zhangmeng.online.exam.ui.api.form.PaperForm;
|
||||
import com.zhangmeng.online.exam.ui.api.form.QuestionForm;
|
||||
import com.zhangmeng.online.exam.ui.api.form.RoleForm;
|
||||
import com.zhangmeng.online.exam.ui.api.form.UserForm;
|
||||
import com.zhangmeng.online.exam.ui.api.form.*;
|
||||
import com.zhangmeng.online.exam.ui.api.form.base.Form;
|
||||
import com.zhangmeng.online.exam.ui.components.DynamicTableComponent;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
|
|
@ -81,6 +78,10 @@ public class FxUtils {
|
|||
form = new PaperForm();
|
||||
}
|
||||
|
||||
if (form instanceof PermissionForm){
|
||||
form = new PermissionForm();
|
||||
}
|
||||
|
||||
Scene scene = null;
|
||||
if (!isEdit) {
|
||||
scene = new Scene(form);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
|
||||
<VBox spacing="10" xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="com.zhangmeng.online.exam.ui.controller.PermissionEditController">
|
||||
<padding>
|
||||
<Insets top="10" right="10" bottom="10" left="10"/>
|
||||
</padding>
|
||||
|
||||
<GridPane hgap="10" vgap="10">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints minWidth="80" prefWidth="100"/>
|
||||
<ColumnConstraints hgrow="ALWAYS"/>
|
||||
</columnConstraints>
|
||||
|
||||
|
||||
<Label text="父级权限:" GridPane.rowIndex="0" GridPane.columnIndex="0"/>
|
||||
<ComboBox fx:id="permissionComboBox" GridPane.rowIndex="0" GridPane.columnIndex="1"/>
|
||||
|
||||
<!-- 权限名称 -->
|
||||
<Label text="权限名称:" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
|
||||
<TextField fx:id="rolenameField" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
|
||||
|
||||
<!-- 描述 -->
|
||||
<Label text="描述:" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
|
||||
<TextField fx:id="descriptionField" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
|
||||
|
||||
<!-- url -->
|
||||
<Label text="权限路径:" GridPane.rowIndex="3" GridPane.columnIndex="0"/>
|
||||
<TextField fx:id="urlField" GridPane.rowIndex="3" GridPane.columnIndex="1"/>
|
||||
|
||||
|
||||
</GridPane>
|
||||
|
||||
<HBox spacing="10" alignment="CENTER_RIGHT">
|
||||
<Button text="保存" onAction="#handleSave" defaultButton="true"/>
|
||||
<Button text="取消" onAction="#handleCancel" cancelButton="true"/>
|
||||
</HBox>
|
||||
</VBox>
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.PasswordField?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
||||
|
||||
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fmxl.UserForm">
|
||||
<children>
|
||||
<Label layoutX="83.0" layoutY="64.0" text="用户名:" />
|
||||
<PasswordField layoutX="162.0" layoutY="117.0" prefHeight="23.0" prefWidth="289.0" />
|
||||
<Label layoutX="87.0" layoutY="121.0" text="密码:" />
|
||||
<Label layoutX="87.0" layoutY="169.0" text="手机号:" />
|
||||
<Label layoutX="87.0" layoutY="224.0" text="邮箱:" />
|
||||
<TextField layoutX="162.0" layoutY="60.0" prefHeight="23.0" prefWidth="289.0" />
|
||||
<TextField layoutX="162.0" layoutY="165.0" prefHeight="23.0" prefWidth="289.0" />
|
||||
<TextField layoutX="162.0" layoutY="220.0" prefHeight="23.0" prefWidth="289.0" />
|
||||
<Button layoutX="263.0" layoutY="288.0" mnemonicParsing="false" text="提交" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
Loading…
Reference in New Issue