增加导入试题功能

main
lj7788 2025-08-23 23:20:26 +08:00
parent 302de3c0f0
commit f5fb4d910a
21 changed files with 621 additions and 25 deletions

View File

@ -1,6 +1,8 @@
package com.hig.questions.controller;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -42,6 +44,8 @@ import com.ruoyi.common.core.page.TableDataInfo;
@RequestMapping("/questions/questionsbank")
public class ExamQuestionsBankController extends BaseController
{
private static final Logger log = LoggerFactory.getLogger(ExamQuestionsBankController.class);
@Value("${cms.exam.photo-path}")
private String photopath;
@ -70,7 +74,7 @@ public class ExamQuestionsBankController extends BaseController
public AjaxResult arrayList(@PathVariable("bankCodes") String bankCodes)
{
// startPage();
// System.out.println("bankCodes:" + bankCodes);
// log.debug("bankCodes: {}", bankCodes);
List<ExamQuestionsBank> list = examQuestionsBankService.selectExamQuestionsBankListByCode(bankCodes.split(","));
return AjaxResult.success(list);
}
@ -88,6 +92,32 @@ public class ExamQuestionsBankController extends BaseController
return util.exportExcel(list, "题库管理数据");
}
/**
*
*/
@Log(title = "题库管理", businessType = BusinessType.IMPORT)
@PreAuthorize("@ss.hasPermi('questions:questionsbank:import')")
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
{
ExcelUtil<ExamQuestionsBank> util = new ExcelUtil<ExamQuestionsBank>(ExamQuestionsBank.class);
List<ExamQuestionsBank> examQuestionsBankList = util.importExcel(file.getInputStream());
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
String operName = loginUser.getUsername();
String message = examQuestionsBankService.importExamQuestionsBank(examQuestionsBankList, updateSupport, operName);
return AjaxResult.success(message);
}
/**
*
*/
@GetMapping("/importTemplate")
public AjaxResult importTemplate()
{
ExcelUtil<ExamQuestionsBank> util = new ExcelUtil<ExamQuestionsBank>(ExamQuestionsBank.class);
return util.importTemplateExcel("题库管理数据");
}
/**
*
*/
@ -107,13 +137,13 @@ public class ExamQuestionsBankController extends BaseController
public AjaxResult add(@RequestBody ExamQuestionsBank examQuestionsBank)
{
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
System.out.println(loginUser.getUser().getUserName());
System.out.println(loginUser.getUser().getDept().getDeptId());
log.debug("用户名: {}", loginUser.getUser().getUserName());
log.debug("部门ID: {}", loginUser.getUser().getDept().getDeptId());
examQuestionsBank.setCreateBy(loginUser.getUser().getUserName());
examQuestionsBank.setCreateDept(loginUser.getUser().getDept().getDeptId());
examQuestionsBank.setBankCode(UUIDGenerator.generate());
System.out.println("examQuestionsBank:" + examQuestionsBank.toString());
log.debug("examQuestionsBank: {}", examQuestionsBank.toString());
return toAjax(examQuestionsBankService.insertExamQuestionsBank(examQuestionsBank));
}
@ -125,7 +155,7 @@ public class ExamQuestionsBankController extends BaseController
@PutMapping
public AjaxResult edit(@RequestBody ExamQuestionsBank examQuestionsBank)
{
System.out.println("examQuestionsBank:" + examQuestionsBank.toString());
log.debug("examQuestionsBank: {}", examQuestionsBank.toString());
return toAjax(examQuestionsBankService.updateExamQuestionsBank(examQuestionsBank));
}
@ -152,10 +182,10 @@ public class ExamQuestionsBankController extends BaseController
// 拼接路径
String path = RuoYiConfig.getProfile() + photopath;
System.out.println("拼接路径为:" + path);
log.debug("拼接路径为: {}", path);
String filename = FileUpload.writeUploadFile(file,path);
String fileurl = photopath + "/" + filename;
System.out.println(fileurl);
log.debug("fileurl: {}", fileurl);
int count = 0;
@ -163,7 +193,7 @@ public class ExamQuestionsBankController extends BaseController
// 相应赋值
ExamBankPicture examBankPicture = new ExamBankPicture(bankcode, path, fileurl, filename, originalfile);
System.out.println("examBankPicture:" + examBankPicture.toString());
log.debug("examBankPicture: {}", examBankPicture.toString());
try
{

View File

@ -1,8 +1,13 @@
package com.hig.questions.controller;
import java.util.List;
import java.util.*;
import com.ruoyi.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
@ -11,6 +16,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
@ -40,6 +46,8 @@ import com.ruoyi.common.core.page.TableDataInfo;
@RequestMapping("/questions/examquestions")
public class ExamQuestionsController extends BaseController
{
private static final Logger log = LoggerFactory.getLogger(ExamQuestionsController.class);
@Autowired
private IExamQuestionsService examQuestionsService;
@ -80,6 +88,65 @@ public class ExamQuestionsController extends BaseController
return util.exportExcel(list, "考试题目数据");
}
/**
*
*/
@Log(title = "考试题目", businessType = BusinessType.IMPORT)
@PreAuthorize("@ss.hasPermi('questions:examquestions:import')")
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file, boolean updateSupport,String bankCode) throws Exception
{
ExcelUtil<ExamQuestions> util = new ExcelUtil<ExamQuestions>(ExamQuestions.class);
List<ExamQuestions> examQuestionsList = util.importExcel(file.getInputStream());
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
String operName = loginUser.getUsername();
List<ExamQuestions> examQuestions=new ArrayList<>();
examQuestionsList.forEach(x->{
x.setBankCode(bankCode);
String tmp= x.getQuestionsTypeStr();
boolean flag=false;
if("判断题".equals(tmp)){
x.setQuestionsType(1);
flag=true;
}
if("单选题".equals(tmp)){
x.setQuestionsType(2);
flag=true;
}
if("多选题".equals(tmp)){
x.setQuestionsType(3);
flag=true;
}
if(flag){
examQuestions.add(x);
}
if(StringUtils.isEmpty(x.getRateNumberStr())){
x.setRateNumber(0);
}else{
x.setRateNumber(x.getRateNumberStr().length()/2);
}
x.setCreateBy(operName);
x.setCreateTime(new Date());
x.setQuestionsCode(UUID.randomUUID().toString());
});
if(CollectionUtils.isEmpty(examQuestions)){
return AjaxResult.error("导入数据为空!");
}
String message = examQuestionsService.importExamQuestions(examQuestions, updateSupport, operName);
return AjaxResult.success(message);
}
/**
*
*/
@GetMapping("/importTemplate")
public AjaxResult importTemplate()
{
ExcelUtil<ExamQuestions> util = new ExcelUtil<ExamQuestions>(ExamQuestions.class);
return util.importTemplateExcel("考试题目数据");
}
/**
*
*/
@ -110,7 +177,7 @@ public class ExamQuestionsController extends BaseController
ExamQuestionsContent examQuestionsContent = new ExamQuestionsContent(examQuestions.getQuestionsCode(), examQuestions.getQuestionsContent());
System.out.println("examQuestionsContent:" + examQuestionsContent.toString());
log.debug("examQuestionsContent: {}", examQuestionsContent.toString());
// 开始保存数据

