【修改】 试题录入,选择题
This commit is contained in:
@@ -13,19 +13,31 @@
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="专业" prop="specialtyName">
|
||||
<el-input v-model="formData.specialtyName" placeholder="请输入专业" />
|
||||
<el-input v-model="formData.specialtyName" placeholder="请输入专业" disabled/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="试题名称" prop="quBankName">
|
||||
<el-input v-model="formData.quBankName" placeholder="请输入专业" />
|
||||
<el-input v-model="formData.quBankName" placeholder="请试题名称" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="课程" prop="courseName">
|
||||
<el-input v-model="formData.courseName" placeholder="请输入课程" disabled/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="题库" prop="required">
|
||||
<el-input v-model="formData.required" placeholder="请输入手机题库" />
|
||||
<el-input v-model="formData.required" placeholder="请选择题库" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="题型难度" prop="quLevel">
|
||||
<el-input v-model="formData.quLevel" placeholder="请输入题型难度" disabled/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
@@ -36,8 +48,40 @@
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="课程" prop="courseName">
|
||||
<el-input v-model="formData.courseName" placeholder="请输入课程" />
|
||||
<el-form-item label="知识点" prop="pointNames">
|
||||
<el-input v-model="formData.pointNames" placeholder="请输入知识点" disabled/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="审核状态" prop="audit">
|
||||
<el-input v-model="formData.audit" placeholder="请输入审核状态" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="题型" prop="subjectName">
|
||||
<el-input v-model="formData.subjectName" placeholder="请输入题型" disabled/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="启用状态" prop="status">
|
||||
<el-radio-group v-model="formData.status">
|
||||
<el-radio
|
||||
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
|
||||
:key="dict.value"
|
||||
:value="dict.value"
|
||||
>
|
||||
{{ dict.label }}
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="来源" prop="resourceValue">
|
||||
<el-input v-model="formData.resourceValue" placeholder="请输入来源" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@@ -237,14 +281,10 @@
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||
import { CommonStatusEnum } from '@/utils/constants'
|
||||
import { defaultProps, handleTree } from '@/utils/tree'
|
||||
import * as PostApi from '@/api/system/post'
|
||||
import * as DeptApi from '@/api/system/dept'
|
||||
import * as UserApi from '@/api/system/user'
|
||||
import { FormRules } from 'element-plus'
|
||||
import * as QuestionApi from '@/api/paper/question'
|
||||
|
||||
defineOptions({ name: 'SystemUserForm' })
|
||||
defineOptions({ name: 'ChoiceForm' })
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
@@ -260,14 +300,18 @@ const formData = ref({
|
||||
quBankName: '',
|
||||
required: '',
|
||||
chapteridDictText: '',
|
||||
analysis: ''
|
||||
analysis: '',
|
||||
quLevel: '',
|
||||
pointNames: '',
|
||||
audit: '',
|
||||
subjectName: '',
|
||||
status: '',
|
||||
resourceValue: ''
|
||||
})
|
||||
const formRules = reactive<FormRules>({
|
||||
specialtyName: [{ required: true, message: '用户名称不能为空', trigger: 'blur' }]
|
||||
// specialtyName: [{ required: true, message: '用户名称不能为空', trigger: 'blur' }]
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
const deptList = ref<Tree[]>([]) // 树形结构
|
||||
const postList = ref([] as PostApi.PostVO[]) // 岗位列表
|
||||
// 左侧试题描述
|
||||
const leftActiveName = ref('desc')
|
||||
// 右侧tab
|
||||
@@ -327,53 +371,94 @@ const handleDocumentSelectionChange = (val: any) => {
|
||||
}
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
const open = async (queryParams: any ,type: string, id?: number) => {
|
||||
dialogVisible.value = true
|
||||
dialogTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
resetForm()
|
||||
|
||||
// 修改时,设置数据
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await UserApi.getUser(id)
|
||||
formData.value = await QuestionApi.getQuestion(id)
|
||||
for (let i = 0; i < formData.value.answerList.length; i++) {
|
||||
if (formData.value.answerList[i].isRight === '0') {
|
||||
let num = Number(i);
|
||||
let nums = '';
|
||||
if (num >= 0 && num <= 25) {
|
||||
nums = String.fromCharCode(num + 65);
|
||||
} else {
|
||||
return '请输入 0-25 之间的数字';
|
||||
}
|
||||
radio.value = nums;
|
||||
}
|
||||
optionsContent[i + 1] = formData.value.answerList[i].content;
|
||||
}
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
} else {
|
||||
formData.value.specialtyName = queryParams.specialtyName
|
||||
formData.value.courseName = queryParams.courseName
|
||||
formData.value.subjectName = queryParams.subjectName
|
||||
}
|
||||
// 加载部门树
|
||||
deptList.value = handleTree(await DeptApi.getSimpleDeptList())
|
||||
// 加载岗位列表
|
||||
postList.value = await PostApi.getSimplePostList()
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
// 转换函数:将大写字母 A-Z 映射为 0-25
|
||||
const mappedNumber = computed(() => {
|
||||
const char = radio.value.toUpperCase();
|
||||
const code = char.charCodeAt(0);
|
||||
if (code >= 65 && code <= 90) {
|
||||
return code - 65;
|
||||
} else {
|
||||
return '请输入 A-Z 的字母';
|
||||
}
|
||||
});
|
||||
// 选择答案数据
|
||||
const answerData = ref([]);
|
||||
/** 提交表单 */
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
const submitForm = async () => {
|
||||
const values = Object.values(optionsContent);
|
||||
console.log(values)
|
||||
// 校验表单
|
||||
if (!formRef) return
|
||||
const valid = await formRef.value.validate()
|
||||
if (!valid) return
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formData.value as unknown as UserApi.UserVO
|
||||
if (formType.value === 'create') {
|
||||
await UserApi.createUser(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await UserApi.updateUser(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
// 组合数据 (选择题)
|
||||
// 创建临时字段
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
let data = {};
|
||||
data.content = values[i];
|
||||
data.sort = i;
|
||||
// 判断正确答案
|
||||
if (mappedNumber.value === i) {
|
||||
data.isRight = '0';
|
||||
} else {
|
||||
data.isRight = '1';
|
||||
}
|
||||
answerData.value.push(data);
|
||||
}
|
||||
formData.value.answerList = answerData.value;
|
||||
console.log(formData.value.answerList)
|
||||
// 校验表单
|
||||
if (!formRef) return
|
||||
const valid = await formRef.value.validate()
|
||||
if (!valid) return
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formData.value as unknown
|
||||
if (formType.value === 'create') {
|
||||
await QuestionApi.addQuestion(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await QuestionApi.editQuestion(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
// 发送操作成功的事件
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
dialogVisible.value = false
|
||||
// 发送操作成功的事件
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
@@ -385,7 +470,13 @@ const resetForm = () => {
|
||||
quBankName: '',
|
||||
required: '',
|
||||
chapteridDictText: '',
|
||||
analysis: ''
|
||||
analysis: '',
|
||||
quLevel: '',
|
||||
pointNames: '',
|
||||
audit: '',
|
||||
subjectName: '',
|
||||
status: '',
|
||||
resourceValue: ''
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
Reference in New Issue
Block a user