试题导入、模板下载

pg_adapter
dshclm 9 months ago
parent 164a8f6cc3
commit 9cc35b4945

@ -12,6 +12,7 @@ import com.ruoyi.system.domain.qu.ElQu;
import com.ruoyi.system.domain.qu.dto.export.QuExportDTO;
import com.ruoyi.system.domain.qu.dto.ext.QuDetailDTO;
import com.ruoyi.system.domain.qu.dto.request.QuQueryReqDTO;
import com.ruoyi.system.domain.repo.ElRepo;
import com.ruoyi.web.controller.manager.QuManager;
import com.ruoyi.web.controller.manager.RepoManager;
import io.swagger.annotations.Api;
@ -186,7 +187,6 @@ public class QuController extends BaseController {
@ApiOperation("导入Excel")
@RequiresPermissions("system:qu:import")
@ResponseBody
@PostMapping( "/import")
public AjaxResult importFile(@RequestParam("file") MultipartFile file) {
@ -217,5 +217,4 @@ public class QuController extends BaseController {
}

@ -2,9 +2,10 @@
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('题库列表')" />
<th:block th:include="include :: element-css" />
</head>
<body class="gray-bg">
<div class="container-div">
<div class="container-div" id="app">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="notice-form">
@ -38,14 +39,28 @@
<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:qu:remove">
<i class="fa fa-remove"></i> 删除
</a>
<a class="btn btn-info" @click="toImport()">
<i class="fa fa-upload"></i> 导入
</a>
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-table"></table>
</div>
</div>
<el-dialog
:visible.sync="importVisible"
title="导入试题"
width="30%"
>
<el-row>
<el-button type="primary" @click="chooseFile()">上传导入</el-button>
<el-button type="warning" @click="downloadTemplate()">下载导入模板</el-button>
<input ref="upFile" class="file" name="file" type="file" style="display: none" @change="doImport">
</el-row>
</el-dialog>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: element-js" />
<script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('system:qu:edit')}]];
var removeFlag = [[${@permission.hasPermi('system:qu:remove')}]];
@ -92,6 +107,89 @@
};
$.table.init(options);
});
// function toImport(){
// $.modal.open("试题导入", prefix + "/toImport",'500','300');
// }
// 请求实例
const instance = axios.create({
baseURL: ctx,
timeout: 60000
})
var app = new Vue({
el: '#app',
data: {
importVisible:false
},
mounted(){
},
methods: {
toImport(){
this.importVisible = true
},
// 只是为了美化一下导入按钮
chooseFile: function() {
this.$refs.upFile.dispatchEvent(new MouseEvent('click'))
},
downloadTemplate() {
// 创建一个隐藏的<a>标签
var link = document.createElement('a');
link.style.display = 'none';
document.body.appendChild(link);
link.setAttribute('href', '/file/试题导入模板.xlsx');
link.setAttribute('download', '试题导入模板.xlsx');
link.click();
document.body.removeChild(link);
},
upload(url, file, data) {
const formData = new FormData()
formData.append('file', file)
// 附加数据
if (data) {
Object.keys(data).forEach((key) => {
formData.append(key, data[key])
})
}
return new Promise((resolve, reject) => {
instance.request({
url: url,
method: 'post',
data: formData,
timeout: 1200000
}).then(response => {
console.log(response)
resolve(response)
}).catch(err => {
reject(err)
})
})
},
importExcel(file) {
return this.upload('system/qu/import', file)
},
doImport(e) {
const file = e.target.files[0]
let that = this
this.importExcel(file).then((res)=>{
console.log(res)
if (res.data.code !== 0) {
that.$alert(res.data.msg, '导入信息', {
dangerouslyUseHTMLString: true
})
} else {
that.$message({
message: '数据导入成功!',
type: 'success'
})
this.importVisible = false
$.table.refresh()
}
})
},
},
});
</script>
</body>
</html>

@ -34,18 +34,18 @@
<p>【{{ quData.quType===1?'单选题':'多选题' }}】{{ quData.content }}</p>
<p v-if="quData.image!=null && quData.image!=''">
<el-image :src="quData.image" style="max-width:80%;" />
<el-image :src="quData.image" style="max-width:80%;" ></el-image>
</p>
<div v-if="quData.quType === 1">
<el-radio-group v-model="radioValues" readonly>
<el-radio v-for="an in quData.answerList" :label="an.id" readonly>{{ an.content }}</el-radio>
<el-radio v-for="an in quData.answerList" :key="an.id" :label="an.id" readonly>{{ an.content }}</el-radio>
</el-radio-group>
</div>
<!-- 多选题 -->
<div v-if="quData.quType === 2">
<el-checkbox-group v-model="multiValues" readonly>
<el-checkbox v-for="an in quData.answerList" :label="an.id">{{ an.content }}</el-checkbox>
<el-checkbox v-for="an in quData.answerList" :key="an.id" :label="an.id">{{ an.content }}</el-checkbox>
</el-checkbox-group>
</div>
@ -61,7 +61,7 @@
<el-card class="qu-analysis" style="margin-top: 20px; margin-bottom: 30px">
选项解析:
<div v-for="an in quData.answerList" v-if="an.analysis" class="qu-analysis-line">
<div v-for="an in quData.answerList" :key="an.id" v-if="an.analysis" class="qu-analysis-line">
<p style="color: #555;">{{ an.content }}</p>
<p style="color: #1890ff;">{{ an.analysis }}</p>
</div>

Loading…
Cancel
Save