View File

@ -38,6 +38,8 @@ public class ExamQuestions extends BaseEntity
/** 试题类型 */
@Excel(name = "试题类型")
private String questionsTypeStr;
private Integer questionsType;
/** 题目分数 */
@ -46,8 +48,49 @@ public class ExamQuestions extends BaseEntity
/** 复杂度 */
@Excel(name = "复杂度")
private String rateNumberStr;
private Integer rateNumber;
/** 复杂度 */
@Excel(name = "A")
private String answerA;
/** 复杂度 */
@Excel(name = "B")
private String answerB;
/** 复杂度 */
@Excel(name = "C")
private String answerC;
/** 复杂度 */
@Excel(name = "D")
private String answerD;
/** 复杂度 */
@Excel(name = "E")
private String answerE;
/** 复杂度 */
@Excel(name = "F")
private String answerF;
/** 复杂度 */
@Excel(name = "G")
private String answerG;
/** 复杂度 */
@Excel(name = "H")
private String answerH;
/** 复杂度 */
@Excel(name = "I")
private String answerI;
/** 复杂度 */
@Excel(name = "J")
private String answerJ;
/** 正确答案 */
@Excel(name = "正确答案")
private String rightAnswer;
@ -66,8 +109,103 @@ public class ExamQuestions extends BaseEntity
/** 题目选项 */
private List<ExamQuestionsAnswer> answerList ;
public String getQuestionsTypeStr() {
return questionsTypeStr;
}
public void setQuestionsTypeStr(String questionsTypeStr) {
this.questionsTypeStr = questionsTypeStr;
}
public String getRateNumberStr() {
return rateNumberStr;
}
public void setRateNumberStr(String rateNumberStr) {
this.rateNumberStr = rateNumberStr;
}
public String getAnswerA() {
return answerA;
}
public void setAnswerA(String answerA) {
this.answerA = answerA;
}
public String getAnswerB() {
return answerB;
}
public void setAnswerB(String answerB) {
this.answerB = answerB;
}
public String getAnswerC() {
return answerC;
}
public void setAnswerC(String answerC) {
this.answerC = answerC;
}
public String getAnswerD() {
return answerD;
}
public void setAnswerD(String answerD) {
this.answerD = answerD;
}
public String getAnswerE() {
return answerE;
}
public void setAnswerE(String answerE) {
this.answerE = answerE;
}
public String getAnswerF() {
return answerF;
}
public void setAnswerF(String answerF) {
this.answerF = answerF;
}
public String getAnswerG() {
return answerG;
}
public void setAnswerG(String answerG) {
this.answerG = answerG;
}
public String getAnswerH() {
return answerH;
}
public void setAnswerH(String answerH) {
this.answerH = answerH;
}
public String getAnswerI() {
return answerI;
}
public void setAnswerI(String answerI) {
this.answerI = answerI;
}
public String getAnswerJ() {
return answerJ;
}
public void setAnswerJ(String answerJ) {
this.answerJ = answerJ;
}
public List<ExamQuestionsAnswer> getAnswerList() {
return answerList;
}

