【修改】 试题录入,选择题
This commit is contained in:

committed by
陆光LG

parent
12cbdaa78a
commit
a22a77ecc1
@@ -25,3 +25,12 @@ export const removeQuestion = (ids: string[]) => {
|
||||
return request.delete({ url: '/exam/question/' + ids})
|
||||
}
|
||||
|
||||
// 新增试题
|
||||
export function addQuestion(data: any) {
|
||||
return request.post({url: '/exam/question', data});
|
||||
}
|
||||
|
||||
// 修改试题
|
||||
export function editQuestion(data: any) {
|
||||
return request.put({url: '/exam/question', data});
|
||||
}
|
@@ -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()
|
||||
}
|
||||
|
@@ -118,9 +118,11 @@
|
||||
<template #default="scope">
|
||||
<el-switch
|
||||
v-model="scope.row.status"
|
||||
:active-value="0"
|
||||
:inactive-value="1"
|
||||
active-value="0"
|
||||
inactive-value="1"
|
||||
@change="handleStatusChange(scope.row)"
|
||||
/>
|
||||
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="专业" align="center" prop="specialtyName" width="120" />
|
||||
@@ -173,35 +175,17 @@
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
@click="openForm('update', scope.row.id)"
|
||||
@click="openForm('update', scope.row.quId)"
|
||||
>
|
||||
<Icon icon="ep:edit" />修改
|
||||
</el-button>
|
||||
<el-dropdown
|
||||
@command="(command) => handleCommand(command, scope.row)"
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
@click="openForm('update', scope.row.quId)"
|
||||
>
|
||||
<el-button type="primary" link><Icon icon="ep:d-arrow-right" /> 更多</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item
|
||||
command="handleDelete"
|
||||
v-if="checkPermi(['system:user:delete'])"
|
||||
>
|
||||
<Icon icon="ep:delete" />删除
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
command="handleResetPwd"
|
||||
>
|
||||
<Icon icon="ep:key" />重置密码
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
command="handleRole"
|
||||
>
|
||||
<Icon icon="ep:circle-check" />分配角色
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<Icon icon="ep:delete" />删除
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -361,10 +345,14 @@ const findNamePathFromTreeList = (treeList: Tree[], targetId: number): string[]
|
||||
const formRef = ref()
|
||||
const cformRef = ref()
|
||||
const openForm = (type: string, id?: number) => {
|
||||
console.log(queryParams)
|
||||
if (queryParams.subjectName == "") {
|
||||
return message.confirm('请选择题型!');
|
||||
}
|
||||
if (chooseQuestionType.value.includes("选择题")){
|
||||
cformRef.value.open(type, id)
|
||||
} else {
|
||||
formRef.value.open(type, id)
|
||||
formRef.value.open(queryParams, type, id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,13 +360,11 @@ const openForm = (type: string, id?: number) => {
|
||||
const importFormRef = ref()
|
||||
|
||||
/** 修改用户状态 */
|
||||
const handleStatusChange = async (row: UserApi.UserVO) => {
|
||||
const handleStatusChange = async (row: any) => {
|
||||
try {
|
||||
// 修改状态的二次确认
|
||||
const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用'
|
||||
await message.confirm('确认要"' + text + '""' + row.username + '"用户吗?')
|
||||
await message.confirm('确认要修改' + row.quId + '"试题状态吗?')
|
||||
// 发起修改状态
|
||||
await UserApi.updateUserStatus(row.id, row.status)
|
||||
// 刷新列表
|
||||
await getList()
|
||||
} catch {
|
||||
|
Reference in New Issue
Block a user