This commit is contained in:
alvis
2020-07-16 14:12:31 +08:00
parent 1c159a7bad
commit f746aef851
2140 changed files with 7218 additions and 4689 deletions

View File

@@ -0,0 +1,62 @@
<template>
<div style="line-height:1.8">
<div v-if="qType==1" 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">
<span class="q-item-prefix">{{item.prefix}}</span>
<span v-html="item.content" class="q-item-content"></span>
</span>
</div>
</div>
<div v-else-if="qType==2" 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">
<span class="q-item-prefix">{{item.prefix}}</span>
<span v-html="item.content" class="q-item-content"></span>
</span>
</div>
</div>
<div v-else-if="qType==3" v-loading="qLoading">
<div class="q-title" v-html="question.title" style="display: inline;margin-right: 10px"/>
<span></span>
<span :key="item.id" v-for="item in question.items">
<span v-html="item.content" class="q-item-content"></span>
</span>
<span></span>
</div>
<div v-else-if="qType==4" v-loading="qLoading">
<div class="q-title" v-html="question.title"/>
</div>
<div v-else-if="qType==5" v-loading="qLoading">
<div class="q-title" v-html="question.title"/>
</div>
<div v-else>
</div>
</div>
</template>
<script>
export default {
name: 'QuestionShow',
props: {
question: {
type: Object,
default: function () {
return {}
}
},
qLoading: {
type: Boolean,
default: false
},
qType: {
type: Number,
default: 0
}
},
methods: {}
}
</script>

View File

@@ -0,0 +1,225 @@
<template>
<div class="app-container">
<el-form :model="form" ref="form" label-width="100px" v-loading="formLoading" :rules="rules">
<el-form-item label="年级:" prop="gradeLevel" required>
<el-select v-model="form.gradeLevel" placeholder="年级" @change="levelChange">
<el-option v-for="item in levelEnum" :key="item.key" :value="item.key" :label="item.value"></el-option>
</el-select>
</el-form-item>
<el-form-item label="学科:" prop="subjectId" required>
<el-select v-model="form.subjectId" placeholder="学科" >
<el-option v-for="item in subjectFilter" :key="item.id" :value="item.id" :label="item.name+' ( '+item.levelName+' )'"></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="填空答案:" required>
<el-form-item :label="item.prefix" :key="item.prefix" v-for="item in form.items" label-width="50px" class="question-item-label">
<el-input v-model="item.content" @focus="inputClick(item,'content')" class="question-item-content-input" style="width: 80%"/>
<span class="question-item-span">分数</span><el-input-number v-model="item.score" :precision="1" :step="1" :max="100" ></el-input-number>
</el-form-item>
</el-form-item>
<el-form-item label="解析:" prop="analyze" required>
<el-input v-model="form.analyze" @focus="inputClick(form,'analyze')" />
</el-form-item>
<el-form-item label="分数:" prop="score" required>
<el-input-number v-model="form.score" :precision="1" :step="1" :max="100"></el-input-number>
</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>
<el-button type="primary" @click="submitForm">提交</el-button>
<el-button @click="resetForm">重置</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 {
form: {
id: null,
questionType: 4,
gradeLevel: null,
subjectId: null,
title: '',
items: [
],
analyze: '',
correct: '',
score: '',
difficult: 0
},
subjectFilter: null,
formLoading: false,
rules: {
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' }
]
},
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.response
_this.formLoading = false
})
}
},
methods: {
editorReady (instance) {
this.richEditor.instance = instance
let currentContent = this.richEditor.object[this.richEditor.parameterName]
this.richEditor.instance.setContent(currentContent)
// 光标定位到Ueditor
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()
if (this.richEditor.parameterName === 'title') { // 题干的正确答案重置
if (this.questionItemReset(content)) {
this.richEditor.object[this.richEditor.parameterName] = content
this.richEditor.dialogVisible = false
} else {
}
} else {
this.richEditor.object[this.richEditor.parameterName] = content
this.richEditor.dialogVisible = false
}
},
questionItemReset (content) {
let spanRegex = new RegExp('<span class="gapfilling-span (.*?)">(.*?)<\\/span>', 'g')
let _this = this
let newFormItem = []
let gapfillingItems = content.match(spanRegex)
if (gapfillingItems === null) {
this.$message.error('请插入填空')
return false
}
gapfillingItems.forEach(function (span, index) {
let pairRegex = /<span class="gapfilling-span (.*?)">(.*?)<\/span>/
pairRegex.test(span)
newFormItem.push({ id: null, prefix: RegExp.$2, content: '', score: '0' })
})
newFormItem.forEach(function (item) {
_this.form.items.some((oldItem, index) => {
if (oldItem.itemUuid === item.itemUuid) {
item.content = oldItem.content
item.id = oldItem.id
item.score = oldItem.score
return true
}
})
})
_this.form.items = newFormItem
return true
},
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
}
})
},
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
},
resetForm () {
this.$refs['form'].resetFields()
},
...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>

