| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- <template>
- <div class="app-container">
- <a-form :model="form" ref="formRef" :rules="rules" layout="vertical">
- <!-- <a-form-item label="年级:" name="gradeLevel" required>
- <a-select v-model:value="form.gradeLevel" placeholder="年级" @change="levelChange">
- <a-select-option v-for="item in levelEnum" :key="item.key" :value="item.key">
- {{ item.value }}
- </a-select-option>
- </a-select>
- </a-form-item>
- <a-form-item label="学科:" name="subjectId" required>
- <a-select v-model:value="form.subjectId" placeholder="学科">
- <a-select-option v-for="item in subjectFilter" :key="item.id" :value="item.id">
- {{ item.name + ' ( ' + item.levelName + ' )' }}
- </a-select-option>
- </a-select>
- </a-form-item> -->
- <a-form-item label="学期" name="semesterId" :rules="rules.semesterId">
- <a-select v-model:value="form.semesterId" placeholder="请选择学期" allowClear @change="handleSemesterChange">
- <a-select-option v-for="item in semesterList" :key="item.id" :value="item.id">
- {{ item.name }}
- </a-select-option>
- </a-select>
- </a-form-item>
- <!-- <a-form-item label="专业" name="majorId">
- <a-select v-model:value="form.majorId" placeholder="请选择专业" allowClear @change="handleMajorChange">
- <a-select-option v-for="item in majorList" :key="item.id" :value="item.id">
- {{ item.majorName }}
- </a-select-option>
- </a-select>
- </a-form-item> -->
- <a-form-item label="课程" name="courseId" :rules="rules.courseId">
- <a-select v-model:value="form.courseId" placeholder="请选择课程" allowClear :disabled="!form.semesterId">
- <a-select-option v-for="item in courseList" :key="item.courseId" :value="item.courseId">
- {{ item.courseName }}
- </a-select-option>
- </a-select>
- </a-form-item>
- <a-form-item label="题库类型:" name="bankType" required>
- <a-select v-model:value="form.bankType" placeholder="题库类型">
- <a-select-option v-for="item in bankTypeEnum" :key="item.key" :value="item.key">
- {{ item.value }}
- </a-select-option>
- </a-select>
- </a-form-item>
- <a-form-item label="题干:" name="title" required>
- <div v-if="form.title" class="rich-text-preview" v-html="form.title" @click="inputClick(form, 'title')"></div>
- <a-input
- v-else
- v-model:value="form.title"
- readonly
- placeholder="点击编辑题干内容"
- @click="inputClick(form, 'title')"
- />
- </a-form-item>
- <a-form-item label="答案:" name="correct" required>
- <div
- v-if="form.correct"
- class="rich-text-preview"
- v-html="form.correct"
- @click="inputClick(form, 'correct')"
- ></div>
- <a-input
- v-else
- v-model:value="form.correct"
- readonly
- placeholder="点击编辑答案内容"
- @click="inputClick(form, 'correct')"
- />
- </a-form-item>
- <a-form-item label="解析:" name="analyze" required>
- <div
- v-if="form.analyze"
- class="rich-text-preview"
- v-html="form.analyze"
- @click="inputClick(form, 'analyze')"
- ></div>
- <a-input
- v-else
- v-model:value="form.analyze"
- readonly
- placeholder="点击编辑解析内容"
- @click="inputClick(form, 'analyze')"
- />
- </a-form-item>
- <a-form-item v-if="form.bankType !== '2'" label="分数:" name="score" required>
- <a-input-number v-model:value="form.score" :precision="1" :step="1" :max="100" :min="0"/>
- </a-form-item>
- <a-form-item label="难度:" required>
- <a-rate v-model:value="form.difficult" class="question-item-rate" />
- </a-form-item>
- <a-form-item>
- <a-button type="primary" @click="submitForm" :loading="formLoading">提交</a-button>
- <a-button @click="resetForm">重置</a-button>
- <a-button type="success" @click="showQuestion">预览</a-button>
- </a-form-item>
- </a-form>
- <a-modal
- v-model:visible="richEditor.dialogVisible"
- width="70%"
- :footer="null"
- :closable="false"
- centered
- destroy-on-close
- >
- <Editor v-model="richEditorContent" :toolbar="toolbar" :height="300" />
- <div style="text-align: right; margin-top: 16px">
- <a-button type="primary" @click="editorConfirm">确定</a-button>
- <a-button @click="richEditor.dialogVisible = false">取消</a-button>
- </div>
- </a-modal>
- <a-modal v-model:visible="questionShow.dialog" width="800px" :footer="null" :bodyStyle="{ padding: '24px' }">
- <QuestionShow :qType="questionShow.qType" :question="questionShow.question" :qLoading="questionShow.loading" />
- </a-modal>
- </div>
- </template>
- <script setup>
- import { ref, reactive, computed, onMounted } from 'vue'
- import { message } from 'ant-design-vue'
- import { useExamStore } from '@/store/exam'
- import tQuestionApi from '@/api/exam/question/tQuestionApi'
- import QuestionShow from '../components/Show.vue'
- import Editor from '@/components/Editor/index.vue'
- import '../style/common.less'
- import resourceAuditApi from '@/api/resourceAudit.js'
- const bankTypeEnum = computed(() => examStore.getBankTypeEnum)
- const toolbar = computed(() => examStore.toolbar)
- const examStore = useExamStore()
- const props = defineProps({
- id: {
- type: Number,
- default: 0
- }
- })
- const emit = defineEmits(['successful'])
- const formRef = ref()
- const semesterList = ref([])
- const majorList = ref([])
- const courseList = ref([])
- const form = reactive({
- id: null,
- questionType: 5,
- // gradeLevel: null,
- // subjectId: null,
- title: '',
- items: [],
- analyze: '',
- correct: '',
- score: '',
- difficult: 0,
- bankType: null,
- courseId: null,
- semesterId: null,
- majorId: null
- })
- const subjectFilter = ref([])
- const formLoading = ref(false)
- const rules = {
- bankType: [{ required: true, message: '请选择题库类型', trigger: 'change' }],
- gradeLevel: [{ required: true, message: '请选择年级', trigger: 'change' }],
- subjectId: [{ required: true, message: '请选择学科', trigger: 'change' }],
- title: [{ required: true, message: '请输入题干', trigger: 'blur' }],
- correct: [{ required: true, message: '请输入答案', trigger: 'blur' }],
- analyze: [{ required: true, message: '请输入解析', trigger: 'blur' }],
- score: [{ required: true, message: '请输入分数', trigger: 'blur' }],
- semesterId: [{ required: true, message: '请选择学期', trigger: 'change' }],
- courseId: [{ required: true, message: '请选择课程', trigger: 'change' }]
- }
- const richEditor = reactive({
- dialogVisible: false,
- object: null,
- parameterName: '',
- instance: null
- })
- const richEditorContent = ref('')
- const questionShow = reactive({
- qType: 0,
- dialog: false,
- question: null,
- loading: false
- })
- const levelEnum = computed(() => examStore.levelEnum)
- const subjects = computed(() => examStore.subjects)
- onMounted(async () => {
- await examStore.initSubject()
- subjectFilter.value = subjects.value
- const id = props.id
- if (id && parseInt(id) !== 0) {
- formLoading.value = true
- tQuestionApi.select(id).then((re) => {
- Object.assign(form, re)
- formLoading.value = false
- // 如果是编辑模式,需要根据已有数据加载相应的课程列表
- if (re.semesterId) {
- // 直接加载课程列表
- loadCourseList()
- }
- })
- }
- // 加载学期列表
- const semesterLoading = message.loading('正在加载学期列表...', 0)
- resourceAuditApi
- .semesterDownList()
- .then((res) => {
- if (res.code === 200) {
- semesterList.value = res.data
- } else {
- message.error('加载学期列表失败:' + (res.msg || '未知错误'))
- }
- })
- .catch((err) => {
- message.error('加载学期列表失败:' + (err.message || '网络错误'))
- })
- .finally(() => {
- semesterLoading()
- })
- // 加载专业
- // const majorLoading = message.loading('正在加载专业列表...', 0)
- // resourceAuditApi
- // .majordownList()
- // .then((res) => {
- // if (res.code === 200) {
- // majorList.value = res.data
- // } else {
- // message.error('加载专业列表失败:' + (res.msg || '未知错误'))
- // }
- // })
- // .catch((err) => {
- // message.error('加载专业列表失败:' + (err.message || '网络错误'))
- // })
- // .finally(() => {
- // majorLoading()
- // })
- })
- // 学期变更处理函数
- const handleSemesterChange = (value) => {
- form.courseId = null
- courseList.value = []
- // 如果学期和专业都已选择,则查询课程列表
- if (value) {
- loadCourseList()
- }
- }
- // 专业变更处理函数
- // const handleMajorChange = (value) => {
- // form.courseId = null
- // courseList.value = []
- // // 如果学期和专业都已选择,则查询课程列表
- // if (value && form.semesterId) {
- // loadCourseList()
- // }
- // }
- // 加载课程列表
- const loadCourseList = () => {
- // 添加加载状态
- const courseLoading = message.loading('正在加载课程列表...', 0)
- // 根据选择的学期和专业加载课程列表
- resourceAuditApi
- .courseAllList({
- semesterId: form.semesterId,
- majorId: form.majorId
- })
- .then((res) => {
- if (res.code === 200) {
- courseList.value = res.data
- } else {
- message.error('加载课程列表失败:' + (res.msg || '未知错误'))
- }
- })
- .catch((err) => {
- message.error('加载课程列表失败:' + (err.message || '网络错误'))
- })
- .finally(() => {
- courseLoading()
- })
- }
- function inputClick(object, parameterName) {
- richEditor.object = object
- richEditor.parameterName = parameterName
- richEditorContent.value = object[parameterName] || ''
- richEditor.dialogVisible = true
- }
- function editorConfirm() {
- richEditor.object[richEditor.parameterName] = richEditorContent.value
- richEditor.dialogVisible = false
- }
- function submitForm() {
- formRef.value.validate().then((valid) => {
- if (valid) {
- formLoading.value = true
- tQuestionApi
- .edit(form)
- .then(() => {
- emit('successful')
- formLoading.value = false
- })
- .catch(() => {
- formLoading.value = false
- })
- }
- })
- }
- function resetForm() {
- const lastId = form.id
- formRef.value.resetFields()
- Object.assign(form, {
- id: null,
- questionType: 5,
- // gradeLevel: null,
- // subjectId: null,
- semesterId: null,
- majorId: null,
- courseId: null,
- title: '',
- items: [],
- analyze: '',
- correct: '',
- score: '',
- bankType: null,
- difficult: 0
- })
- form.id = lastId
- majorList.value = [] // 清空专业列表
- courseList.value = [] // 清空课程列表
- }
- function levelChange() {
- form.subjectId = null
- subjectFilter.value = subjects.value.filter((data) => data.level === form.gradeLevel)
- }
- function showQuestion() {
- questionShow.dialog = true
- questionShow.qType = form.questionType
- questionShow.question = { ...form }
- }
- </script>
- <style lang="less" scoped>
- .app-container {
- background: #fff;
- padding: 24px;
- border-radius: 8px;
- }
- </style>
|