View File

@ -29,6 +29,7 @@ public class ExamQuestionsBank extends BaseEntity
private String bankName;
/** 题库描述 */
@Excel(name = "题库描述")
private String bankDescribe;
/** 题库版本 */

View File

@ -19,6 +19,14 @@ public interface ExamQuestionsBankMapper
*/
public ExamQuestionsBank selectExamQuestionsBankById(String bankCode);
/**
*
*
* @param bankName
* @return
*/
public ExamQuestionsBank selectExamQuestionsBankByName(String bankName);
/**
*
*

View File

@ -19,6 +19,14 @@ public interface ExamQuestionsMapper
*/
public ExamQuestions selectExamQuestionsById(String questionsCode);
/**
*
*
* @param questionsTitle
* @return
*/
public ExamQuestions selectExamQuestionsByTitle(String questionsTitle);
/**
*
*

View File

@ -69,4 +69,14 @@ public interface IExamQuestionsBankService
* @return
*/
public int deleteExamQuestionsBankById(String bankCode);
/**
*
*
* @param examQuestionsBankList
* @param isUpdateSupport
* @param operName
* @return
*/
public String importExamQuestionsBank(List<ExamQuestionsBank> examQuestionsBankList, Boolean isUpdateSupport, String operName);
}

View File

@ -58,4 +58,22 @@ public interface IExamQuestionsService
* @return
*/
public int deleteExamQuestionsById(String questionsCode);
/**
*
*
* @param examQuestionsList
* @param isUpdateSupport
* @param operName
* @return
*/
public String importExamQuestions(List<ExamQuestions> examQuestionsList, Boolean isUpdateSupport, String operName);
/**
*
*
* @param questionsTitle
* @return
*/
public ExamQuestions selectExamQuestionsByTitle(String questionsTitle);
}

View File

