question img

This commit is contained in:
caoqianming 2020-06-01 18:04:36 +08:00
parent db6114cc99
commit 1ec1bbf98a
5 changed files with 78 additions and 1 deletions

View File

@ -3,4 +3,4 @@ ENV = 'production'
# base api # base api
# VUE_APP_BASE_API = '/prod-api' # VUE_APP_BASE_API = '/prod-api'
VUE_APP_BASE_API = 'http://apitest.ahctc.cn' VUE_APP_BASE_API = 'https://apitest.ctcshe.com'

View File

@ -32,6 +32,20 @@
<el-form-item label="题干" prop="name"> <el-form-item label="题干" prop="name">
<el-input v-model="Form.name" style="width:600px" type="textarea" :rows=3></el-input> <el-input v-model="Form.name" style="width:600px" type="textarea" :rows=3></el-input>
</el-form-item> </el-form-item>
<el-form-item label="题干图片" prop="img" >
<el-upload
class="avatar-uploader"
:headers="myHeaders"
:action="uploadUrl"
accept="image/jpeg, image/gif, image/png, image/bmp"
:show-file-list="false"
:on-success="handleImgSuccess"
:before-upload="beforeImgUpload"
>
<img v-if="Form.img" :src="Form.img" style="width: 200px;height: 100px;display: block;"/>
<el-button size="small" type="primary" v-else>点击上传</el-button>
</el-upload>
</el-form-item>
<el-form-item label="选项A" prop="optionA" > <el-form-item label="选项A" prop="optionA" >
<el-input v-model="Form.options.A" style="width:600px" :disabled="inputDisable"></el-input> <el-input v-model="Form.options.A" style="width:600px" :disabled="inputDisable"></el-input>
</el-form-item> </el-form-item>
@ -90,12 +104,17 @@
<script> <script>
import { createQuestion,getQuestioncatAll } from "@/api/question"; import { createQuestion,getQuestioncatAll } from "@/api/question";
import { genTree, deepClone } from "@/utils"; import { genTree, deepClone } from "@/utils";
import { uploadUrl } from "@/api/file";
import { getToken } from "@/utils/auth";
export default { export default {
data() { data() {
return { return {
myHeaders: { Authorization: "JWT " + getToken() },
uploadUrl: uploadUrl(),
Form: { Form: {
name: "", name: "",
type:"", type:"",
img:null,
questioncat:null, questioncat:null,
right:'', right:'',
options:{ options:{
@ -128,6 +147,16 @@ export default {
this.getQuestioncatAll() this.getQuestioncatAll()
}, },
methods: { methods: {
handleImgSuccess(res, file) {
this.Form.img = res.data.path
},
beforeImgUpload(file) {
const isLt2M = file.size / 1024 / 1024 < 0.6;
if (!isLt2M) {
this.$message.error("上传图片大小不能超过 600KB!");
}
return isLt2M;
},
submitForm(formName) { submitForm(formName) {
this.$refs[formName].validate(valid => { this.$refs[formName].validate(valid => {
if (valid) { if (valid) {

View File

@ -33,6 +33,20 @@
<el-form-item label="题干" prop="name"> <el-form-item label="题干" prop="name">
<el-input v-model="Form.name" style="width:600px" type="textarea" :rows=3></el-input> <el-input v-model="Form.name" style="width:600px" type="textarea" :rows=3></el-input>
</el-form-item> </el-form-item>
<el-form-item label="题干图片" prop="img" >
<el-upload
class="avatar-uploader"
:headers="myHeaders"
:action="uploadUrl"
accept="image/jpeg, image/gif, image/png, image/bmp"
:show-file-list="false"
:on-success="handleImgSuccess"
:before-upload="beforeImgUpload"
>
<img v-if="Form.img" :src="banner.img" style="width: 200px;height: 100px;display: block;"/>
<el-button size="small" type="primary" v-else>点击上传</el-button>
</el-upload>
</el-form-item>
<el-form-item label="选项A" prop="optionA" > <el-form-item label="选项A" prop="optionA" >
<el-input v-model="Form.options.A" style="width:600px" :disabled="inputDisable"></el-input> <el-input v-model="Form.options.A" style="width:600px" :disabled="inputDisable"></el-input>
</el-form-item> </el-form-item>
@ -90,12 +104,17 @@
<script> <script>
import { createQuestion,getQuestioncatAll, getQuestion, getQuestioncatList, updateQuestion } from "@/api/question"; import { createQuestion,getQuestioncatAll, getQuestion, getQuestioncatList, updateQuestion } from "@/api/question";
import { genTree, deepClone } from "@/utils"; import { genTree, deepClone } from "@/utils";
import { uploadUrl } from "@/api/file";
import { getToken } from "@/utils/auth";
export default { export default {
data() { data() {
return { return {
myHeaders: { Authorization: "JWT " + getToken() },
uploadUrl: uploadUrl(),
Form: { Form: {
id:0, id:0,
name: "", name: "",
img: null,
type:"", type:"",
questioncat:null, questioncat:null,
right:'', right:'',
@ -130,6 +149,16 @@ export default {
this.getQuestioncatAll() this.getQuestioncatAll()
}, },
methods: { methods: {
handleImgSuccess(res, file) {
this.Form.img = res.data.path
},
beforeImgUpload(file) {
const isLt2M = file.size / 1024 / 1024 < 0.6;
if (!isLt2M) {
this.$message.error("上传图片大小不能超过 600KB!");
}
return isLt2M;
},
submitForm(formName) { submitForm(formName) {
this.$refs[formName].validate(valid => { this.$refs[formName].validate(valid => {
if (valid) { if (valid) {

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.4 on 2020-06-01 09:59
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('question', '0011_auto_20200417_1135'),
]
operations = [
migrations.AddField(
model_name='question',
name='img',
field=models.CharField(blank=True, max_length=1000, null=True, verbose_name='题干图片'),
),
]

View File

@ -37,6 +37,7 @@ class Question(SoftCommonModel):
('', ''), ('', ''),
) )
name = models.TextField(verbose_name='题干') name = models.TextField(verbose_name='题干')
img = models.CharField(max_length=1000, null=True, blank=True, verbose_name='题干图片')
type = models.CharField(max_length=50, default='单选', choices=type_choices, verbose_name='题型') type = models.CharField(max_length=50, default='单选', choices=type_choices, verbose_name='题型')
level = models.CharField(max_length=50, default='', choices=level_choices, verbose_name='难度') level = models.CharField(max_length=50, default='', choices=level_choices, verbose_name='难度')
questioncat = models.ForeignKey(Questioncat, blank=True, null=True, on_delete=models.SET_NULL, verbose_name='所属题库', related_name='questioncat') questioncat = models.ForeignKey(Questioncat, blank=True, null=True, on_delete=models.SET_NULL, verbose_name='所属题库', related_name='questioncat')