View File

@@ -0,0 +1,212 @@
<template>
<div class="app-container">
<el-form :model="form" ref="form" label-width="100px" v-loading="formLoading" :rules="rules">
<el-form-item label="年级:" prop="gradeLevel" required>
<el-select v-model="form.gradeLevel" placeholder="年级" @change="levelChange">
<el-option v-for="item in levelEnum" :key="item.key" :value="item.key" :label="item.value"></el-option>
</el-select>
</el-form-item>
<el-form-item label="学科:" prop="subjectId" required>
<el-select v-model="form.subjectId" placeholder="学科" >
<el-option v-for="item in subjectFilter" :key="item.id" :value="item.id" :label="item.name+' ( '+item.levelName+' )'"></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="选项:" 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="解析:" prop="analyze" required>
<el-input v-model="form.analyze" @focus="inputClick(form,'analyze')" />
</el-form-item>
<el-form-item label="分数:" prop="score" required>
<el-input-number v-model="form.score" :precision="1" :step="1" :max="100"></el-input-number>
</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="正确答案:" prop="correctArray" required>
<el-checkbox-group v-model="form.correctArray">
<el-checkbox v-for="item in form.items" :label="item.prefix" :key="item.prefix">{{item.prefix}}</el-checkbox>
</el-checkbox-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 {
form: {
id: null,
questionType: 2,
gradeLevel: null,
subjectId: null,
title: '',
items: [
{ id: null, prefix: 'A', content: '' },
{ id: null, prefix: 'B', content: '' },
{ id: null, prefix: 'C', content: '' },
{ id: null, prefix: 'D', content: '' }
],
analyze: '',
correct: '',
correctArray: [],
score: '',
difficult: 0
},
subjectFilter: null,
formLoading: false,
rules: {
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' }
],
correctArray: [
{ required: true, message: '请选择正确答案', 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.response
_this.formLoading = false
})
}
},
methods: {
editorReady (instance) {
this.richEditor.instance = instance
let currentContent = this.richEditor.object[this.richEditor.parameterName]
this.richEditor.instance.setContent(currentContent)
// 光标定位到Ueditor
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 last = items[items.length - 1]
let newLastPrefix = String.fromCharCode(last.prefix.charCodeAt() + 1)
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
}
})
},
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
},
resetForm () {
this.$refs['form'].resetFields()
},
...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>

View File