@ -7,7 +7,10 @@ import java.util.stream.Collectors;
import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.hig.utils.UUIDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hig.questions.mapper.ExamQuestionsBankMapper;
@ -105,5 +108,72 @@ public class ExamQuestionsBankServiceImpl implements IExamQuestionsBankService
return examQuestionsBankMapper.selectExamQuestionsBankListByCode(bankCodes);
}
/**
*
*
* @param examQuestionsBankList
* @param isUpdateSupport
* @param operName
* @return
*/
@Override
public String importExamQuestionsBank(List<ExamQuestionsBank> examQuestionsBankList, Boolean isUpdateSupport, String operName)
{
if (StringUtils.isNull(examQuestionsBankList) || examQuestionsBankList.size() == 0)
{
throw new CustomException("导入题库数据不能为空!");
}
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (ExamQuestionsBank examQuestionsBank : examQuestionsBankList)
{
try
{
// 验证是否存在这个题库
ExamQuestionsBank b = examQuestionsBankMapper.selectExamQuestionsBankByName(examQuestionsBank.getBankName());
if (StringUtils.isNull(b))
{
examQuestionsBank.setBankCode(UUIDGenerator.generate());
examQuestionsBank.setCreateBy(operName);
examQuestionsBank.setCreateTime(DateUtils.getNowDate());
this.insertExamQuestionsBank(examQuestionsBank);
successNum++;
successMsg.append("<br/>" + successNum + "、题库 " + examQuestionsBank.getBankName() + " 导入成功");
}
else if (isUpdateSupport)
{
examQuestionsBank.setBankCode(b.getBankCode());
examQuestionsBank.setUpdateBy(operName);
this.updateExamQuestionsBank(examQuestionsBank);
successNum++;
successMsg.append("<br/>" + successNum + "、题库 " + examQuestionsBank.getBankName() + " 更新成功");
}
else
{
failureNum++;
failureMsg.append("<br/>" + failureNum + "、题库 " + examQuestionsBank.getBankName() + " 已存在");
}
}
catch (Exception e)
{
failureNum++;
String msg = "<br/>" + failureNum + "、题库 " + examQuestionsBank.getBankName() + " 导入失败:";
failureMsg.append(msg + e.getMessage());
}
}
if (failureNum > 0)
{
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new CustomException(failureMsg.toString());
}
else
{
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
}
return successMsg.toString();
}
}

View File

@ -1,7 +1,18 @@
package com.hig.questions.service.impl;
import java.util.List;
import java.util.UUID;
import com.hig.questions.domain.ExamQuestionsAnswer;
import com.hig.questions.domain.ExamQuestionsContent;
import com.hig.questions.domain.ExamQuestionsProperty;
import com.hig.questions.mapper.ExamQuestionsAnswerMapper;
import com.hig.questions.mapper.ExamQuestionsContentMapper;
import com.hig.questions.mapper.ExamQuestionsPropertyMapper;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.hig.utils.UUIDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hig.questions.mapper.ExamQuestionsMapper;
@ -20,6 +31,14 @@ public class ExamQuestionsServiceImpl implements IExamQuestionsService
@Autowired
private ExamQuestionsMapper examQuestionsMapper;
@Autowired
private ExamQuestionsPropertyMapper examQuestionsPropertyMapper;
@Autowired
private ExamQuestionsContentMapper examQuestionsContentMapper;
@Autowired
private ExamQuestionsAnswerMapper examQuestionsAnswerMapper;
/**
*
*
@ -92,4 +111,99 @@ public class ExamQuestionsServiceImpl implements IExamQuestionsService
{
return examQuestionsMapper.deleteExamQuestionsById(questionsCode);
}
/**
*
*
* @param questionsTitle
* @return
*/
@Override
public ExamQuestions selectExamQuestionsByTitle(String questionsTitle)
{
return examQuestionsMapper.selectExamQuestionsByTitle(questionsTitle);
}
/**
*
*
* @param examQuestionsList
* @param isUpdateSupport
* @param operName
* @return
*/
@Override
public String importExamQuestions(List<ExamQuestions> examQuestionsList, Boolean isUpdateSupport, String operName) {
if (StringUtils.isNull(examQuestionsList) || examQuestionsList.size() == 0) {
throw new CustomException("导入考试题目数据不能为空!");
}
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (ExamQuestions examQuestions : examQuestionsList) {
try {
ExamQuestionsProperty examProperty = new ExamQuestionsProperty();
examProperty.setBankCode(examQuestions.getBankCode());
examProperty.setQuestionsCode(examQuestions.getQuestionsCode());
examProperty.setQuestionsTitle(examQuestions.getQuestionsTitle());
examProperty.setQuestionsScore(examQuestions.getQuestionsScore());
examProperty.setQuestionsType(examQuestions.getQuestionsType());
examProperty.setRateNumber(examQuestions.getRateNumber());
examProperty.setAnswerAnalyse(examQuestions.getAnswerAnalyse());
examProperty.setRightAnswer(examQuestions.getRightAnswer());
examProperty.setStatus(0);
examProperty.setCreateTime(DateUtils.getNowDate());
examProperty.setCreateBy(examQuestions.getCreateBy());
examQuestionsPropertyMapper.insertExamQuestionsProperty(examProperty);
ExamQuestionsContent examContent = new ExamQuestionsContent(
examQuestions.getQuestionsCode(), examQuestions.getQuestionsContent()
);
examQuestionsContentMapper.insertExamQuestionsContent(examContent);
ExamQuestionsAnswer answer = new ExamQuestionsAnswer();
answer.setQuestionsCode(examQuestions.getQuestionsCode());
int idx = -1;
String opt = "ABCDEFGHIJKLMN";
String code = "";
String rightAnswer = examQuestions.getRightAnswer();
if (StringUtils.isEmpty(rightAnswer)) {
rightAnswer = "";
}
String[] tmps = new String[]{
examQuestions.getAnswerA(),
examQuestions.getAnswerB(),
examQuestions.getAnswerC(),
examQuestions.getAnswerD(),
examQuestions.getAnswerE(),
examQuestions.getAnswerF(),
examQuestions.getAnswerG(),
examQuestions.getAnswerH()
};
for (String tmp : tmps) {
if (StringUtils.isNotEmpty(tmp)) {
idx++;
code = "" + opt.charAt(idx);
answer.setOptionCode(code);
answer.setOptionDescribe(tmp);
answer.setIsRight(rightAnswer.contains(code) ? 0 : 1);
examQuestionsAnswerMapper.insertExamQuestionsAnswer(answer);
}
}
successNum++;
}catch (Exception e){
failureNum++;
}
}
if (failureNum > 0) {
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new CustomException(failureMsg.toString());
} else {
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
}
return successMsg.toString();
}
}

