Compare commits
No commits in common. "2b5b365e2f61f02c17ace36c35bd99ae69dd0968" and "c33c0d923e87752dfbf97d04c78fcb6205b8ac0b" have entirely different histories.
2b5b365e2f
...
c33c0d923e
|
@ -83,7 +83,7 @@ export const constantRoutes = [
|
||||||
path: 'questionUpload',
|
path: 'questionUpload',
|
||||||
component: () => import('@/views/classTask/newClassTaskAssign/questionUpload/index.vue'),
|
component: () => import('@/views/classTask/newClassTaskAssign/questionUpload/index.vue'),
|
||||||
name: 'questionUpload',
|
name: 'questionUpload',
|
||||||
meta: { title: '习题上传', showBread: true }
|
meta: { title: '习题上传' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'aiKolors',
|
path: 'aiKolors',
|
||||||
|
|
|
@ -5,7 +5,6 @@ import { JYApiListCT, JYApiListOriginYear, JYApiListSO} from "@/utils/examQuesti
|
||||||
|
|
||||||
const useClassTaskStore = defineStore('classTask',{
|
const useClassTaskStore = defineStore('classTask',{
|
||||||
state: () => ({
|
state: () => ({
|
||||||
isOpenQuestUploadView: false, // 是否打开习题上传的页面
|
|
||||||
classListIds: [],
|
classListIds: [],
|
||||||
entpCourseWorkTypeList: [
|
entpCourseWorkTypeList: [
|
||||||
{value: 0, label: "不限"},
|
{value: 0, label: "不限"},
|
||||||
|
|
|
@ -149,14 +149,10 @@ import { useGetHomework } from '@/hooks/useGetHomework'
|
||||||
import { sessionStore } from '@/utils/store'
|
import { sessionStore } from '@/utils/store'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import useUserStore from '@/store/modules/user'
|
import useUserStore from '@/store/modules/user'
|
||||||
import useClassTaskStore from '@/store/modules/classTask'
|
|
||||||
|
|
||||||
const userStore = useUserStore().user
|
const userStore = useUserStore().user
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { proxy } = getCurrentInstance()
|
const { proxy } = getCurrentInstance()
|
||||||
const useClassTaskStores = useClassTaskStore();
|
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
currentCourse: Object,
|
currentCourse: Object,
|
||||||
})
|
})
|
||||||
|
@ -193,7 +189,6 @@ const boardLoading = ref(false);
|
||||||
const fileLoading = ref(false); // 常规作业loading
|
const fileLoading = ref(false); // 常规作业loading
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
console.log("----onMounted-------")
|
|
||||||
currentRow.value = {id:0};
|
currentRow.value = {id:0};
|
||||||
if(propsQueryCourseObj){
|
if(propsQueryCourseObj){
|
||||||
if(JSON.parse(propsQueryCourseObj)){
|
if(JSON.parse(propsQueryCourseObj)){
|
||||||
|
@ -221,28 +216,7 @@ onMounted(() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initHomeWork();
|
initHomeWork();
|
||||||
isInToMyQuestion(); // 如果是上传习题后返回的,跳转到个人题库
|
|
||||||
})
|
})
|
||||||
// 是否进入个人题库
|
|
||||||
const isInToMyQuestion = () => {
|
|
||||||
console.log('isOpenQuestUploadView',useClassTaskStores.isOpenQuestUploadView);
|
|
||||||
if(useClassTaskStores.isOpenQuestUploadView){
|
|
||||||
useClassTaskStores.isOpenQuestUploadView = false;
|
|
||||||
|
|
||||||
currentRow.value = {id:1}; // 作业设计
|
|
||||||
activeAptTab.value = "个人题库";
|
|
||||||
//提交内容清空 重置
|
|
||||||
classWorkForm.id = 0;
|
|
||||||
classWorkForm.uniquekey = ""; // 作业唯一标识 作业名称
|
|
||||||
classWorkForm.worktype = "习题训练"; //作业类型
|
|
||||||
classWorkForm.title = ""; // 作业说明
|
|
||||||
classWorkForm.quizlist = []; // 作业习题列表内容
|
|
||||||
classWorkForm.chooseWorkLists = []; // 作业框架梳理list
|
|
||||||
classWorkForm.fileHomeworkList = []; // 常规作业文件列表
|
|
||||||
classWorkForm.whiteboardObj = ""; // 作业资源 - 课堂展示 白板
|
|
||||||
classWorkForm.question = ""; // 作业资源 - 课堂展示 输入的问题
|
|
||||||
}
|
|
||||||
}
|
|
||||||
watch(() => props.currentCourse, (newVal, oldVal) => {
|
watch(() => props.currentCourse, (newVal, oldVal) => {
|
||||||
if(newVal){
|
if(newVal){
|
||||||
courseObj.textbookId = newVal.textbookId // 版本
|
courseObj.textbookId = newVal.textbookId // 版本
|
||||||
|
|
|
@ -74,7 +74,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import "vue-cropper/dist/index.css";
|
import "vue-cropper/dist/index.css";
|
||||||
import { VueCropper } from "vue-cropper";
|
import { VueCropper } from "vue-cropper";
|
||||||
import { onMounted, ref,watch, reactive, getCurrentInstance,nextTick, onUnmounted } from 'vue'
|
import { onMounted, ref,watch, reactive, getCurrentInstance,nextTick } from 'vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { cloneDeep } from 'lodash'
|
import { cloneDeep } from 'lodash'
|
||||||
|
|
||||||
|
@ -88,8 +88,6 @@ import { useRouter, useRoute } from 'vue-router'
|
||||||
|
|
||||||
import { ocrImg2ExamByManualUpl, ocrImg2ItemByManualUpl } from "@/views/classTask/newClassTaskAssign/questionUpload/ocrImg2ExamQues";
|
import { ocrImg2ExamByManualUpl, ocrImg2ItemByManualUpl } from "@/views/classTask/newClassTaskAssign/questionUpload/ocrImg2ExamQues";
|
||||||
import QuesItem from "@/views/classTask/newClassTaskAssign/questionUpload/quesItem/index.vue";
|
import QuesItem from "@/views/classTask/newClassTaskAssign/questionUpload/quesItem/index.vue";
|
||||||
import useClassTaskStore from '@/store/modules/classTask'
|
|
||||||
|
|
||||||
|
|
||||||
// const Remote = require('@electron/remote')
|
// const Remote = require('@electron/remote')
|
||||||
// const fs = require('fs');
|
// const fs = require('fs');
|
||||||
|
@ -98,9 +96,7 @@ import useUserStore from '@/store/modules/user'
|
||||||
const userStore = useUserStore().user
|
const userStore = useUserStore().user
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { proxy } = getCurrentInstance();
|
const { proxy } = getCurrentInstance()
|
||||||
const useClassTaskStores = useClassTaskStore();
|
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -155,7 +151,6 @@ const cropOption = reactive({
|
||||||
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
useClassTaskStores.isOpenQuestUploadView = true; // 打开过习题上传界面
|
|
||||||
console.log('propsQueryCourseObj', JSON.parse(propsQueryCourseObj));
|
console.log('propsQueryCourseObj', JSON.parse(propsQueryCourseObj));
|
||||||
if(propsQueryCourseObj&&JSON.parse(propsQueryCourseObj)){
|
if(propsQueryCourseObj&&JSON.parse(propsQueryCourseObj)){
|
||||||
courseObj.textbookId = JSON.parse(propsQueryCourseObj).bookObj // 版本
|
courseObj.textbookId = JSON.parse(propsQueryCourseObj).bookObj // 版本
|
||||||
|
@ -166,13 +161,7 @@ onMounted(() => {
|
||||||
}
|
}
|
||||||
initHomeWork();
|
initHomeWork();
|
||||||
})
|
})
|
||||||
onUnmounted(()=>{
|
|
||||||
// 延迟1s 关闭习题上传界面,作业管理界面需要根据 isOpenQuestUploadView 来进行判断
|
|
||||||
setTimeout(()=>{
|
|
||||||
useClassTaskStores.isOpenQuestUploadView = false; // 关闭习题上传界面
|
|
||||||
console.log('onUnmounted 习题上传');
|
|
||||||
}, 1000)
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 entpcourseid 获取作业列表
|
* 获取 entpcourseid 获取作业列表
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { ElMessageBox, ElMessage } from "element-plus";
|
import { ElMessageBox, ElMessage } from "element-plus";
|
||||||
import qs from "qs";
|
import qs from "qs";
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import request from '@/utils/request'
|
|
||||||
import { pyOCRAPI } from "@/api/education/entpcoursework";
|
import { pyOCRAPI } from "@/api/education/entpcoursework";
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,20 +9,13 @@ const baidubceConfig = {
|
||||||
// Header
|
// Header
|
||||||
'Content-Type': "application/x-www-form-urlencoded",
|
'Content-Type': "application/x-www-form-urlencoded",
|
||||||
// 格式
|
// 格式
|
||||||
'Accept': 'application/json',
|
'Accept' : 'application/json',
|
||||||
// id(临时测试)
|
// id(临时测试)
|
||||||
'client_id': "U0DrGBE6X92IXgV6cJMNON8F",
|
'client_id': "U0DrGBE6X92IXgV6cJMNON8F",
|
||||||
// 密钥(临时测试)
|
// 密钥(临时测试)
|
||||||
'client_secret': 'oWb0M0YWMmZPMQIhIUkJX99ddr7h61qf',
|
'client_secret': 'oWb0M0YWMmZPMQIhIUkJX99ddr7h61qf',
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getOcrContent(data) {
|
|
||||||
return request({
|
|
||||||
url: '/ocr/exam',
|
|
||||||
method: 'post',
|
|
||||||
data: data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,8 +34,8 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
|
||||||
let regex = null;
|
let regex = null;
|
||||||
// 识别内容拼接
|
// 识别内容拼接
|
||||||
let ocrTxt = ''
|
let ocrTxt = ''
|
||||||
|
|
||||||
if (isLocalTest) {
|
if(isLocalTest) {
|
||||||
// 临时本地测试(json格式跟百度ocr一致)
|
// 临时本地测试(json格式跟百度ocr一致)
|
||||||
const response = await fetch('/cropImgTest/single.json');
|
const response = await fetch('/cropImgTest/single.json');
|
||||||
const resOcr = await response.json();
|
const resOcr = await response.json();
|
||||||
|
@ -67,7 +59,7 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const tmp = await ocrImg2Json(imgBase64);
|
const tmp = await ocrImg2Json(imgBase64);
|
||||||
if (!tmp?.data) {
|
if(!tmp?.data) {
|
||||||
return examItem;
|
return examItem;
|
||||||
}
|
}
|
||||||
ocrJson = tmp.data.results;
|
ocrJson = tmp.data.results;
|
||||||
|
@ -77,12 +69,12 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ocrJson == '') {
|
if(ocrJson == '') {
|
||||||
ElMessage.error('[人工录入-单项]识别的图片为空, 识别失败, 请检查重试!');
|
ElMessage.error('[人工录入-单项]识别的图片为空, 识别失败, 请检查重试!');
|
||||||
return examItem;
|
return examItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ocrTxt == '') {
|
if(ocrTxt == '') {
|
||||||
ElMessage.error('[人工录入-单项]识别内容拼接失败, 请检查重试!');
|
ElMessage.error('[人工录入-单项]识别内容拼接失败, 请检查重试!');
|
||||||
return examItem;
|
return examItem;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +87,7 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
|
||||||
ocrTxt = ocrTxt.replace(regex, '').replace(/<br \/>/g, '');
|
ocrTxt = ocrTxt.replace(regex, '').replace(/<br \/>/g, '');
|
||||||
examItem = ocrTxt;
|
examItem = ocrTxt;
|
||||||
}
|
}
|
||||||
else if (curItem === 'workdesc') {
|
else if (curItem === 'workdesc') {
|
||||||
// 该类型下无需[判断题]和[主观题]处理
|
// 该类型下无需[判断题]和[主观题]处理
|
||||||
if (examType.includes('复合题')) {
|
if (examType.includes('复合题')) {
|
||||||
// 因[题目+选项]分离正则匹配需要, 故需开头手动拼一个<br />
|
// 因[题目+选项]分离正则匹配需要, 故需开头手动拼一个<br />
|
||||||
|
@ -104,13 +96,13 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
|
||||||
worktype: '单选题',
|
worktype: '单选题',
|
||||||
params: [],
|
params: [],
|
||||||
}
|
}
|
||||||
mutiParams.arrWorkDesc.forEach(item => {
|
mutiParams.arrWorkDesc.forEach( item => {
|
||||||
const obj = {
|
const obj = {
|
||||||
title: item.title,
|
title: item.title,
|
||||||
workanswer: '',
|
workanswer: '',
|
||||||
checkAnswer: [],
|
checkAnswer: [],
|
||||||
type: item.type,
|
type: item.type,
|
||||||
options: item.options.map(element => { return { text: element.replace(/<br \/>/g, '') } }),
|
options: item.options.map(element => {return {text: element.replace(/<br \/>/g, '')}}),
|
||||||
}
|
}
|
||||||
examItem.params.push(obj);
|
examItem.params.push(obj);
|
||||||
});
|
});
|
||||||
|
@ -122,7 +114,7 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
|
||||||
// 先判断是否存在选项标识, 且存在2个及以上(A.---1.---(1)---(1))
|
// 先判断是否存在选项标识, 且存在2个及以上(A.---1.---(1)---(1))
|
||||||
regex = /\s*[A-H][..。]/g;
|
regex = /\s*[A-H][..。]/g;
|
||||||
const matches = ocrTxt.match(regex);
|
const matches = ocrTxt.match(regex);
|
||||||
if (matches == null || matches.length < 2) {
|
if (matches==null || matches.length < 2){
|
||||||
ElMessage.error('[人工录入-单项]识别[选项]失败, 请检查重试!');
|
ElMessage.error('[人工录入-单项]识别[选项]失败, 请检查重试!');
|
||||||
return examItem;
|
return examItem;
|
||||||
}
|
}
|
||||||
|
@ -146,7 +138,7 @@ export const ocrImg2ItemByManualUpl = async (isLocalTest = false, imgBase64 = ''
|
||||||
examItem.push(obj);
|
examItem.push(obj);
|
||||||
return examItem;
|
return examItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (curItem === 'workanswer') {
|
else if (curItem === 'workanswer') {
|
||||||
// 该类型下只做[主观题]和[复合题]的处理
|
// 该类型下只做[主观题]和[复合题]的处理
|
||||||
|
@ -171,8 +163,8 @@ export const ocrImg2ExamByManualUpl = async (isLocalTest = false, imgBase64 = ''
|
||||||
let ocrJson = '';
|
let ocrJson = '';
|
||||||
// 识别内容拼接
|
// 识别内容拼接
|
||||||
let ocrTxt = '';
|
let ocrTxt = '';
|
||||||
|
|
||||||
if (isLocalTest) {
|
if(isLocalTest) {
|
||||||
// 临时本地测试(json格式跟百度ocr一致)
|
// 临时本地测试(json格式跟百度ocr一致)
|
||||||
const response = await fetch('/cropImgTest/single.json');
|
const response = await fetch('/cropImgTest/single.json');
|
||||||
const resOcr = await response.json();
|
const resOcr = await response.json();
|
||||||
|
@ -181,7 +173,7 @@ export const ocrImg2ExamByManualUpl = async (isLocalTest = false, imgBase64 = ''
|
||||||
ocrJson.forEach(ele => {
|
ocrJson.forEach(ele => {
|
||||||
ocrTxt += `${ele.words.word}<br />`;
|
ocrTxt += `${ele.words.word}<br />`;
|
||||||
});
|
});
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
// 备用ocr识别服务 (python的一个识别服务)
|
// 备用ocr识别服务 (python的一个识别服务)
|
||||||
// const response = await ocrImgPyJson(imgBase64);
|
// const response = await ocrImgPyJson(imgBase64);
|
||||||
|
@ -194,7 +186,7 @@ export const ocrImg2ExamByManualUpl = async (isLocalTest = false, imgBase64 = ''
|
||||||
// });
|
// });
|
||||||
} else {
|
} else {
|
||||||
const tmp = await ocrImg2Json(imgBase64);
|
const tmp = await ocrImg2Json(imgBase64);
|
||||||
if (!tmp?.data) {
|
if(!tmp?.data) {
|
||||||
return examQues;
|
return examQues;
|
||||||
}
|
}
|
||||||
ocrJson = tmp.data.results;
|
ocrJson = tmp.data.results;
|
||||||
|
@ -203,20 +195,20 @@ export const ocrImg2ExamByManualUpl = async (isLocalTest = false, imgBase64 = ''
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ocrJson == '') {
|
if(ocrJson == '') {
|
||||||
ElMessage.error('[人工录入-整题]图片识别内容为空, 识别失败, 请重试!');
|
ElMessage.error('[人工录入-整题]图片识别内容为空, 识别失败, 请重试!');
|
||||||
return examQues;
|
return examQues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(ocrTxt == '') {
|
||||||
if (ocrTxt == '') {
|
|
||||||
ElMessage.error('[人工录入-整题]识别内容拼接失败, 请重试!');
|
ElMessage.error('[人工录入-整题]识别内容拼接失败, 请重试!');
|
||||||
return examQues;
|
return examQues;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 识别内容转为试题结构
|
// 识别内容转为试题结构
|
||||||
examQues = assembleExam(ocrTxt);
|
examQues = assembleExam(ocrTxt);
|
||||||
if (examQues.err != '') {
|
if(examQues.err != '') {
|
||||||
ElMessage.error(`[人工录入-整题]${examQues.err}, 请重试!`);
|
ElMessage.error(`[人工录入-整题]${examQues.err}, 请重试!`);
|
||||||
examQues = {};
|
examQues = {};
|
||||||
}
|
}
|
||||||
|
@ -234,36 +226,30 @@ const ocrImg2Json = async (urlBase64) => {
|
||||||
ElMessage.error("未检测到截图图片, 请截取图片后再识别");
|
ElMessage.error("未检测到截图图片, 请截取图片后再识别");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
let base64Code = urlBase64.split(",")[1];
|
const resToken = await bdyAPI_getToken();
|
||||||
const resOcr = await getOcrContent({ base64Code: base64Code });
|
if (resToken.status !== 200) {
|
||||||
if (resOcr.code !== 200) {
|
ElMessage.error("百度智能云用户标识有误");
|
||||||
ElMessage.error("图片识别错误");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// const resToken = await bdyAPI_getToken();
|
|
||||||
// if (resToken.status !== 200) {
|
|
||||||
// ElMessage.error("百度智能云用户标识有误");
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const token = resToken.data?.access_token;
|
const token = resToken.data?.access_token;
|
||||||
// let base64Code = urlBase64.split(",")[1];
|
let base64Code = urlBase64.split(",")[1];
|
||||||
// const query = {
|
const query = {
|
||||||
// image: base64Code, //图片地址(base64)
|
image: base64Code, //图片地址(base64)
|
||||||
// line_probability: false, //是否返回每行识别结果的置信度。默认为false
|
line_probability: false, //是否返回每行识别结果的置信度。默认为false
|
||||||
// disp_line_poly: false, //是否返回每行的四角点坐标。默认为false
|
disp_line_poly: false, //是否返回每行的四角点坐标。默认为false
|
||||||
// words_type: 'handprint_mix', //文字类型。 默认:印刷文字识别 = handwring_only:手写文字识别 = handprint_mix: 手写印刷混排识别
|
words_type: 'handprint_mix', //文字类型。 默认:印刷文字识别 = handwring_only:手写文字识别 = handprint_mix: 手写印刷混排识别
|
||||||
// layout_analysis: false, //是否分析文档版面:包括layout(图、表、标题、段落、目录);attribute(栏、页眉、页脚、页码、脚注)的分析输出
|
layout_analysis: false, //是否分析文档版面:包括layout(图、表、标题、段落、目录);attribute(栏、页眉、页脚、页码、脚注)的分析输出
|
||||||
// recg_long_division: false, //是否检测并识别手写竖式
|
recg_long_division: false, //是否检测并识别手写竖式
|
||||||
// recg_formula: true, //控制是否检测并识别公式,默认为false
|
recg_formula: true, //控制是否检测并识别公式,默认为false
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
|
||||||
// const resOcr = await bdyAPI_getOcrContent(token, base64Code, query);
|
const resOcr = await bdyAPI_getOcrContent(token, base64Code, query);
|
||||||
// if (resOcr.status !== 200) {
|
if (resOcr.status !== 200) {
|
||||||
// ElMessage.error("百度智能云图片识别错误");
|
ElMessage.error("百度智能云图片识别错误");
|
||||||
// return null;
|
return null;
|
||||||
// }
|
}
|
||||||
|
|
||||||
return resOcr;
|
return resOcr;
|
||||||
}
|
}
|
||||||
|
@ -278,7 +264,7 @@ const ocrImgPyJson = async (urlBase64) => {
|
||||||
ElMessage.error("未检测到截图图片, 请截取图片后再识别");
|
ElMessage.error("未检测到截图图片, 请截取图片后再识别");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const resOcr = await pyOCRAPI(urlBase64);
|
const resOcr = await pyOCRAPI(urlBase64);
|
||||||
if (resOcr.status !== 200) {
|
if (resOcr.status !== 200) {
|
||||||
ElMessage.error("图片识别错误");
|
ElMessage.error("图片识别错误");
|
||||||
|
@ -365,7 +351,7 @@ const assembleExam = (eachSub) => {
|
||||||
|
|
||||||
let regex = null;
|
let regex = null;
|
||||||
let titleAndWorkDesc = '',
|
let titleAndWorkDesc = '',
|
||||||
answer = '';
|
answer = '';
|
||||||
|
|
||||||
|
|
||||||
// 获取[题源] - 格式化
|
// 获取[题源] - 格式化
|
||||||
|
@ -375,7 +361,7 @@ const assembleExam = (eachSub) => {
|
||||||
subObj.worktag = workTag[0].replace(/^\d*[..。]/g, '');
|
subObj.worktag = workTag[0].replace(/^\d*[..。]/g, '');
|
||||||
subObj.worktag = subObj.worktag.replace('(', '(').replace(')', ')');
|
subObj.worktag = subObj.worktag.replace('(', '(').replace(')', ')');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 去掉开头的序号和题源
|
// 去掉开头的序号和题源
|
||||||
eachSub = eachSub.replace(regex, '');
|
eachSub = eachSub.replace(regex, '');
|
||||||
// 先判断是否存在答案
|
// 先判断是否存在答案
|
||||||
|
@ -384,7 +370,7 @@ const assembleExam = (eachSub) => {
|
||||||
if (!hasAnswer) {
|
if (!hasAnswer) {
|
||||||
// 不存在答案, 仅处理[题干+选项]
|
// 不存在答案, 仅处理[题干+选项]
|
||||||
titleAndWorkDesc = eachSub;
|
titleAndWorkDesc = eachSub;
|
||||||
} else {
|
}else {
|
||||||
// 存在答案, 需处理[题干+选项]和[答案+解析]
|
// 存在答案, 需处理[题干+选项]和[答案+解析]
|
||||||
regex = /(<br \/>?\s*[【\[].*?[】\]])/g;
|
regex = /(<br \/>?\s*[【\[].*?[】\]])/g;
|
||||||
let tmpList = eachSub.split(regex);
|
let tmpList = eachSub.split(regex);
|
||||||
|
@ -400,10 +386,10 @@ const assembleExam = (eachSub) => {
|
||||||
// 第二部分[分析-答案] 处理
|
// 第二部分[分析-答案] 处理
|
||||||
let answerAndAnswer = {};
|
let answerAndAnswer = {};
|
||||||
// 将第二部分的内容做key-value绑定 - 键为【分析】、【讨论】、【方法】等. 值为随之分隔的内容
|
// 将第二部分的内容做key-value绑定 - 键为【分析】、【讨论】、【方法】等. 值为随之分隔的内容
|
||||||
for (let i = 1; i < tmpList.length - 1; i = i + 2) {
|
for (let i=1; i<tmpList.length-1; i=i+2){
|
||||||
let key = tmpList[i];
|
let key = tmpList[i];
|
||||||
key = key.replace(/<br \/>|【|】|\[|\]/g, '');
|
key = key.replace(/<br \/>|【|】|\[|\]/g, '');
|
||||||
let value = tmpList[i + 1];
|
let value = tmpList[i+1];
|
||||||
value = value.replace(/^<br \/>+|<br \/>+$/g, '');
|
value = value.replace(/^<br \/>+|<br \/>+$/g, '');
|
||||||
answerAndAnswer[key] = value;
|
answerAndAnswer[key] = value;
|
||||||
}
|
}
|
||||||
|
@ -444,12 +430,12 @@ const assembleExam = (eachSub) => {
|
||||||
|
|
||||||
// [答案] - 初步初始化 --- 根据答案判断试题大分类: 复合题(实际为大题) 或 其他基础题型(单选,多选,填空,判断)
|
// [答案] - 初步初始化 --- 根据答案判断试题大分类: 复合题(实际为大题) 或 其他基础题型(单选,多选,填空,判断)
|
||||||
answer = answerAndAnswer['答案'].trim();
|
answer = answerAndAnswer['答案'].trim();
|
||||||
if (!answer) {
|
if(!answer) {
|
||||||
answer = answerAndAnswer['答案及评分参考'].trim();
|
answer = answerAndAnswer['答案及评分参考'].trim();
|
||||||
answer = answer.replace(/^\d+[\u4e00-\u9fa5][..。]\s*<br \/>/, ''); // 去掉 - 有些开头会有[xx分。]
|
answer = answer.replace(/^\d+[\u4e00-\u9fa5][..。]\s*<br \/>/, ''); // 去掉 - 有些开头会有[xx分。]
|
||||||
}
|
}
|
||||||
// 将多余的空格替换为固定的4个空格
|
// 将多余的空格替换为固定的4个空格
|
||||||
answer = answer.replaceAll("\\s{3,}", " ");
|
answer = answer.replaceAll("\\s{3,}"," ");
|
||||||
if (answer == null | answer == '') {
|
if (answer == null | answer == '') {
|
||||||
subObj.err = '题目缺少[答案]';
|
subObj.err = '题目缺少[答案]';
|
||||||
return subObj;
|
return subObj;
|
||||||
|
@ -469,7 +455,7 @@ const assembleExam = (eachSub) => {
|
||||||
let answerFind = regex.test(answer);
|
let answerFind = regex.test(answer);
|
||||||
regex = /(\d+[..。]|\(\d+\)|(\d+))/;
|
regex = /(\d+[..。]|\(\d+\)|(\d+))/;
|
||||||
let titleFind = regex.test(titleAndWorkDesc);
|
let titleFind = regex.test(titleAndWorkDesc);
|
||||||
if (titleFind && answerFind) {
|
if(titleFind && answerFind){
|
||||||
/**
|
/**
|
||||||
* [复合题] - 处理逻辑
|
* [复合题] - 处理逻辑
|
||||||
*/
|
*/
|
||||||
|
@ -485,7 +471,7 @@ const assembleExam = (eachSub) => {
|
||||||
|
|
||||||
if (tmpExam) {
|
if (tmpExam) {
|
||||||
// 错误信息
|
// 错误信息
|
||||||
if (tmpExam.errMsg !== '') {
|
if(tmpExam.errMsg !== '') {
|
||||||
subObj.err = tmpExam.err;
|
subObj.err = tmpExam.err;
|
||||||
return subObj;
|
return subObj;
|
||||||
}
|
}
|
||||||
|
@ -498,7 +484,7 @@ const assembleExam = (eachSub) => {
|
||||||
subObj.workanswer = JSON.stringify(tmpExam.arrWorkAnswer);
|
subObj.workanswer = JSON.stringify(tmpExam.arrWorkAnswer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return subObj;
|
return subObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,7 +508,7 @@ const processExamSingle = function (titleAndWorkDesc, answer) {
|
||||||
let matcher = null;
|
let matcher = null;
|
||||||
|
|
||||||
/** [判断题]的处理逻辑, resp: -1-未找到 0-*为对应匹配的index */
|
/** [判断题]的处理逻辑, resp: -1-未找到 0-*为对应匹配的index */
|
||||||
let judgedStatus = answer !== '' ? containsExactMatch(answer) : -1;
|
let judgedStatus = answer!=='' ? containsExactMatch(answer) : -1;
|
||||||
|
|
||||||
/** 其他基础题型(单选,多选,填空,判断)的处理逻辑 */
|
/** 其他基础题型(单选,多选,填空,判断)的处理逻辑 */
|
||||||
// 先去掉开头的试题序号
|
// 先去掉开头的试题序号
|
||||||
|
@ -538,7 +524,7 @@ const processExamSingle = function (titleAndWorkDesc, answer) {
|
||||||
answer = answer.replace("<br />", "").trim();
|
answer = answer.replace("<br />", "").trim();
|
||||||
|
|
||||||
// [题型] - 格式化 - 根据答案字符个数区分[单选]或[多选]
|
// [题型] - 格式化 - 根据答案字符个数区分[单选]或[多选]
|
||||||
examSingle.workType = answer === '' ? '单选题' : answer.length == 1 ? "单选题" : "多选题";
|
examSingle.workType = answer==='' ? '单选题' : answer.length == 1 ? "单选题" : "多选题";
|
||||||
|
|
||||||
// 切分题干+选项
|
// 切分题干+选项
|
||||||
regex = /<br \/>*\s*[A-H][..。]/g;
|
regex = /<br \/>*\s*[A-H][..。]/g;
|
||||||
|
@ -549,12 +535,12 @@ const processExamSingle = function (titleAndWorkDesc, answer) {
|
||||||
|
|
||||||
// [选项]-处理 --- ['ABC123','ABC123']
|
// [选项]-处理 --- ['ABC123','ABC123']
|
||||||
for (let i = 1; i < tmpSplit.length; i++) {
|
for (let i = 1; i < tmpSplit.length; i++) {
|
||||||
let option = tmpSplit[i].replace("<br />", "").trim();
|
let option = tmpSplit[i].replace("<br />", "").trim();
|
||||||
//option = option.replace("_", "");
|
//option = option.replace("_", "");
|
||||||
// [选项] - 格式化
|
// [选项] - 格式化
|
||||||
examSingle.arrWorkDesc.push(option);
|
examSingle.arrWorkDesc.push(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [题目答案] --- ['0'] | ['0','1']
|
// [题目答案] --- ['0'] | ['0','1']
|
||||||
if (answer !== '') {
|
if (answer !== '') {
|
||||||
// 答案为空时, 置空后直接返回
|
// 答案为空时, 置空后直接返回
|
||||||
|
@ -584,7 +570,7 @@ const processExamSingle = function (titleAndWorkDesc, answer) {
|
||||||
examSingle.arrWorkAnswer = answer.split(" ");
|
examSingle.arrWorkAnswer = answer.split(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (judgedStatus != -1) {
|
else if( judgedStatus != -1 ) {
|
||||||
/**
|
/**
|
||||||
* 判断题
|
* 判断题
|
||||||
*/
|
*/
|
||||||
|
@ -649,48 +635,48 @@ const processExamMulti = function (titleAndWorkDesc, answer) {
|
||||||
// 先确定当前是以什么形式的小题序号来切分 --- 需要全部独立判断, 避免出现复合题中, 每小题内还包含小题的情况--- 1.回答以下问题 (1)***** (2)******
|
// 先确定当前是以什么形式的小题序号来切分 --- 需要全部独立判断, 避免出现复合题中, 每小题内还包含小题的情况--- 1.回答以下问题 (1)***** (2)******
|
||||||
let cliceSucc = false;
|
let cliceSucc = false;
|
||||||
let arrAnswer = []
|
let arrAnswer = []
|
||||||
if (!cliceSucc) {
|
if(!cliceSucc){
|
||||||
regex = /<br \/>\s*\d+[..。]\s*/;
|
regex = /<br \/>\s*\d+[..。]\s*/;
|
||||||
if (regex.test(titleAndWorkDesc)) {
|
if (regex.test(titleAndWorkDesc)) {
|
||||||
// 再次以答案中的序号同步匹配一次
|
// 再次以答案中的序号同步匹配一次
|
||||||
regex = /^\s*\d+[..。]\s*/;
|
regex = /^\s*\d+[..。]\s*/;
|
||||||
if (answer === '' || regex.test(answer)) {
|
if(answer === '' || regex.test(answer)){
|
||||||
regex = /<br \/>\s*\d+[..。]\s*/g;
|
regex = /<br \/>\s*\d+[..。]\s*/g;
|
||||||
tmpSplit = titleAndWorkDesc.split(regex);
|
tmpSplit = titleAndWorkDesc.split(regex);
|
||||||
if (answer !== '') {
|
if (answer !== '') {
|
||||||
// 存在答案时, 再校验
|
// 存在答案时, 再校验
|
||||||
regex = /^\s*\d+[..。]\s*|<br \/>\s*\d+[..。]\s*|\s+\d+[..。]\s*/g;
|
regex = /^\s*\d+[..。]\s*|<br \/>\s*\d+[..。]\s*|\s+\d+[..。]\s*/g;
|
||||||
arrAnswer = answer.split(regex);
|
arrAnswer = answer.split(regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
cliceSucc = true;
|
cliceSucc = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!cliceSucc) {
|
if (!cliceSucc){
|
||||||
regex = /<br \/>\s*(\d+)\s*/;
|
regex = /<br \/>\s*(\d+)\s*/;
|
||||||
if (regex.test(titleAndWorkDesc)) {
|
if (regex.test(titleAndWorkDesc)) {
|
||||||
// 再次以答案中的序号同步匹配一次
|
// 再次以答案中的序号同步匹配一次
|
||||||
regex = /\s*(\d+)\s*/;
|
regex = /\s*(\d+)\s*/;
|
||||||
if (answer === '' || regex.test(answer)) {
|
if(answer === '' || regex.test(answer)){
|
||||||
regex = /<br \/>\s*(\d+)\s*/g;
|
regex = /<br \/>\s*(\d+)\s*/g;
|
||||||
tmpSplit = titleAndWorkDesc.split(regex);
|
tmpSplit = titleAndWorkDesc.split(regex);
|
||||||
if (answer !== '') {
|
if (answer !== '') {
|
||||||
// 存在答案时, 再校验
|
// 存在答案时, 再校验
|
||||||
regex = /^\s*(\d+)\s*|<br \/>\s*(\d+)\s*|\s+(\d+)\s*/g;
|
regex = /^\s*(\d+)\s*|<br \/>\s*(\d+)\s*|\s+(\d+)\s*/g;
|
||||||
arrAnswer = answer.split(regex);
|
arrAnswer = answer.split(regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
cliceSucc = true;
|
cliceSucc = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!cliceSucc) {
|
if (!cliceSucc){
|
||||||
regex = /<br \/>\s*\(\d+\)\s*/;
|
regex = /<br \/>\s*\(\d+\)\s*/;
|
||||||
if (regex.test(titleAndWorkDesc)) {
|
if (regex.test(titleAndWorkDesc)) {
|
||||||
// 再次以答案中的序号同步匹配一次
|
// 再次以答案中的序号同步匹配一次
|
||||||
regex = /^\s*\(\d+\)\s*/;
|
regex = /^\s*\(\d+\)\s*/;
|
||||||
if (answer === '' || regex.test(answer)) {
|
if(answer === '' || regex.test(answer)){
|
||||||
regex = /<br \/>\s*\(\d+\)\s*/g;
|
regex = /<br \/>\s*\(\d+\)\s*/g;
|
||||||
tmpSplit = titleAndWorkDesc.split(regex);
|
tmpSplit = titleAndWorkDesc.split(regex);
|
||||||
if (answer !== '') {
|
if (answer !== '') {
|
||||||
|
@ -703,19 +689,19 @@ const processExamMulti = function (titleAndWorkDesc, answer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!cliceSucc) {
|
if (!cliceSucc){
|
||||||
examMulti.errMsg = '[复合题]小题与答案序号[不匹配]';
|
examMulti.errMsg = '[复合题]小题与答案序号[不匹配]';
|
||||||
return examMulti;
|
return examMulti;
|
||||||
}
|
}
|
||||||
if (tmpSplit.length < 2) {
|
if (tmpSplit.length < 2){
|
||||||
examMulti.errMsg = '[复合题]题干与小题[切分失败]';
|
examMulti.errMsg = '[复合题]题干与小题[切分失败]';
|
||||||
return examMulti;
|
return examMulti;
|
||||||
}
|
}
|
||||||
if (answer !== '' && arrAnswer.length < 2) {
|
if (answer !== '' && arrAnswer.length < 2){
|
||||||
examMulti.errMsg = '[复合题]答案切分小题失败';
|
examMulti.errMsg = '[复合题]答案切分小题失败';
|
||||||
return examMulti;
|
return examMulti;
|
||||||
}
|
}
|
||||||
if (answer !== '' && tmpSplit.length != arrAnswer.length) {
|
if (answer !== '' && tmpSplit.length != arrAnswer.length){
|
||||||
examMulti.errMsg = '[复合题]小题个数与答案个数[不一致]';
|
examMulti.errMsg = '[复合题]小题个数与答案个数[不一致]';
|
||||||
return examMulti;
|
return examMulti;
|
||||||
}
|
}
|
||||||
|
@ -724,13 +710,13 @@ const processExamMulti = function (titleAndWorkDesc, answer) {
|
||||||
examMulti.title = tmpSplit[0].trim();
|
examMulti.title = tmpSplit[0].trim();
|
||||||
|
|
||||||
// [选项]+[答案] - 逻辑处理
|
// [选项]+[答案] - 逻辑处理
|
||||||
for (let i = 1; i < tmpSplit.length; i++) {
|
for (let i=1; i<tmpSplit.length; i++){
|
||||||
const tmp = tmpSplit[i].trim();
|
const tmp = tmpSplit[i].trim();
|
||||||
// 因arrAnswer[0]对应为分隔出来的首位空数组, 故这里也可直接使用i=1作为下标获取答案
|
// 因arrAnswer[0]对应为分隔出来的首位空数组, 故这里也可直接使用i=1作为下标获取答案
|
||||||
const tmpAnswer = answer === '' ? '' : arrAnswer[i].trim();
|
const tmpAnswer = answer === '' ? '' : arrAnswer[i].trim();
|
||||||
// 单题处理
|
// 单题处理
|
||||||
const tmpExam = processExamSingle(tmp, tmpAnswer);
|
const tmpExam = processExamSingle(tmp, tmpAnswer);
|
||||||
if (tmpExam.errMsg !== '') {
|
if(tmpExam.errMsg !== ''){
|
||||||
examMulti.errMsg = '[复合题]小题解析失败';
|
examMulti.errMsg = '[复合题]小题解析失败';
|
||||||
return examMulti;
|
return examMulti;
|
||||||
}
|
}
|
||||||
|
@ -782,10 +768,10 @@ const containsExactMatch = function (answer) {
|
||||||
answer = answer.replace("_____", "");
|
answer = answer.replace("_____", "");
|
||||||
let index = 0;
|
let index = 0;
|
||||||
for (let item of EXAM_JUDGED_DICTIONARY) {
|
for (let item of EXAM_JUDGED_DICTIONARY) {
|
||||||
if (answer === item) {
|
if (answer === item) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
Loading…
Reference in New Issue