2025年4月11日14:53:22
parent
f365c606b2
commit
9ad557eb28
|
|
@ -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.OptionEditController;
|
||||
import com.zhangmeng.online.exam.ui.controller.SubjectEditController;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author zm
|
||||
* @date 2025/4/11 14:05
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class QuestionOptionForm extends Form {
|
||||
|
||||
|
||||
private OptionEditController controller;
|
||||
|
||||
public QuestionOptionForm() {
|
||||
try {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/option-edit.fxml"));
|
||||
this.getChildren().add(fxmlLoader.load());
|
||||
this.controller = fxmlLoader.getController();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public OptionEditController getController() {
|
||||
return controller;
|
||||
}
|
||||
|
||||
public void setController(OptionEditController controller) {
|
||||
this.controller = controller;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,9 +3,18 @@ package com.zhangmeng.online.exam.ui.api.model;
|
|||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.zhangmeng.online.exam.ui.api.form.QuestionOptionForm;
|
||||
import com.zhangmeng.online.exam.ui.api.form.SubjectForm;
|
||||
import com.zhangmeng.online.exam.ui.controller.OptionEditController;
|
||||
import com.zhangmeng.online.exam.ui.controller.SubjectEditController;
|
||||
import com.zhangmeng.online.exam.ui.module.QuestionOption;
|
||||
import com.zhangmeng.online.exam.ui.module.Subject;
|
||||
import com.zhangmeng.online.exam.ui.service.OptionService;
|
||||
import com.zhangmeng.online.exam.ui.service.SubjectService;
|
||||
import com.zhangmeng.online.exam.ui.utils.ApiUtils;
|
||||
import com.zhangmeng.online.exam.ui.api.DataLoad;
|
||||
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.beans.property.SimpleStringProperty;
|
||||
import javafx.scene.Parent;
|
||||
|
|
@ -38,14 +47,18 @@ public class QuestionOptionDataLoad implements DataLoad {
|
|||
Map<String, SimpleStringProperty> userMap = new HashMap<>();
|
||||
userMap.put("序号", new SimpleStringProperty(user.getString("id")));
|
||||
userMap.put("选项名称", new SimpleStringProperty(user.getString("name")));
|
||||
userMap.put("选项名称_name", new SimpleStringProperty(user.getString("name")));
|
||||
userMap.put("选项内容", new SimpleStringProperty(user.getString("optionContent")));
|
||||
userMap.put("选项内容_optionContent", new SimpleStringProperty(user.getString("optionContent")));
|
||||
userMap.put("是否为正确答案", new SimpleStringProperty(user.getString("isAnswer")));
|
||||
userMap.put("是否为正确答案_isAnswer", new SimpleStringProperty(user.getString("isAnswer")));
|
||||
userMap.put("解析", new SimpleStringProperty(user.getString("explanation")));
|
||||
userMap.put("解析_explanation", new SimpleStringProperty(user.getString("explanation")));
|
||||
userMap.put("id", new SimpleStringProperty(user.getString("id")));
|
||||
userMapList.add(userMap);
|
||||
}
|
||||
|
||||
ApiUtils.DataView dataView = new ApiUtils.DataView(Arrays.asList("序号", "选项名称", "选项内容", "是否为正确答案", "解析", "id" ), userMapList).setDataLoad(this).setPageNum(pageNum).setPageSize(pageSize).setTotal(total);
|
||||
ApiUtils.DataView dataView = new ApiUtils.DataView(Arrays.asList("序号", "选项名称", "选项内容", "是否为正确答案", "解析", "id"), userMapList).setDataLoad(this).setPageNum(pageNum).setPageSize(pageSize).setTotal(total);
|
||||
dataView.setDataLoad(this);
|
||||
return dataView;
|
||||
}
|
||||
|
|
@ -64,9 +77,9 @@ public class QuestionOptionDataLoad implements DataLoad {
|
|||
public Map<String, Object> saveForm(Map<String, Object> map) {
|
||||
String result = HttpUtils.POST(ApiUtils.API_URL + "/user/save", map);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
if (jsonObject.getIntValue("code") == 200){
|
||||
if (jsonObject.getIntValue("code") == 200) {
|
||||
AlertUtils.alert_msg("保存成功!");
|
||||
}else {
|
||||
} else {
|
||||
AlertUtils.alert_warning("保存失败!");
|
||||
}
|
||||
return null;
|
||||
|
|
@ -76,11 +89,11 @@ public class QuestionOptionDataLoad implements DataLoad {
|
|||
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);
|
||||
String result = HttpUtils.POST(ApiUtils.API_URL + "/option/delete", map);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
if (jsonObject.getIntValue("code") == 200){
|
||||
if (jsonObject.getIntValue("code") == 200) {
|
||||
AlertUtils.alert_msg("删除成功!");
|
||||
}else {
|
||||
} else {
|
||||
AlertUtils.alert_warning("删除失败!");
|
||||
}
|
||||
}
|
||||
|
|
@ -88,12 +101,28 @@ public class QuestionOptionDataLoad implements DataLoad {
|
|||
@Override
|
||||
public void editData(String id, Stage stage) {
|
||||
|
||||
QuestionOption questionOption = OptionService.getQuestionOptionById(id);
|
||||
QuestionOptionForm questionOptionForm = new QuestionOptionForm();
|
||||
OptionEditController controller = questionOptionForm.getController();
|
||||
controller.setQuestionOption(questionOption);
|
||||
FxUtils.alert("编辑学科信息", (Parent) questionOptionForm, stage, true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateData(String id, String name, String oldValue, String newValue) {
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", id);
|
||||
map.put("fieldName", name);
|
||||
map.put("oldValue", oldValue == null ? "" : oldValue);
|
||||
map.put("newValue", newValue);
|
||||
String result = HttpUtils.POST(ApiUtils.API_URL + "/option/update", map);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
if (jsonObject.getIntValue("code") == 200) {
|
||||
AlertUtils.alert_msg("更新成功!");
|
||||
} else {
|
||||
AlertUtils.alert_warning("更新失败!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ public class MainController {
|
|||
case "/role/list" -> init_table(ApiUtils.getRoleList(),FxUtils.Role_DynamicTableComponent);
|
||||
case "/question/list" -> init_table(ApiUtils.getQuestionList(),FxUtils.Question_DynamicTableComponent);
|
||||
case "/subject/list" -> init_table(ApiUtils.getSubjectList(),FxUtils.Subject_DynamicTableComponent);
|
||||
case "/questionOption/list" -> init_table(ApiUtils.getQuestionOptionList(),FxUtils.QuestionOption_DynamicTableComponent);
|
||||
case "/option/list" -> init_table(ApiUtils.getQuestionOptionList(),FxUtils.QuestionOption_DynamicTableComponent);
|
||||
case "/permission/list" -> init_table(ApiUtils.getPermissionList(),FxUtils.Permission_DynamicTableComponent);
|
||||
case "/profession/list" -> init_table(ApiUtils.getProfessionList(),FxUtils.Profession_DynamicTableComponent);
|
||||
case "发布公告" -> FXMLLoader.load(getClass().getResource("/fxml/notice-edit.fxml"));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,121 @@
|
|||
package com.zhangmeng.online.exam.ui.controller;
|
||||
|
||||
import com.zhangmeng.online.exam.ui.module.QuestionOption;
|
||||
import com.zhangmeng.online.exam.ui.service.OptionService;
|
||||
import com.zhangmeng.online.exam.ui.utils.AlertUtils;
|
||||
import com.zhangmeng.online.exam.ui.utils.FxUtils;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.zhangmeng.online.exam.ui.utils.FxUtils.Question_DynamicTableComponent;
|
||||
|
||||
/**
|
||||
* @author zm
|
||||
* @date 2025/4/11 12:11
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class OptionEditController {
|
||||
|
||||
|
||||
@FXML
|
||||
public RadioButton trueRadioButton;
|
||||
|
||||
@FXML
|
||||
public RadioButton falseRadioButton;
|
||||
|
||||
@FXML
|
||||
public TextField optionNameField;
|
||||
|
||||
@FXML
|
||||
public TextField optionContentField;
|
||||
|
||||
@FXML
|
||||
public TextArea explanationTextArea;
|
||||
|
||||
private QuestionOption questionOption;
|
||||
|
||||
public void setQuestionOption(QuestionOption questionOption) {
|
||||
this.questionOption = questionOption;
|
||||
this.optionNameField.setText(questionOption.getName());
|
||||
this.optionContentField.setText(questionOption.getOptionContent());
|
||||
this.explanationTextArea.setText(questionOption.getExplanation());
|
||||
if (questionOption.isAnswer()) {
|
||||
this.trueRadioButton.setSelected(true);
|
||||
this.falseRadioButton.setSelected(false);
|
||||
} else {
|
||||
this.trueRadioButton.setSelected(false);
|
||||
this.falseRadioButton.setSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
private final SimpleBooleanProperty isFlag = new SimpleBooleanProperty(true);
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
ToggleGroup tg = new ToggleGroup();
|
||||
trueRadioButton.setToggleGroup(tg);
|
||||
trueRadioButton.setUserData(true);
|
||||
falseRadioButton.setToggleGroup(tg);
|
||||
falseRadioButton.setUserData(false);
|
||||
tg.selectToggle(trueRadioButton);//默认选项
|
||||
|
||||
tg.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
|
||||
RadioButton radioButton = (RadioButton) newValue;
|
||||
radioButton.getUserData();
|
||||
isFlag.set((boolean) radioButton.getUserData());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleSave(ActionEvent actionEvent) {
|
||||
if (optionNameField.getText().trim().isEmpty()) {
|
||||
AlertUtils.alert_warning("选项名称不能为空");
|
||||
return;
|
||||
}
|
||||
if (optionContentField.getText().trim().isEmpty()) {
|
||||
AlertUtils.alert_warning("选项内容不能为空");
|
||||
return;
|
||||
}
|
||||
Map<String, Object> option = new HashMap<>();
|
||||
option.put("id", questionOption == null ? "" : questionOption.getId());
|
||||
option.put("name", optionNameField.getText().trim());
|
||||
option.put("content", optionContentField.getText().trim());
|
||||
option.put("isFlag", isFlag.get());
|
||||
option.put("explanation", explanationTextArea.getText() == null ? "" : explanationTextArea.getText().trim());
|
||||
boolean result = OptionService.saveOption(option);
|
||||
if (result) {
|
||||
AlertUtils.alert_msg("保存成功");
|
||||
closeDialog();
|
||||
FxUtils.FX_BEANS.get(Question_DynamicTableComponent).flushData();
|
||||
}else {
|
||||
AlertUtils.alert_warning("保存失败");
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void handleCancel(ActionEvent actionEvent) {
|
||||
closeDialog();
|
||||
}
|
||||
|
||||
private void closeDialog() {
|
||||
Stage stage = (Stage) trueRadioButton.getScene().getWindow();
|
||||
stage.close();
|
||||
}
|
||||
|
||||
public QuestionOption getQuestionOption() {
|
||||
return questionOption;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package com.zhangmeng.online.exam.ui.module;
|
||||
|
||||
/**
|
||||
* @author zm
|
||||
* @date 2025/4/11 14:12
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class QuestionOption {
|
||||
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String optionContent;
|
||||
|
||||
private boolean isAnswer;
|
||||
|
||||
private String explanation;
|
||||
|
||||
|
||||
public QuestionOption() {
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getOptionContent() {
|
||||
return optionContent;
|
||||
}
|
||||
|
||||
public void setOptionContent(String optionContent) {
|
||||
this.optionContent = optionContent;
|
||||
}
|
||||
|
||||
public boolean isAnswer() {
|
||||
return isAnswer;
|
||||
}
|
||||
|
||||
public void setAnswer(boolean answer) {
|
||||
isAnswer = answer;
|
||||
}
|
||||
|
||||
public String getExplanation() {
|
||||
return explanation;
|
||||
}
|
||||
|
||||
public void setExplanation(String explanation) {
|
||||
this.explanation = explanation;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.zhangmeng.online.exam.ui.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.zhangmeng.online.exam.ui.module.QuestionOption;
|
||||
import com.zhangmeng.online.exam.ui.module.Subject;
|
||||
import com.zhangmeng.online.exam.ui.utils.AlertUtils;
|
||||
import com.zhangmeng.online.exam.ui.utils.ApiUtils;
|
||||
import com.zhangmeng.online.exam.ui.utils.FxUtils;
|
||||
import com.zhangmeng.online.exam.ui.utils.HttpUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.zhangmeng.online.exam.ui.utils.FxUtils.Permission_DynamicTableComponent;
|
||||
|
||||
/**
|
||||
* @author zm
|
||||
* @date 2025/4/11 12:20
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class OptionService {
|
||||
|
||||
public static boolean saveOption(Map<String, Object> option) {
|
||||
String result = HttpUtils.POST(ApiUtils.API_URL + "/option/save", option);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
return jsonObject.getIntValue("code") == 200;
|
||||
}
|
||||
|
||||
public static QuestionOption getQuestionOptionById(String id) {
|
||||
QuestionOption questionOption = null ;
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", id);
|
||||
String result = HttpUtils.GET(ApiUtils.API_URL + "/option/getQuestionOptionById",params);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
if (jsonObject.getIntValue("code") == 200) {
|
||||
questionOption = new QuestionOption();
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
questionOption.setId(data.getString("id"));
|
||||
questionOption.setName(data.getString("name"));
|
||||
questionOption.setOptionContent(data.getString("optionContent"));
|
||||
questionOption.setExplanation(data.getString("explanation"));
|
||||
questionOption.setAnswer(data.getBoolean("isAnswer"));
|
||||
}
|
||||
return questionOption;
|
||||
}
|
||||
}
|
||||
|
|
@ -93,6 +93,7 @@ public class ApiUtils {
|
|||
|
||||
public static DataView getQuestionOptionList() {
|
||||
DataLoad dataLoad = new QuestionOptionDataLoad();
|
||||
dataLoad.setForm(new QuestionOptionForm());
|
||||
return dataLoad.loadData(PAGE_NUM,PAGE_SIZE);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@ public class FxUtils {
|
|||
form = new SubjectForm();
|
||||
}
|
||||
|
||||
if (form instanceof QuestionOptionForm){
|
||||
form = new QuestionOptionForm();
|
||||
}
|
||||
|
||||
Scene scene = new Scene(form);
|
||||
Stage dialogStage = new Stage();
|
||||
dialogStage.setTitle(title);
|
||||
|
|
@ -90,6 +94,10 @@ public class FxUtils {
|
|||
form = new SubjectForm();
|
||||
}
|
||||
|
||||
if (form instanceof QuestionOptionForm){
|
||||
form = new QuestionOptionForm();
|
||||
}
|
||||
|
||||
Scene scene = null;
|
||||
if (!isEdit) {
|
||||
scene = new Scene(form);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
<?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.OptionEditController">
|
||||
<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"/>
|
||||
<TextField fx:id="optionNameField" GridPane.rowIndex="0" GridPane.columnIndex="1"/>
|
||||
|
||||
<!-- 选项内容 -->
|
||||
<Label text="选项内容:" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
|
||||
<TextField fx:id="optionContentField" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
|
||||
|
||||
<!-- 是否为正确答案 -->
|
||||
<Label text="是否为正确答案:" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
|
||||
<HBox GridPane.rowIndex="2" GridPane.columnIndex="1">
|
||||
<RadioButton text="是" fx:id="trueRadioButton" />
|
||||
<RadioButton text="否" fx:id="falseRadioButton" />
|
||||
</HBox>
|
||||
|
||||
|
||||
<!-- 解析 -->
|
||||
<Label text="解析:" GridPane.rowIndex="3" GridPane.columnIndex="0"/>
|
||||
<TextArea fx:id="explanationTextArea" 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>
|
||||
Loading…
Reference in New Issue