基于vue与element实现创建试卷相关功能

由于最近在一个项目中需要实现创建试卷与预览试卷的功能,所以就自己动手写了一个,效果还不错,目前项目已经交付使用,今天就先和大家分享一下创建试卷。
源码已上传至gitee仓库,地址https://gitee.com/mingDn/exam

创建试卷

先放一下效果图
创建试卷
首先是试卷的相关设置

  • 考试对象是通过接口返回的数据
    考试对象
<span class="content-label">选择考试对象</span>
<el-form-item prop="roleList">
	<el-select
		v-model="form.roleList"
		multiple
		filterable
		allow-create
		default-first-option
		placeholder="请选择考试对象"
	>
		<el-option
			v-for="item in roles"
			:key="item.value"
			:label="item.label"
			:value="item.value"
		/>
	</el-select>
</el-form-item>

需要定义的data数据

roles: [], //考试对象选择列表(接口返回)
form: {
   
	title: '',
	roleList: [], // 考试对象
	deadline: '', // 截止时间
	questions: []
},

获取考试对象列表

getRoles() {
   
	crudRoles.getAll().then(res => {
   
		res.map((obj) => {
   
			const role = {
   
				value: obj.id,
				label: obj.name
			}
			this.roles.push(role)
		})
	})
},
  • 截至时间使用的是element时间日期选择器
    日期时间选择器
<span class="content-label">截止时间</span>
<el-form-item prop="deadline">
	<el-date-picker
	v-model="form.deadline"
	type="datetime"
	placeholder="选择日期时间"
	value-format="yyyy-MM-dd HH:mm:ss"
	/>
</el-form-item>

然后是添加试题
试题类型的相关数据也是通过接口返回的
添加试题
data数据

questionType: [],

获取试题类型

getQuestionType() {
   
	crudExam.getQuestionType().then(res => {
   
		this.questionType = res
	})
},
<div class="question-type">
	<el-button
		v-for="item in questionType"
		:key="item.typeId"
		style="border-color: #2A82E4; color: #2A82E4"
		@click="addQuestion(item.typeId)"
	>
		<svg-icon :icon-class="item.icon" />
		{
  { item.typeName }}
	</el-button>
</div>
addQuestion(typeId) {
   
	const question = {
   
		id: this.questionId,
        quesTypeId: typeId,
        title: '',
        score: 0,
        answer: [],
        content: []
	}
	this.form.questions.push(question)
	this.questionId++
},

对于添加的试题模板则是单独创建了一个question.vue
这里由于其他布局方法一直不太理想,所以采用了栅格布局,效果还算可以

<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix" style="margin-bottom: -10px">
      <span
        class="type-name"
        v-text="question.quesTypeId < 3 ?
          question.quesTypeId === 1 ?
            '单选题' : '多选题'
          : question.quesTypeId < 5 ?
            question.quesTypeId === 3 ?
              '填空题' : '简答题'
            : '判断题'"
      >卡片名称</span>
      
  • 7
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值