试卷添加
parent
783a60ec05
commit
64b2a44c41
|
|
@ -1,6 +1,7 @@
|
||||||
package com.zhangmeng.online.exam.ui.api;
|
package com.zhangmeng.online.exam.ui.api;
|
||||||
|
|
||||||
import com.zhangmeng.online.exam.ui.admin.IndexPage;
|
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.QuestionForm;
|
||||||
import com.zhangmeng.online.exam.ui.api.form.RoleForm;
|
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.UserForm;
|
||||||
|
|
@ -28,7 +29,7 @@ import java.util.*;
|
||||||
*/
|
*/
|
||||||
public class ApiUtils {
|
public class ApiUtils {
|
||||||
|
|
||||||
public static final String API_URL = "http://localhost:8080";
|
public static final String API_URL = "http://localhost:8083";
|
||||||
|
|
||||||
public static final int PAGE_SIZE = 25;
|
public static final int PAGE_SIZE = 25;
|
||||||
|
|
||||||
|
|
@ -102,6 +103,7 @@ public class ApiUtils {
|
||||||
|
|
||||||
public static DataView getExamPaper() {
|
public static DataView getExamPaper() {
|
||||||
DataLoad dataLoad = new PaperDataLoad();
|
DataLoad dataLoad = new PaperDataLoad();
|
||||||
|
dataLoad.setForm(new PaperForm());
|
||||||
return dataLoad.loadData(PAGE_NUM,PAGE_SIZE);
|
return dataLoad.loadData(PAGE_NUM,PAGE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
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.PaperEditController;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zm
|
||||||
|
* @date 2025/4/6 14:52
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
public class PaperForm extends Form {
|
||||||
|
private PaperEditController controller;
|
||||||
|
|
||||||
|
public PaperEditController getController() {
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
public PaperForm() {
|
||||||
|
try {
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/paper-edit.fxml"));
|
||||||
|
this.getChildren().add(fxmlLoader.load());
|
||||||
|
controller = fxmlLoader.getController();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -46,7 +46,7 @@ public class DynamicTableComponentCallBackImpl implements DynamicTableComponentC
|
||||||
// Form form = (Form) node;
|
// Form form = (Form) node;
|
||||||
// form.setTableComponent(table);
|
// form.setTableComponent(table);
|
||||||
// AlertUtils.alert("设置", node, primaryStage);
|
// AlertUtils.alert("设置", node, primaryStage);
|
||||||
FxUtils.alert("设置",node, primaryStage);
|
FxUtils.alert("设置",node, primaryStage, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,195 @@
|
||||||
|
package com.zhangmeng.online.exam.ui.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.zhangmeng.online.exam.ui.api.ApiUtils;
|
||||||
|
import com.zhangmeng.online.exam.ui.components.DynamicTableComponent;
|
||||||
|
import com.zhangmeng.online.exam.ui.module.QuestionType;
|
||||||
|
import com.zhangmeng.online.exam.ui.module.SubjectType;
|
||||||
|
import com.zhangmeng.online.exam.ui.service.RoleService;
|
||||||
|
import com.zhangmeng.online.exam.ui.service.SubjectService;
|
||||||
|
import com.zhangmeng.online.exam.ui.service.UserService;
|
||||||
|
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 javafx.collections.FXCollections;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.control.cell.CheckBoxListCell;
|
||||||
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.util.Callback;
|
||||||
|
import javafx.util.StringConverter;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.zhangmeng.online.exam.ui.utils.FxUtils.FX_BEANS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zm
|
||||||
|
* @date 2025/4/6 14:58
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
public class PaperEditController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public TextField nameField;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public TextArea descriptionTextArea;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public TextField scoreField;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public TextField passScoreField;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public TextField examTimeField;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public ComboBox<Status> statusComboBox;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public ComboBox<SubjectType> subjectBox;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize() {
|
||||||
|
// 初始化状态下拉框
|
||||||
|
Status status1 = new Status("启用", 1);
|
||||||
|
Status status2 = new Status("禁用", 0);
|
||||||
|
statusComboBox.getItems().addAll(status1, status2);
|
||||||
|
statusComboBox.setValue(status1);
|
||||||
|
|
||||||
|
statusComboBox.setConverter(new StringConverter<Status>() {
|
||||||
|
@Override
|
||||||
|
public String toString(Status object) {
|
||||||
|
return object.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Status fromString(String string) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
statusComboBox.setCellFactory(new Callback<ListView<Status>, ListCell<Status>>() {
|
||||||
|
@Override
|
||||||
|
public ListCell<Status> call(ListView<Status> statusListView) {
|
||||||
|
return new ListCell<>() {
|
||||||
|
@Override
|
||||||
|
protected void updateItem(Status item, boolean empty) {
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
if (item != null && !empty) {
|
||||||
|
HBox hBox = new HBox();
|
||||||
|
Label label = new Label(item.getName());
|
||||||
|
hBox.getChildren().add(label);
|
||||||
|
setGraphic(hBox);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
subjectBox.getItems().addAll(SubjectService.getALLSubjectType());
|
||||||
|
subjectBox.getSelectionModel().selectFirst();
|
||||||
|
subjectBox.setConverter(new StringConverter<SubjectType>() {
|
||||||
|
@Override
|
||||||
|
public String toString(SubjectType object) {
|
||||||
|
return object.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SubjectType fromString(String string) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void handleSave(ActionEvent actionEvent) {
|
||||||
|
|
||||||
|
// 保存试卷信息
|
||||||
|
if (nameField.getText().trim().isEmpty()) {
|
||||||
|
AlertUtils.alert_warning("试卷名称不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (descriptionTextArea.getText().trim().isEmpty()) {
|
||||||
|
AlertUtils.alert_warning("试卷描述不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scoreField.getText().trim().isEmpty()) {
|
||||||
|
AlertUtils.alert_warning("总分不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (passScoreField.getText().trim().isEmpty()) {
|
||||||
|
AlertUtils.alert_warning("及格分数不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (examTimeField.getText().trim().isEmpty()) {
|
||||||
|
AlertUtils.alert_warning("考试时间不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 保存试卷信息
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.put("token", UserService.getCurrentUser().getToken());
|
||||||
|
params.put("name", nameField.getText().trim());
|
||||||
|
params.put("description", descriptionTextArea.getText().trim());
|
||||||
|
params.put("score", scoreField.getText().trim());
|
||||||
|
params.put("passScore", passScoreField.getText().trim());
|
||||||
|
params.put("examTime", examTimeField.getText().trim());
|
||||||
|
params.put("status", statusComboBox.getValue().getValue());
|
||||||
|
params.put("subjectId", subjectBox.getSelectionModel().getSelectedItem().getId());
|
||||||
|
|
||||||
|
String response = HttpUtils.POST(ApiUtils.API_URL + "/paper/save", params);
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||||
|
if (jsonObject.getIntValue("code") == 200) {
|
||||||
|
Alert alert = AlertUtils.alert_msg("保存成功!");
|
||||||
|
handleCancel();
|
||||||
|
} else {
|
||||||
|
AlertUtils.alert_warning("保存失败!" + jsonObject.getString("msg"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void handleCancel() {
|
||||||
|
|
||||||
|
Stage window = (Stage) subjectBox.getScene().getWindow();
|
||||||
|
window.close();
|
||||||
|
//刷新数据
|
||||||
|
DynamicTableComponent dynamicTableComponent = FX_BEANS.get(FxUtils.Paper_DynamicTableComponent);
|
||||||
|
dynamicTableComponent.flushData();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Status {
|
||||||
|
private String name;
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
public Status(String name, int value) {
|
||||||
|
this.name = name;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.zhangmeng.online.exam.ui.utils;
|
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.QuestionForm;
|
||||||
import com.zhangmeng.online.exam.ui.api.form.RoleForm;
|
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.UserForm;
|
||||||
|
|
@ -76,6 +77,10 @@ public class FxUtils {
|
||||||
form = new QuestionForm();
|
form = new QuestionForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (form instanceof PaperForm){
|
||||||
|
form = new PaperForm();
|
||||||
|
}
|
||||||
|
|
||||||
Scene scene = null;
|
Scene scene = null;
|
||||||
if (!isEdit) {
|
if (!isEdit) {
|
||||||
scene = new Scene(form);
|
scene = new Scene(form);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.ComboBox?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.TextArea?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.layout.ColumnConstraints?>
|
||||||
|
<?import javafx.scene.layout.GridPane?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
|
||||||
|
<VBox prefHeight="355.0" prefWidth="648.0" spacing="10" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.online.exam.ui.controller.PaperEditController">
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="10" left="10" right="10" top="10" />
|
||||||
|
</padding>
|
||||||
|
|
||||||
|
<GridPane hgap="10" vgap="10">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints minWidth="80" prefWidth="100" />
|
||||||
|
<ColumnConstraints hgrow="ALWAYS" />
|
||||||
|
</columnConstraints>
|
||||||
|
|
||||||
|
<!-- 试卷名称 -->
|
||||||
|
<Label text="试卷名称:" GridPane.columnIndex="0" GridPane.rowIndex="0" />
|
||||||
|
<TextField fx:id="nameField" GridPane.columnIndex="1" GridPane.rowIndex="0" />
|
||||||
|
|
||||||
|
<!-- 试卷描述 -->
|
||||||
|
<Label text="试卷描述:" GridPane.columnIndex="0" GridPane.rowIndex="1" />
|
||||||
|
<TextArea fx:id="descriptionTextArea" prefHeight="70.0" prefWidth="518.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||||
|
|
||||||
|
<!-- 总分 -->
|
||||||
|
<Label text="总分:" GridPane.columnIndex="0" GridPane.rowIndex="2" />
|
||||||
|
<TextField fx:id="scoreField" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||||
|
|
||||||
|
<!-- 及格分数 -->
|
||||||
|
<Label text="及格分数:" GridPane.columnIndex="0" GridPane.rowIndex="3" />
|
||||||
|
<TextField fx:id="passScoreField" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
||||||
|
|
||||||
|
<!-- 考试时间 -->
|
||||||
|
<Label text="考试时间:" GridPane.columnIndex="0" GridPane.rowIndex="4" />
|
||||||
|
<TextField fx:id="examTimeField" GridPane.columnIndex="1" GridPane.rowIndex="4" />
|
||||||
|
|
||||||
|
<!-- 试卷状态 -->
|
||||||
|
<Label text="状态:" GridPane.columnIndex="0" GridPane.rowIndex="5" />
|
||||||
|
<ComboBox fx:id="statusComboBox" GridPane.columnIndex="1" GridPane.rowIndex="5" />
|
||||||
|
|
||||||
|
<!-- 所属科目 -->
|
||||||
|
<Label text="所属科目:" GridPane.columnIndex="0" GridPane.rowIndex="6" />
|
||||||
|
<ComboBox fx:id="subjectBox" GridPane.columnIndex="1" GridPane.rowIndex="6" />
|
||||||
|
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints />
|
||||||
|
<RowConstraints />
|
||||||
|
<RowConstraints />
|
||||||
|
<RowConstraints />
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" />
|
||||||
|
<RowConstraints />
|
||||||
|
<RowConstraints />
|
||||||
|
</rowConstraints>
|
||||||
|
</GridPane>
|
||||||
|
|
||||||
|
<HBox alignment="CENTER_RIGHT" spacing="10">
|
||||||
|
<Button defaultButton="true" onAction="#handleSave" text="保存" />
|
||||||
|
<Button cancelButton="true" onAction="#handleCancel" text="取消" />
|
||||||
|
</HBox>
|
||||||
|
</VBox>
|
||||||
Loading…
Reference in New Issue