View File

@ -64,6 +64,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectExamQuestionsBankVo"/>
where a.bank_code = #{bankCode}
</select>
<select id="selectExamQuestionsBankByName" parameterType="String" resultMap="ExamQuestionsBankResult">
<include refid="selectExamQuestionsBankVo"/>
where a.bank_name = #{bankName}
</select>
<insert id="insertExamQuestionsBank" parameterType="ExamQuestionsBank" >
insert into exam_questions_bank

View File

@ -37,6 +37,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectExamQuestionsVo"/>
where questions_code = #{questionsCode}
</select>
<select id="selectExamQuestionsByTitle" parameterType="String" resultMap="ExamQuestionsResult">
<include refid="selectExamQuestionsVo"/>
where questions_title = #{questionsTitle}
</select>
<insert id="insertExamQuestions" parameterType="ExamQuestions" useGeneratedKeys="true" keyProperty="questionsId">
insert into exam_questions

View File

@ -19,7 +19,7 @@
<httpcore.version>4.4.16</httpcore.version>
<commons-codec.version>1.15</commons-codec.version>
<commons-logging.version>1.2</commons-logging.version>
<commons-io.version>2.11.0</commons-io.version>
<commons-io.version>2.15.1</commons-io.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
</properties>
@ -121,9 +121,5 @@
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -28,7 +28,7 @@
<fastjson.version>1.2.83</fastjson.version>
<oshi.version>6.4.6</oshi.version>
<jna.version>5.13.0</jna.version>
<commons.io.version>2.11.0</commons.io.version>
<commons.io.version>2.15.1</commons.io.version>
<commons.fileupload.version>1.5</commons.fileupload.version>
<commons.collections.version>3.2.2</commons.collections.version>
<poi.version>5.2.4</poi.version>
@ -161,8 +161,8 @@
<!-- MySQL驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>${mysql.version}</version>
</dependency>

View File

@ -39,8 +39,8 @@
<!-- Mysql驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!--oracle驱动-->

View File

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

Binary file not shown.

View File

@ -50,4 +50,12 @@ export function exportExamquestions(query) {
method: 'get',
params: query
})
}
// 下载考试题目导入模板
export function importTemplate() {
return request({
url: '/questions/examquestions/importTemplate',
method: 'get'
})
}

View File

@ -19,6 +19,11 @@ $--border-color-lighter: #e6ebf5;
$--table-border:1px solid#dfe6ec;
/* 添加缺失的变量定义 */
$fontColorWeight: 80% !default;
$--color-white: #ffffff !default;
$--tag-success-color: $--color-success !default;
/* icon font path, required */
$--font-path: '~element-ui/lib/theme-chalk/fonts';

View File

