var allTixingArr = [
'默写',
'作文',
'其他',
'短文',
'句子',
'单句',
'填空题',
'简答题',
'解答题',
'判断题', //判断
'双选题',
'计算题',
'作图题',
'综合题',
'推断题',
'实验题',
'探究题',
'选择题', //多选
'辨析题',
'论述题',
'简析题',
'多选题', //多选
'单选题', //单选
'连线题',
'诗歌鉴赏',
'语言表达',
'名著导读',
'完形填空',
'单词辩音',
'单词释义',
'阅读理解',
'阅读表达',
'语法填空',
'短文改错',
'阅读填空',
'单句改错',
'完成句子',
'句型转换',
'句子翻译',
'书面表达',
'非选择题',
'现代文阅读',
'文言文阅读',
'阅读七选五',
'任务型阅读',
'任务型读写',
'识图作答题',
'材料解析题',
'分析评价题',
'技术应用题',
'作图读图题',
'不定项选择题', //多选
'单句语法填空',
'实验题探究题',
'首字母短文填空'];
//文档全解析
var xiaotiMiaoshu = []; //小题描述
var daanhejiexi = ""; //答案和解析
var allCount = 0; //总的题目数量
var plainTxt = "";
function startFenxi(){
if($.trim(ue.getPlainTxt()) == ""){
layer.open({
title:"抱歉",
content:"没有检测到内容"
});
return false;
}
plainTxt = ue.getPlainTxt().substring(0, ue.getPlainTxt().indexOf("答案和解析"));
daanhejiexi = ue.getPlainTxt().substring(ue.getPlainTxt().indexOf("答案和解析"));
//去掉所有回车和换行
plainTxt = plainTxt.replace(/\n/g, "");
daanhejiexi = daanhejiexi.replace(/\n/g, "");
//判断是否匹配类型,如果是则可以取试卷标题
if(daanhejiexi.length > 0){
$("#paper-name").val((plainTxt.substring(0, plainTxt.indexOf("副标题"))));
}
var tixingStrArr = []; //存储当前得到的题型
var tixingCount = 0;
for(var i=0; i<allTixingArr.length; i++){
if(plainTxt.indexOf("、"+allTixingArr[i]+"(") != -1){
tixingCount ++;
tixingStrArr.push(allTixingArr[i]);
}
}
//大题的序号需要找出然后删除
var indexArr = []; //将得到的题型进行排序
for(var i=0; i<tixingStrArr.length; i++){
//获取对应的大题序号
var xuhaoStr = plainTxt.substring(plainTxt.indexOf("、" + tixingStrArr[i] + "(") -1, plainTxt.indexOf("、" + tixingStrArr[i] + "("));
if(tixingStrArr.length <= 9){
tixingStrArr[i] = xuhaoStr + "、" + tixingStrArr[i] + "(";
}else if(tixingStrArr.length <= 20){
var firstStr = plainTxt.substring(plainTxt.indexOf("、" + tixingStrArr[i] + "(") -2, plainTxt.indexOf("、" + tixingStrArr[i] + "(") - 1);
if(firstStr === "十" || firstStr === "二"){
xuhaoStr = firstStr + xuhaoStr;
}
}
indexArr.push(plainTxt.indexOf(tixingStrArr[i]));
}
//对得到的题型进行排序
for(var i=0;i<indexArr.length-1;i++){//外层循环控制排序趟数
for(var j=0;j<indexArr.length-1-i;j++){//内层循环控制每一趟排序多少次
if(indexArr[j]>indexArr[j+1]){
//序号排序
var temp=indexArr[j];
indexArr[j]=indexArr[j+1];
indexArr[j+1]=temp;
//排序题型以适配文档题目类型顺序
var temp2=tixingStrArr[j];
tixingStrArr[j]=tixingStrArr[j+1];
tixingStrArr[j+1]=temp2;
}
}
}
//此时tixingArr是已经排列好顺序的
var datiStrArr = []; //存储每一道大题的题文
for(var i=0; i<tixingStrArr.length; i++){
if(i == tixingStrArr.length -1 ){ //最后一种
datiStrArr.push(plainTxt.substring(plainTxt.indexOf(tixingStrArr[i])));
}else{
datiStrArr.push(plainTxt.substring(plainTxt.indexOf(tixingStrArr[i]), plainTxt.indexOf(tixingStrArr[(i+1)])));
}
}
//得到了每道大题的题文内容后进行解析判断这道题总共有多少道小题,这样可以循环
var xiaotiCountArr = []; //每道大题的小题个数
var stat = 0; //序号
var startIndex = 1;
for(var i=0; i<datiStrArr.length; i++){
var xiaotiCount = datiStrArr[i].substring(datiStrArr[i].indexOf("本大题共")+4, datiStrArr[i].indexOf("小题,"));
var xiaotiScore = datiStrArr[i].substring(datiStrArr[i].indexOf("小题,共")+4, datiStrArr[i].indexOf(".0分)"));
xiaotiCountArr.push(parseInt(xiaotiCount));
//保存题的描述,包括题型,小题数量,小题分数
var tixing = tixingStrArr[i];
var tiCount = xiaotiCount;
allCount += parseInt(xiaotiCount);
var tiScore = xiaotiScore;
if(i === 0){
startIndex = 1;
}else{
startIndex += parseInt(xiaotiCountArr[(i-1)]); //开始序号为上一题的开始+上一题的题数
}
xiaotiMiaoshu.push(tixing+"&*" + tiCount + "&*" + tiScore + "&*" + startIndex);
}
//得到题文描述后开始进行分析每道大题中的所有小题并取出来
for(var i=0; i<xiaotiMiaoshu.length; i++){
var split = xiaotiMiaoshu[i].split("&*");
var tiCount = split[1];
var tiScore = split[2];
var tiStartIndex = split[3];
var tiEndIndex = parseInt(tiStartIndex) + parseInt(tiCount) -1;
//获取每一道小题内容
for(var j=tiStartIndex; j<=tiEndIndex; j++){
var title = datiStrArr[i].substring(datiStrArr[i].indexOf(j+". "));
var singleQuestionStr = "";
var singleAnswerStr = "";
if(j === tiEndIndex){
singleQuestionStr = title.substring(title.indexOf(j+". ")+(j+". ").length);
singleAnswerStr = daanhejiexi.substring(daanhejiexi.indexOf(j+". ")+(j+". ").length);
}else{
singleQuestionStr = title.substring(title.indexOf(j+". ")+(j+". ").length, title.indexOf((parseInt(j)+1)+". "));
singleAnswerStr = daanhejiexi.substring(title.indexOf(j+". ")+(j+". ").length, daanhejiexi.indexOf((parseInt(j)+1)+". "));
}
let answer = "A"; //默认选项
let childrenArr = [];
let isFirst = false;
let isLast = false;
if(j == 1){
isFirst = true;
}
if(j == allCount){
isLast = true;
}
let qid = parseInt(j);
let score = parseInt(tiScore / tiCount);
let selectArr = ["<button>A</button>", "<button>B</button>", "<button>C</button>", "<button>D</button>"];
questions.push({
answer:answer,
childrenArr:childrenArr,
qid:qid,
score:score,
selectArr:selectArr,
title:singleQuestionStr
});
}
}
//设置答案
setAnswer(xiaotiMiaoshu);
uiFlushCardList();
uiFlushQuestionList();
}
//解析答案并设置到题目中
var allAnswerStrArr = [];
function setAnswer(xiaotiMiaoshu){
var nowCount = 0;
for(var i=1; i<=allCount; i++){
nowCount++;
if(i == allCount){
allAnswerStrArr.push(daanhejiexi.substring(daanhejiexi.indexOf(i+".【")));
}else{
let ind = daanhejiexi.indexOf((i+1)+".【");
let endStr = daanhejiexi.substring(ind-1, ind);
let flag = true; //是否是正确的序号捕获
if(endStr == "1" || endStr == "2" || endStr == "3" || endStr == "4" || endStr == "5" || endStr == "6" || endStr == "7" || endStr == "8" || endStr == "9"){
if(((i+1)+""+endStr).length > 2){ //序号长度如果大于3位数则是正确的
flag = true;
}else{
flag = false;
console.info("错误的序号:" + (i+1));
}
}
if(daanhejiexi.indexOf((i+1)+".【") == -1 || flag == false){
let tmp = daanhejiexi.substring(daanhejiexi.indexOf(i+".【答案】"));
let jiexiTmp = tmp.substring(tmp.indexOf("【答案】"), tmp.indexOf("【解析】"));
let xiaotiCount = 0; //小题答案个数
for(var j=1; j<=5; j++){
if(jiexiTmp.indexOf(j+"】") != -1){
i++;
xiaotiCount ++;
}else{
break;
}
}
var resultJiexi = tmp.substring(0, tmp.indexOf(i+".【答案】"));
resultJiexi = resultJiexi.substring(resultJiexi.indexOf("【解析】") + 4);
var answerMoreStr1 = "";
for(var j=1; j<=xiaotiCount; j++){
if(j == xiaotiCount){
let answer = jiexiTmp.substring(jiexiTmp.indexOf(j+"】")+2, jiexiTmp.indexOf(j+"】") + 3);
answerMoreStr1 = nowCount+".【答案】" + answer + "【解析】" + resultJiexi;
nowCount++;
}else{
let answer = jiexiTmp.substring(jiexiTmp.indexOf(j+"】")+2, jiexiTmp.indexOf(j+"】") + 3);
answerMoreStr1 = nowCount+".【答案】" + answer + "【解析】" + resultJiexi;
nowCount++;
}
allAnswerStrArr.push(answerMoreStr1);
}
i--;
nowCount --;
}else{
allAnswerStrArr.push(daanhejiexi.substring(daanhejiexi.indexOf(i+".【"), daanhejiexi.indexOf((i+1)+".【")));
}
}
}
for(var i=0; i<xiaotiMiaoshu.length; i++){
var split = xiaotiMiaoshu[i].split("&*");
var tixing = split[0];
var tiCount = split[1];
var tiStartIndex = split[3];
var tiEndIndex = parseInt(tiStartIndex) + parseInt(tiCount) -1;
tiStartIndex = parseInt(tiStartIndex);
tiEndIndex = parseInt(tiEndIndex);
//["一、单选题("] --> ["单选题"]
tixing = tixing.substring(tixing.indexOf("、")+1, tixing.indexOf("("));
for(var j=tiStartIndex; j<=tiEndIndex; j++){
if(tixing == "选择题" || tixing == "单选题"){
questions[j-1].type = 1;
questions[j-1].answer = allAnswerStrArr[j-1].substring(allAnswerStrArr[j-1].indexOf("【答案】") + 4, allAnswerStrArr[j-1].indexOf("【答案】") + 5);
}else if(tixing == "多选题" || tixing == "双选题" || tixing == "不定项选择题"){
questions[j-1].type = 2;
questions[j-1].answer = [];
var tmp = allAnswerStrArr[j-1].substring(allAnswerStrArr[j-1].indexOf("【答案】")+4, allAnswerStrArr[j-1].indexOf("【解析】"));
if(tmp.indexOf("A") !== -1){
questions[j-1].answer.push("A");
}
if(tmp.indexOf("B") !== -1){
questions[j-1].answer.push("B");
}
if(tmp.indexOf("C") !== -1){
questions[j-1].answer.push("C");
}
if(tmp.indexOf("D") !== -1){
questions[j-1].answer.push("D");
}
}else if(tixing == "判断题"){
questions[j-1].type = 3;
if((allAnswerStrArr[j-1].substring(allAnswerStrArr[j-1].indexOf("【答案】") + 4, allAnswerStrArr[j-1].indexOf("【答案】") + 5)) == "T" || (allAnswerStrArr[j-1].substring(allAnswerStrArr[j-1].indexOf("【答案】") + 4, allAnswerStrArr[j-1].indexOf("【答案】") + 5)) == "A"){
questions[j-1].answer = "对";
}else if((allAnswerStrArr[j-1].substring(allAnswerStrArr[j-1].indexOf("【答案】") + 4, allAnswerStrArr[j-1].indexOf("【答案】") + 5)) == "F" || (allAnswerStrArr[j-1].substring(allAnswerStrArr[j-1].indexOf("【答案】") + 4, allAnswerStrArr[j-1].indexOf("【答案】") + 5)) == "B"){
questions[j-1].answer = "错";
}else{
questions[j-1].answer = "对";
}
}else{
questions[j-1].type = 5;
questions[j-1].answer = allAnswerStrArr[j-1].substring(allAnswerStrArr[j-1].indexOf("【答案】") + 4, allAnswerStrArr[j-1].indexOf("【解析】"));
}
questions[j-1].answerMore = allAnswerStrArr[j-1].substring(allAnswerStrArr[j-1].indexOf("【解析】") + 4);
}
}
}