北斗应用技术培训考试管理系统
This commit is contained in:
129
src/components/addNewData/trainindTopic/judgment/singleAdd.vue
Normal file
129
src/components/addNewData/trainindTopic/judgment/singleAdd.vue
Normal file
@@ -0,0 +1,129 @@
|
||||
<template>
|
||||
<el-form
|
||||
ref="ruleFormRef"
|
||||
style="max-width: 600px"
|
||||
:model="ruleForm"
|
||||
:rules="rules"
|
||||
label-width="auto"
|
||||
size="default"
|
||||
status-icon
|
||||
class="mx-auto"
|
||||
>
|
||||
<el-form-item class="mx-1 font-bold" label="题干" prop="stem">
|
||||
<el-input
|
||||
clearable
|
||||
placeholder="请输入题干"
|
||||
v-model="ruleForm.stem"
|
||||
@input="filter(ruleForm.stem, 'stem')"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item class="mx-1 font-bold" label="答案" prop="answer">
|
||||
<el-select
|
||||
clearable
|
||||
size="small"
|
||||
placeholder="请选择答案"
|
||||
autocomplete="off"
|
||||
v-model="ruleForm.answer"
|
||||
style="width: 100%; font-size: 1rem"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in addData.answerOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
class="text-center"
|
||||
:style="item.style"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item class="mx-1 font-bold" label="难度" prop="difficulty">
|
||||
<el-select
|
||||
clearable
|
||||
size="small"
|
||||
placeholder="请选择难度"
|
||||
autocomplete="off"
|
||||
v-model="ruleForm.difficulty"
|
||||
style="width: 100%; font-size: 1rem"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in addData.difficultyOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
class="text-center"
|
||||
:style="item.style"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive } from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
|
||||
const ruleFormRef = ref(null);
|
||||
|
||||
const ruleForm = reactive({
|
||||
stem: "",
|
||||
answer: "",
|
||||
difficulty: "",
|
||||
});
|
||||
|
||||
const formClone = ref({});
|
||||
|
||||
const rules = reactive({
|
||||
stem: [{ required: true, message: "请输入题干", trigger: "blur" }],
|
||||
answer: [{ required: true, message: "请选择答案", trigger: "change" }],
|
||||
difficulty: [{ required: true, message: "请选择难度", trigger: "change" }],
|
||||
});
|
||||
|
||||
const emit = defineEmits(["addJudgment"]);
|
||||
|
||||
const filter = (value, label) => {
|
||||
if (/[=\s"'+-]/.test(value)) {
|
||||
if (ruleForm[label]) {
|
||||
ruleForm[label] = value.replace(/[=\s"'+-]/g, "");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const props = defineProps({
|
||||
addData: Object,
|
||||
});
|
||||
|
||||
const resetCheckForm = () => {
|
||||
if (!ruleFormRef) return;
|
||||
ruleFormRef.value.resetFields();
|
||||
};
|
||||
|
||||
const confirm = async () => {
|
||||
if (!ruleFormRef) return;
|
||||
await ruleFormRef.value.validate((valid) => {
|
||||
if (valid) {
|
||||
formClone.value = { ...ruleForm };
|
||||
emit("addJudgment", [formClone.value]);
|
||||
ruleFormRef.value.resetFields();
|
||||
ElMessage({
|
||||
message: `提交成功!`,
|
||||
type: "success",
|
||||
});
|
||||
} else {
|
||||
ElMessage.error("提交失败!");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const validate = () => {
|
||||
if (!ruleFormRef) return Promise.resolve(false);
|
||||
return new Promise((resolve) => {
|
||||
ruleFormRef.value.validate((valid) => {
|
||||
resolve(valid);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
defineExpose({ resetCheckForm, confirm, validate, ruleForm, formClone });
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
Reference in New Issue
Block a user