@ -32,6 +32,10 @@
<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
v-hasPermi="['questions:examquestions:remove']">删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="info" plain icon="el-icon-upload2" size="mini" :loading="exportLoading"
@click="handleImport" v-hasPermi="['questions:examquestions:import']">导入</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading"
@click="handleExport" v-hasPermi="['questions:examquestions:export']">导出</el-button>
@ -62,20 +66,45 @@
</el-table-column>
</el-table>
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
@pagination="getList" />
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize" @pagination="getList" />
</div>
</div>
<div v-else>
<exam-questions ref="editRef" @refreshData="editDoneHandle"></exam-questions>
</div>
<!-- 试题导入对话框 -->
<el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
<el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
:action="upload.url + '?updateSupport=' + upload.updateSupport + '&bankCode='+(bankData?.bankCode||'')"
:disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess"
:auto-upload="false" drag>
<i class="el-icon-upload"></i>
<div class="el-upload__text">
将文件拖到此处
<em>点击上传</em>
</div>
<div class="el-upload__tip" style="color:red;display: flex;" slot="tip">
<span>提示仅允许导入"xls""xlsx"格式文件</span>
<el-link type="info" style="font-size:12px;color:#1890ff" @click="importTemplate"></el-link>
</div>
</el-upload>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitFileForm"> </el-button>
<el-button @click="upload.open = false"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listQuestionsproperty, getQuestionsproperty, delQuestionsproperty, addQuestionsproperty, updateQuestionsproperty, exportQuestionsproperty } from "@/api/questions/questionsproperty";
import { listExamquestions, getExamquestions, delExamquestions, addExamquestions, updateExamquestions, exportExamquestions } from "@/api/questions/examquestions";
import { listExamquestions, getExamquestions, delExamquestions, addExamquestions, updateExamquestions, exportExamquestions, importTemplate } from "@/api/questions/examquestions";
import { getToken } from "@/utils/auth";
import ExamQuestions from './examQuestions'
export default {
@ -89,6 +118,21 @@ export default {
loading: true,
//
exportLoading: false,
//
upload: {
//
open: false,
//
title: "",
//
isUploading: false,
//
updateSupport: 0,
//
headers: { Authorization: "Bearer " + getToken() },
//
url: process.env.VUE_APP_BASE_API + "/questions/examquestions/importData"
},
//
ids: [],
//
@ -156,6 +200,7 @@ export default {
};
},
created() {
window.qlApp = this
this.getDicts("sys_normal_disable").then(response => {
this.statusOptions = response.data;
});
@ -335,6 +380,51 @@ export default {
this.exportLoading = false;
}).catch(() => { });
},
/** 导入按钮操作 */
handleImport() {
this.upload.title = "试题导入";
this.upload.open = true;
},
/** 下载模板操作 */
importTemplate() {
import('axios').then(axios => {
axios.default({
method: 'get',
url: 'data/questions.xlsx',
responseType: 'blob'
}).then(response => {
const blob = new Blob([response.data], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
});
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = '试题模板'+(+new Date())+'.xlsx';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(link.href);
}).catch(error => {
console.error('下载失败:', error);
this.msgError('下载模板失败');
});
});
},
//
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true;
},
//
handleFileSuccess(response, file, fileList) {
this.upload.open = false;
this.upload.isUploading = false;
this.$refs.upload.clearFiles();
this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
this.getList();
},
//
submitFileForm() {
this.$refs.upload.submit();
},
onClose() {
this.$emit('refreshDataList')
}

View File

@ -25,6 +25,28 @@ module.exports = {
lintOnSave: process.env.NODE_ENV === 'development',
// 如果你不需要生产环境的 source map可以将其设置为 false 以加速生产环境构建。
productionSourceMap: false,
// CSS 相关配置
css: {
loaderOptions: {
sass: {
// 抑制 Sass 弃用警告
sassOptions: {
quietDeps: true,
silenceDeprecations: ['slash-div', 'global-builtin', 'import', 'legacy-js-api']
},
// 添加额外的选项来抑制遗留JS API警告
additionalData: '@charset "UTF-8";'
},
scss: {
// 同样配置SCSS
sassOptions: {
quietDeps: true,
silenceDeprecations: ['slash-div', 'global-builtin', 'import', 'legacy-js-api']
},
additionalData: '@charset "UTF-8";'
}
}
},
devServer: {
host: '0.0.0.0',
port: port,