From 420907e5d1f0505da23be79bb502f99bccda1535 Mon Sep 17 00:00:00 2001 From: 龚焕茏 <2842157468@qq.com> Date: 星期四, 13 六月 2024 16:53:58 +0800 Subject: [PATCH] feat:语音题 --- src/views/answer/components/QuestionAnswerShow.vue | 6 src/store/modules/enumItem.js | 5 src/router.js | 7 + src/views/exam/question/components/Show.vue | 2 src/views/exam/question/edit/audio.vue | 249 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 263 insertions(+), 6 deletions(-) diff --git a/src/router.js b/src/router.js index 4a24ef3..5dede70 100644 --- a/src/router.js +++ b/src/router.js @@ -166,6 +166,13 @@ name: 'shortAnswerPage', meta: { title: '绠�绛旈缂栬緫', noCache: true, activeMenu: '/exam/question/list' }, hidden: true + }, + { + path: 'question/edit/audio', + component: () => import('@/views/exam/question/edit/audio'), + name: 'audioPage', + meta: { title: '璇煶棰樼紪杈�', noCache: true, activeMenu: '/exam/question/list' }, + hidden: true } ] }, diff --git a/src/store/modules/enumItem.js b/src/store/modules/enumItem.js index 74048e4..a49585f 100644 --- a/src/store/modules/enumItem.js +++ b/src/store/modules/enumItem.js @@ -15,12 +15,13 @@ paperTypeEnum: [{ key: 1, value: '鍥哄畾璇曞嵎' }, { key: 4, value: '鏃舵璇曞嵎' }, { key: 6, value: '浠诲姟璇曞嵎' }] }, question: { - typeEnum: [{ key: 1, value: '鍗曢�夐' }, { key: 2, value: '澶氶�夐' }, { key: 3, value: '鍒ゆ柇棰�' }, { key: 4, value: '濉┖棰�' }, { key: 5, value: '绠�绛旈' }], + typeEnum: [{ key: 1, value: '鍗曢�夐' }, { key: 2, value: '澶氶�夐' }, { key: 3, value: '鍒ゆ柇棰�' }, { key: 4, value: '濉┖棰�' }, { key: 5, value: '绠�绛旈' }, { key: 6, value: '璇煶棰�' }], editUrlEnum: [{ key: 1, value: '/exam/question/edit/singleChoice', name: '鍗曢�夐' }, { key: 2, value: '/exam/question/edit/multipleChoice', name: '澶氶�夐' }, { key: 3, value: '/exam/question/edit/trueFalse', name: '鍒ゆ柇棰�' }, { key: 4, value: '/exam/question/edit/gapFilling', name: '濉┖棰�' }, - { key: 5, value: '/exam/question/edit/shortAnswer', name: '绠�绛旈' }] + { key: 5, value: '/exam/question/edit/shortAnswer', name: '绠�绛旈' }, + { key: 6, value: '/exam/question/edit/audio', name: '璇煶棰�' }] } } } diff --git a/src/views/answer/components/QuestionAnswerShow.vue b/src/views/answer/components/QuestionAnswerShow.vue index 3258152..087f037 100644 --- a/src/views/answer/components/QuestionAnswerShow.vue +++ b/src/views/answer/components/QuestionAnswerShow.vue @@ -1,7 +1,7 @@ <template> <div v-loading="qLoading" style="line-height:1.8"> - <div v-if="qType == 1 || qType == 2 || qType == 3 || qType == 4 || qType == 5"> - <div v-if="qType == 1"> + <div v-if="qType == 1 || qType == 2 || qType == 3 || qType == 4 || qType == 5 || qType == 6"> + <div v-if="qType == 1 || qType == 6"> <div class="q-title" v-html="question.title" /> <div class="q-content"> <el-radio-group v-model="answer.content"> @@ -69,7 +69,7 @@ </div> <div class="question-answer-show-item"> <span class="question-show-item">姝g‘绛旀锛�</span> - <span v-if="qType == 1 || qType == 2 || qType == 5" v-html="question.correct" class="q-item-span-content" /> + <span v-if="qType == 1 || qType == 2 || qType == 5 || qType == 6" v-html="question.correct" class="q-item-span-content" /> <span v-if="qType == 3" v-html="trueFalseFormatter(question)" class="q-item-span-content" /> <span v-if="qType == 4">{{ question.correctArray }}</span> </div> diff --git a/src/views/exam/question/components/Show.vue b/src/views/exam/question/components/Show.vue index b1f3757..468780b 100644 --- a/src/views/exam/question/components/Show.vue +++ b/src/views/exam/question/components/Show.vue @@ -1,6 +1,6 @@ <template> <div style="line-height:1.8"> - <div v-if="qType==1" v-loading="qLoading"> + <div v-if="qType==1 || qType == 6" v-loading="qLoading"> <div class="q-title" v-html="question.title"/> <div class="q-content"> <span :key="item.id" v-for="item in question.items" class="q-item-contain"> diff --git a/src/views/exam/question/edit/audio.vue b/src/views/exam/question/edit/audio.vue new file mode 100644 index 0000000..7f88df7 --- /dev/null +++ b/src/views/exam/question/edit/audio.vue @@ -0,0 +1,249 @@ +<template> + <div class="app-container"> + <el-form :model="form" ref="form" label-width="100px" v-loading="formLoading" :rules="rules"> + <el-form-item label="瀛︾锛�" prop="subjectId" required> + <el-select v-model="form.subjectId" placeholder="瀛︾"> + <el-option v-for="item in subjects" :key="item.id" :value="item.id" :label="item.name"></el-option> + </el-select> + </el-form-item> + <el-form-item label="棰樺共锛�" prop="title" required> + <el-input v-model="form.title" @focus="inputClick(form, 'title')" /> + </el-form-item> + <el-form-item label="璇煶锛�" prop="audioFile" required> + <el-upload v-model="form.audioFile" :action="uploadUrl" :limit="1" accept="audio/*" :on-success="uploadSuccess" + :file-list="audioList"> + <el-button size="small" type="primary">鐐瑰嚮涓婁紶</el-button> + </el-upload> + </el-form-item> + <el-form-item label="閫夐」锛�" required> + <el-form-item :label="item.prefix" :key="item.prefix" v-for="(item, index) in form.items" label-width="50px" + class="question-item-label"> + <el-input v-model="item.prefix" style="width:50px;" /> + <el-input v-model="item.content" @focus="inputClick(item, 'content')" class="question-item-content-input" /> + <el-button type="danger" size="mini" class="question-item-remove" icon="el-icon-delete" + @click="questionItemRemove(index)"></el-button> + </el-form-item> + </el-form-item> + <el-form-item label="瑙f瀽锛�" prop="analyze" required> + <el-input v-model="form.analyze" @focus="inputClick(form, 'analyze')" /> + </el-form-item> + <el-form-item label="闅惧害锛�" required> + <el-rate v-model="form.difficult" class="question-item-rate"></el-rate> + </el-form-item> + <el-form-item label="姝g‘绛旀锛�" prop="correct" required> + <el-radio-group v-model="form.correct"> + <el-radio v-for="item in form.items" :key="item.prefix" :label="item.prefix">{{ item.prefix }}</el-radio> + </el-radio-group> + </el-form-item> + <el-form-item> + <el-button type="primary" @click="submitForm">鎻愪氦</el-button> + <el-button @click="resetForm">閲嶇疆</el-button> + <el-button type="success" @click="questionItemAdd">娣诲姞閫夐」</el-button> + <el-button type="success" @click="showQuestion">棰勮</el-button> + </el-form-item> + </el-form> + <el-dialog :visible.sync="richEditor.dialogVisible" append-to-body :close-on-click-modal="false" + style="width: 100%;height: 100%" :show-close="false" center> + <Ueditor @ready="editorReady" /> + <span slot="footer" class="dialog-footer"> + <el-button type="primary" @click="editorConfirm">纭� 瀹�</el-button> + <el-button @click="richEditor.dialogVisible = false">鍙� 娑�</el-button> + </span> + </el-dialog> + <el-dialog :visible.sync="questionShow.dialog" style="width: 100%;height: 100%"> + <QuestionShow :qType="questionShow.qType" :question="questionShow.question" :qLoading="questionShow.loading" /> + </el-dialog> + </div> +</template> + +<script> +import QuestionShow from '../components/Show' +import Ueditor from '@/components/Ueditor' +import { mapGetters, mapState, mapActions } from 'vuex' +import questionApi from '@/api/question' + +export default { + components: { + Ueditor, QuestionShow + }, + data() { + return { + audioList: [], + uploadUrl: '/api/upload/upload', + form: { + audioFile: '', + originalFile: '', + id: null, + questionType: 6, + gradeLevel: null, + subjectId: null, + title: '', + items: [ + { prefix: 'A', content: '' }, + { prefix: 'B', content: '' }, + { prefix: 'C', content: '' }, + { prefix: 'D', content: '' } + ], + analyze: '', + correct: '', + score: '', + difficult: 0 + }, + subjectFilter: null, + formLoading: false, + rules: { + audioFile: [ + { required: true, message: '璇蜂笂浼犺闊�', trigger: 'blur' } + ], + gradeLevel: [ + { required: true, message: '璇烽�夋嫨骞寸骇', trigger: 'change' } + ], + subjectId: [ + { required: true, message: '璇烽�夋嫨瀛︾', trigger: 'change' } + ], + title: [ + { required: true, message: '璇疯緭鍏ラ骞�', trigger: 'blur' } + ], + analyze: [ + { required: true, message: '璇疯緭鍏ヨВ鏋�', trigger: 'blur' } + ], + score: [ + { required: true, message: '璇疯緭鍏ュ垎鏁�', trigger: 'blur' } + ], + correct: [ + { required: true, message: '璇烽�夋嫨姝g‘绛旀', trigger: 'change' } + ] + }, + richEditor: { + dialogVisible: false, + object: null, + parameterName: '', + instance: null + }, + questionShow: { + qType: 0, + dialog: false, + question: null, + loading: false + } + } + }, + created() { + let id = this.$route.query.id + let _this = this + this.initSubject(function () { + _this.subjectFilter = _this.subjects + }) + if (id && parseInt(id) !== 0) { + _this.formLoading = true + questionApi.select(id).then(re => { + _this.form = re.data + _this.audioList.push({ name: re.data.originalFile, url: re.data.audioFile }) + _this.formLoading = false + }) + } + }, + methods: { + uploadSuccess(response) { + this.form.audioFile = response.data.url; + this.form.originalFile = response.data.name; + }, + editorReady(instance) { + this.richEditor.instance = instance + let currentContent = this.richEditor.object[this.richEditor.parameterName] + this.richEditor.instance.setContent(currentContent) + // 鍏夋爣瀹氫綅鍒癠editor + this.richEditor.instance.focus(true) + }, + inputClick(object, parameterName) { + this.richEditor.object = object + this.richEditor.parameterName = parameterName + this.richEditor.dialogVisible = true + }, + editorConfirm() { + let content = this.richEditor.instance.getContent() + this.richEditor.object[this.richEditor.parameterName] = content + this.richEditor.dialogVisible = false + }, + questionItemRemove(index) { + this.form.items.splice(index, 1) + }, + questionItemAdd() { + let items = this.form.items + let newLastPrefix + if (items.length > 0) { + let last = items[items.length - 1] + newLastPrefix = String.fromCharCode(last.prefix.charCodeAt() + 1) + } else { + newLastPrefix = 'A' + } + items.push({ id: null, prefix: newLastPrefix, content: '' }) + }, + submitForm() { + let _this = this + this.$refs.form.validate((valid) => { + if (valid) { + this.formLoading = true + questionApi.edit(this.form).then(re => { + if (re.code === 1) { + _this.$message.success(re.message) + _this.delCurrentView(_this).then(() => { + _this.$router.push('/exam/question/list') + }) + } else { + _this.$message.error(re.message) + this.formLoading = false + } + }).catch(e => { + this.formLoading = false + }) + } else { + return false + } + }) + }, + resetForm() { + let lastId = this.form.id + this.$refs['form'].resetFields() + this.form = { + id: null, + questionType: 1, + gradeLevel: null, + subjectId: null, + title: '', + items: [ + { prefix: 'A', content: '' }, + { prefix: 'B', content: '' }, + { prefix: 'C', content: '' }, + { prefix: 'D', content: '' } + ], + analyze: '', + correct: '', + score: '', + difficult: 0 + } + this.form.id = lastId + this.audioList = [] + }, + levelChange() { + this.form.subjectId = null + this.subjectFilter = this.subjects.filter(data => data.level === this.form.gradeLevel) + }, + showQuestion() { + this.questionShow.dialog = true + this.questionShow.qType = this.form.questionType + this.questionShow.question = this.form + }, + ...mapActions('exam', { initSubject: 'initSubject' }), + ...mapActions('tagsView', { delCurrentView: 'delCurrentView' }) + }, + computed: { + ...mapGetters('enumItem', ['enumFormat']), + ...mapState('enumItem', { + questionTypeEnum: state => state.exam.question.typeEnum, + levelEnum: state => state.user.levelEnum + }), + ...mapState('exam', { subjects: state => state.subjects }) + } +} +</script> -- Gitblit v1.8.0