@@ -0,0 +1,187 @@
<template>
<div class="app-container">
<el-form :model="form" ref="form" label-width="100px" v-loading="formLoading" :rules="rules">
<el-form-item label="年级:" prop="gradeLevel" required>
<el-select v-model="form.gradeLevel" placeholder="年级" @change="levelChange">
<el-option v-for="item in levelEnum" :key="item.key" :value="item.key" :label="item.value"></el-option>
</el-select>
</el-form-item>
<el-form-item label="学科:" prop="subjectId" required>
<el-select v-model="form.subjectId" placeholder="学科" >
<el-option v-for="item in subjectFilter" :key="item.id" :value="item.id" :label="item.name+' ( '+item.levelName+' )'"></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="correct" required>
<el-input v-model="form.correct" @focus="inputClick(form,'correct')" />
</el-form-item>
<el-form-item label="解析:" prop="analyze" required>
<el-input v-model="form.analyze" @focus="inputClick(form,'analyze')" />
</el-form-item>
<el-form-item label="分数:" prop="score" required>
<el-input-number v-model="form.score" :precision="1" :step="1" :max="100"></el-input-number>
</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>
<el-button type="primary" @click="submitForm">提交</el-button>
<el-button @click="resetForm">重置</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 {
form: {
id: null,
questionType: 5,
gradeLevel: null,
subjectId: null,
title: '',
items: [],
analyze: '',
correct: '',
score: '',
difficult: 0
},
subjectFilter: null,
formLoading: false,
rules: {
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' }
]
},
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.response
_this.formLoading = false
})
}
},
methods: {
editorReady (instance) {
this.richEditor.instance = instance
let currentContent = this.richEditor.object[this.richEditor.parameterName]
this.richEditor.instance.setContent(currentContent)
// 光标定位到Ueditor
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
},
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 () {
this.$refs['form'].resetFields()
},
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>

View File

@@ -0,0 +1,211 @@
<template>
<div class="app-container">
<el-form :model="form" ref="form" label-width="100px" v-loading="formLoading" :rules="rules">
<el-form-item label="年级:" prop="gradeLevel" required>
<el-select v-model="form.gradeLevel" placeholder="年级" @change="levelChange" clearable>
<el-option v-for="item in levelEnum" :key="item.key" :value="item.key" :label="item.value"></el-option>
</el-select>
</el-form-item>
<el-form-item label="学科:" prop="subjectId" required>
<el-select v-model="form.subjectId" placeholder="学科" >
<el-option v-for="item in subjectFilter" :key="item.id" :value="item.id" :label="item.name+' ( '+item.levelName+' )'"></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="选项:" 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="解析:" prop="analyze" required>
<el-input v-model="form.analyze" @focus="inputClick(form,'analyze')" />
</el-form-item>
<el-form-item label="分数:" prop="score" required>
<el-input-number v-model="form.score" :precision="1" :step="1" :max="100"></el-input-number>
</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="正确答案:" 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 {
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
},
subjectFilter: null,
formLoading: false,
rules: {
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: '请选择正确答案', 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.response
_this.formLoading = false
})
}
},
methods: {
editorReady (instance) {
this.richEditor.instance = instance
let currentContent = this.richEditor.object[this.richEditor.parameterName]
this.richEditor.instance.setContent(currentContent)
// 光标定位到Ueditor
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 last = items[items.length - 1]
let newLastPrefix = String.fromCharCode(last.prefix.charCodeAt() + 1)
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 () {
this.$refs['form'].resetFields()
},
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>

View File

@@ -0,0 +1,198 @@
<template>
<div class="app-container">
<el-form :model="form" ref="form" label-width="100px" v-loading="formLoading" :rules="rules">
<el-form-item label="年级:" prop="gradeLevel" required>
<el-select v-model="form.gradeLevel" placeholder="年级" @change="levelChange">
<el-option v-for="item in levelEnum" :key="item.key" :value="item.key" :label="item.value"></el-option>
</el-select>
</el-form-item>
<el-form-item label="学科:" prop="subjectId" required>
<el-select v-model="form.subjectId" placeholder="学科" >
<el-option v-for="item in subjectFilter" :key="item.id" :value="item.id" :label="item.name+' ( '+item.levelName+' )'"></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="选项:" required>
<el-form-item :label="item.prefix" :key="item.prefix" v-for="(item) 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-form-item>
</el-form-item>
<el-form-item label="解析:" prop="analyze" required>
<el-input v-model="form.analyze" @focus="inputClick(form,'analyze')" />
</el-form-item>
<el-form-item label="分数:" prop="score" required>
<el-input-number v-model="form.score" :precision="1" :step="1" :max="100"></el-input-number>
</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="正确答案:" 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="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 {
form: {
id: null,
questionType: 3,
gradeLevel: null,
subjectId: null,
title: '',
items: [
{ id: null, prefix: 'A', content: '是' },
{ id: null, prefix: 'B', content: '否' }
],
analyze: '',
correct: '',
score: '',
difficult: 0
},
subjectFilter: null,
formLoading: false,
rules: {
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: '请选择正确答案', 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.response
_this.formLoading = false
})
}
},
methods: {
editorReady (instance) {
this.richEditor.instance = instance
let currentContent = this.richEditor.object[this.richEditor.parameterName]
this.richEditor.instance.setContent(currentContent)
// 光标定位到Ueditor
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
},
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 () {
this.$refs['form'].resetFields()
},
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>

View File

@@ -0,0 +1,157 @@
<template>
<div class="app-container">
<el-form :model="queryParam" ref="queryForm" :inline="true">
<el-form-item label="题目ID">
<el-input v-model="queryParam.id" clearable></el-input>
</el-form-item>
<el-form-item label="年级:">
<el-select v-model="queryParam.level" placeholder="年级" @change="levelChange" clearable>
<el-option v-for="item in levelEnum" :key="item.key" :value="item.key" :label="item.value"></el-option>
</el-select>
</el-form-item>
<el-form-item label="学科:">
<el-select v-model="queryParam.subjectId" clearable>
<el-option v-for="item in subjectFilter" :key="item.id" :value="item.id"
:label="item.name+' ( '+item.levelName+' )'"></el-option>
</el-select>
</el-form-item>
<el-form-item label="题型:">
<el-select v-model="queryParam.questionType" clearable>
<el-option v-for="item in questionType" :key="item.key" :value="item.key" :label="item.value"></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm">查询</el-button>
<el-popover placement="bottom" trigger="click">
<el-button type="warning" size="mini" v-for="item in editUrlEnum" :key="item.key"
@click="$router.push({path:item.value})">{{item.name}}
</el-button>
<el-button slot="reference" type="primary" class="link-left">添加</el-button>
</el-popover>
</el-form-item>
</el-form>
<el-table v-loading="listLoading" :data="tableData" border fit highlight-current-row style="width: 100%">
<el-table-column prop="id" label="Id" width="90px"/>
<el-table-column prop="subjectId" label="学科" :formatter="subjectFormatter" width="120px"/>
<el-table-column prop="questionType" label="题型" :formatter="questionTypeFormatter" width="70px"/>
<el-table-column prop="shortTitle" label="题干" show-overflow-tooltip/>
<el-table-column prop="score" label="分数" width="60px"/>
<el-table-column prop="difficult" label="难度" width="60px"/>
<el-table-column prop="createTime" label="创建时间" width="160px"/>
<el-table-column label="操作" align="center" width="220px">
<template slot-scope="{row}">
<el-button size="mini" @click="showQuestion(row)">预览</el-button>
<el-button size="mini" @click="editQuestion(row)">编辑</el-button>
<el-button size="mini" type="danger" @click="deleteQuestion(row)" class="link-left">删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="queryParam.pageIndex" :limit.sync="queryParam.pageSize"
@pagination="search"/>
<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 { mapGetters, mapState, mapActions } from 'vuex'
import Pagination from '@/components/Pagination'
import QuestionShow from './components/Show'
import questionApi from '@/api/question'
export default {
components: { Pagination, QuestionShow },
data () {
return {
queryParam: {
id: null,
questionType: null,
level: null,
subjectId: null,
pageIndex: 1,
pageSize: 10
},
subjectFilter: null,
listLoading: true,
tableData: [],
total: 0,
questionShow: {
qType: 0,
dialog: false,
question: null,
loading: false
}
}
},
created () {
this.initSubject()
this.search()
},
methods: {
submitForm () {
this.queryParam.pageIndex = 1
this.search()
},
search () {
this.listLoading = true
questionApi.pageList(this.queryParam).then(data => {
const re = data.response
this.tableData = re.list
this.total = re.total
this.queryParam.pageIndex = re.pageNum
this.listLoading = false
})
},
levelChange () {
this.queryParam.subjectId = null
this.subjectFilter = this.subjects.filter(data => data.level === this.queryParam.level)
},
addQuestion () {
this.$router.push('/exam/question/edit/singleChoice')
},
showQuestion (row) {
let _this = this
this.questionShow.dialog = true
this.questionShow.loading = true
questionApi.select(row.id).then(re => {
_this.questionShow.qType = re.response.questionType
_this.questionShow.question = re.response
_this.questionShow.loading = false
})
},
editQuestion (row) {
let url = this.enumFormat(this.editUrlEnum, row.questionType)
this.$router.push({ path: url, query: { id: row.id } })
},
deleteQuestion (row) {
let _this = this
questionApi.deleteQuestion(row.id).then(re => {
if (re.code === 1) {
_this.search()
_this.$message.success(re.message)
} else {
_this.$message.error(re.message)
}
})
},
questionTypeFormatter (row, column, cellValue, index) {
return this.enumFormat(this.questionType, cellValue)
},
subjectFormatter (row, column, cellValue, index) {
return this.subjectEnumFormat(cellValue)
},
...mapActions('exam', { initSubject: 'initSubject' })
},
computed: {
...mapGetters('enumItem', ['enumFormat']),
...mapState('enumItem', {
questionType: state => state.exam.question.typeEnum,
editUrlEnum: state => state.exam.question.editUrlEnum,
levelEnum: state => state.user.levelEnum
}),
...mapGetters('exam', ['subjectEnumFormat']),
...mapState('exam', { subjects: state => state.subjects })
}
}
</script>