|
@@ -46,7 +46,8 @@ import { numberToChinese, numberToUpperCase } from "./spins/renderJSON";
|
|
|
import ContItem from "./spins/ContItem.vue";
|
|
|
import previewTem from "./spins/previewTem";
|
|
|
import { randomCode } from "@/utils/utils";
|
|
|
-import { STRUCT_TYPES } from "./spins/paperSetting";
|
|
|
+import { STRUCT_TYPES, MAX_WIDTH } from "./spins/paperSetting";
|
|
|
+const OPTION_NAME = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
|
|
export default {
|
|
|
name: "preview-paper-dialog",
|
|
@@ -205,7 +206,35 @@ export default {
|
|
|
|
|
|
this.paperStruct = studentPaperStructJson;
|
|
|
},
|
|
|
- // transformRichJson(richJson) {},
|
|
|
+ transformRichJson(richJson) {
|
|
|
+ let contents = [];
|
|
|
+ let curBlock = [];
|
|
|
+ const checkNeedSplitSection = (block) => {
|
|
|
+ if (block.type !== "image") return false;
|
|
|
+
|
|
|
+ if (block.param) {
|
|
|
+ if (block.param.width) return block.param.width > MAX_WIDTH / 2;
|
|
|
+ if (block.param.height) return block.param.height > 150;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ };
|
|
|
+
|
|
|
+ richJson.sections.forEach((section) => {
|
|
|
+ section.blocks.forEach((block) => {
|
|
|
+ if (checkNeedSplitSection(block) && curBlock.length) {
|
|
|
+ contents.push({ sections: [{ blocks: [...curBlock] }] });
|
|
|
+ curBlock = [];
|
|
|
+ }
|
|
|
+ curBlock.push(block);
|
|
|
+ });
|
|
|
+
|
|
|
+ if (curBlock.length) {
|
|
|
+ contents.push({ sections: [{ blocks: [...curBlock] }] });
|
|
|
+ curBlock = [];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return contents;
|
|
|
+ },
|
|
|
parseRenderStructList() {
|
|
|
let renderStructList = [];
|
|
|
renderStructList.push({
|
|
@@ -222,17 +251,12 @@ export default {
|
|
|
|
|
|
detail.questions.forEach((question) => {
|
|
|
if (question.subQuestions) {
|
|
|
- if (question.body) {
|
|
|
- renderStructList.push({
|
|
|
- cls: "topic-title",
|
|
|
- type: "json",
|
|
|
- content: {
|
|
|
- isCommon: true,
|
|
|
- number: question.number,
|
|
|
- body: question.body,
|
|
|
- },
|
|
|
- });
|
|
|
- }
|
|
|
+ const bodys = this.parseTopicTitle(
|
|
|
+ question.body,
|
|
|
+ `${question.number}、`
|
|
|
+ );
|
|
|
+ renderStructList.push(...bodys);
|
|
|
+
|
|
|
question.subQuestions.forEach((sq) => {
|
|
|
const contents = this.parseSimpleQuestion(sq, false);
|
|
|
renderStructList.push(...contents);
|
|
@@ -252,84 +276,37 @@ export default {
|
|
|
},
|
|
|
parseSimpleQuestion(question, isCommon) {
|
|
|
let contents = [];
|
|
|
- contents.push({
|
|
|
- cls: "topic-title",
|
|
|
- type: "json",
|
|
|
- content: {
|
|
|
- isSub: !isCommon,
|
|
|
- number: question.number,
|
|
|
- body: question.body,
|
|
|
- },
|
|
|
- });
|
|
|
+
|
|
|
+ const tbodys = this.parseTopicTitle(
|
|
|
+ question.body,
|
|
|
+ isCommon ? `${question.number}、` : `${question.number})`
|
|
|
+ );
|
|
|
+ contents.push(...tbodys);
|
|
|
|
|
|
if (question.options && question.options.length) {
|
|
|
question.options.forEach((op) => {
|
|
|
- contents.push({
|
|
|
- cls: "topic-option",
|
|
|
- type: "json",
|
|
|
- content: {
|
|
|
- isSub: false,
|
|
|
- number: numberToUpperCase(op.number),
|
|
|
- body: op.body,
|
|
|
- },
|
|
|
- });
|
|
|
+ const obodys = this.parseTopicOption(op.body, op.number);
|
|
|
+ contents.push(...obodys);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- // if (question.structType === STRUCT_TYPES.BOOLEAN_CHOICE) {
|
|
|
- // console.log(question.answer, question.studentAnswer);
|
|
|
- // }
|
|
|
-
|
|
|
if (question.answer !== null) {
|
|
|
// console.log(question.answer);
|
|
|
- contents.push({
|
|
|
- cls: "topic-answer",
|
|
|
- type: "json",
|
|
|
- content: {
|
|
|
- answerType: "standard",
|
|
|
- structType: question.structType,
|
|
|
- body: question.answer,
|
|
|
- },
|
|
|
- });
|
|
|
+ const conts = this.parseTopicAnswer(
|
|
|
+ question.answer,
|
|
|
+ question.structType,
|
|
|
+ false
|
|
|
+ );
|
|
|
+ contents.push(...conts);
|
|
|
}
|
|
|
|
|
|
if (question.studentAnswer !== null) {
|
|
|
- // console.log(question.studentAnswer);
|
|
|
- // 简答题的特殊处理,解决上传的大图无法分页问题。文字内容不受影响。
|
|
|
- if (question.structType === STRUCT_TYPES.TEXT) {
|
|
|
- // console.log(question.studentAnswer);
|
|
|
- let aindex = 0;
|
|
|
- question.studentAnswer.forEach((answer) => {
|
|
|
- answer.sections.forEach((section) => {
|
|
|
- contents.push({
|
|
|
- cls: "topic-answer std-answer",
|
|
|
- type: "json",
|
|
|
- content: {
|
|
|
- answerType: "student",
|
|
|
- structType: question.structType,
|
|
|
- hideTitle: aindex !== 0,
|
|
|
- body: [
|
|
|
- {
|
|
|
- sections: [section],
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- });
|
|
|
- aindex++;
|
|
|
- });
|
|
|
- });
|
|
|
- } else {
|
|
|
- // console.log(question.studentAnswer);
|
|
|
- contents.push({
|
|
|
- cls: "topic-answer std-answer",
|
|
|
- type: "json",
|
|
|
- content: {
|
|
|
- answerType: "student",
|
|
|
- structType: question.structType,
|
|
|
- body: question.studentAnswer,
|
|
|
- },
|
|
|
- });
|
|
|
- }
|
|
|
+ const conts = this.parseTopicAnswer(
|
|
|
+ question.studentAnswer,
|
|
|
+ question.structType,
|
|
|
+ true
|
|
|
+ );
|
|
|
+ contents.push(...conts);
|
|
|
}
|
|
|
|
|
|
contents.push({
|
|
@@ -340,6 +317,127 @@ export default {
|
|
|
|
|
|
return contents;
|
|
|
},
|
|
|
+ parseTopicTitle(richJson, numberVal) {
|
|
|
+ if (!richJson) {
|
|
|
+ return {
|
|
|
+ cls: "topic-title",
|
|
|
+ type: "json",
|
|
|
+ content: {
|
|
|
+ sections: [
|
|
|
+ {
|
|
|
+ blocks: [
|
|
|
+ {
|
|
|
+ type: "text",
|
|
|
+ value: numberVal,
|
|
|
+ param: { bold: true },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ const bodys = this.transformRichJson(richJson);
|
|
|
+
|
|
|
+ return bodys.map((body, index) => {
|
|
|
+ if (index === 0) {
|
|
|
+ body.sections[0].blocks.unshift({
|
|
|
+ type: "text",
|
|
|
+ value: numberVal,
|
|
|
+ param: { bold: true },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ cls: "topic-title",
|
|
|
+ type: "json",
|
|
|
+ content: body,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ },
|
|
|
+ parseTopicOption(richJson, number) {
|
|
|
+ const bodys = this.transformRichJson(richJson);
|
|
|
+
|
|
|
+ return bodys.map((body, index) => {
|
|
|
+ if (index === 0) {
|
|
|
+ body.sections[0].blocks.unshift({
|
|
|
+ type: "text",
|
|
|
+ value: `${numberToUpperCase(number)}、`,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ cls: "topic-option",
|
|
|
+ type: "json",
|
|
|
+ content: body,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ },
|
|
|
+ parseTopicAnswer(answer, structType, isStdAns) {
|
|
|
+ // console.log(answer, structType, isStdAns);
|
|
|
+ const answerTitleBlock = {
|
|
|
+ type: "text",
|
|
|
+ value: isStdAns ? "学生答案:" : "标准答案:",
|
|
|
+ param: {
|
|
|
+ bold: true,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ let contents = [];
|
|
|
+ if (
|
|
|
+ structType === STRUCT_TYPES.FILL_BLANK ||
|
|
|
+ structType === STRUCT_TYPES.TEXT
|
|
|
+ ) {
|
|
|
+ contents.push({
|
|
|
+ cls: "topic-answer",
|
|
|
+ type: "json",
|
|
|
+ content: {
|
|
|
+ sections: [
|
|
|
+ {
|
|
|
+ blocks: [{ ...answerTitleBlock }],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ });
|
|
|
+ answer.forEach((item) => {
|
|
|
+ const bodys = this.transformRichJson(item);
|
|
|
+ const conts = bodys.map((body, index) => {
|
|
|
+ if (index === 0) {
|
|
|
+ // body.sections[0].blocks.unshift({
|
|
|
+ // type: "text",
|
|
|
+ // value: "",
|
|
|
+ // });
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ cls: "topic-answer",
|
|
|
+ type: "json",
|
|
|
+ content: body,
|
|
|
+ };
|
|
|
+ });
|
|
|
+ contents.push(...conts);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ let ansCont = "";
|
|
|
+ if (structType === STRUCT_TYPES.BOOLEAN_CHOICE) {
|
|
|
+ ansCont = answer ? "对" : "错";
|
|
|
+ } else {
|
|
|
+ ansCont = answer.map((item) => OPTION_NAME[item - 1]).join("");
|
|
|
+ }
|
|
|
+ contents.push({
|
|
|
+ cls: "topic-answer",
|
|
|
+ type: "json",
|
|
|
+ content: {
|
|
|
+ sections: [
|
|
|
+ {
|
|
|
+ blocks: [
|
|
|
+ { ...answerTitleBlock },
|
|
|
+ { type: "text", value: ansCont },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return contents;
|
|
|
+ },
|
|
|
loadImg(url) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
const img = new Image();
|
|
@@ -368,20 +466,7 @@ export default {
|
|
|
let imgUrls = [];
|
|
|
this.renderStructList.forEach((item) => {
|
|
|
if (item.type === "text") return;
|
|
|
- if (item.cls === "topic-title" || item.cls === "topic-option") {
|
|
|
- imgUrls.push(...this.getRichJsonImgUrls(item.content.body));
|
|
|
- return;
|
|
|
- }
|
|
|
- // 简答题才可能会有图片
|
|
|
- if (
|
|
|
- item.cls.indexOf("answer") &&
|
|
|
- item.content.structType === STRUCT_TYPES.TEXT &&
|
|
|
- item.content.body
|
|
|
- ) {
|
|
|
- item.content.body.forEach((body) => {
|
|
|
- imgUrls.push(...this.getRichJsonImgUrls(body));
|
|
|
- });
|
|
|
- }
|
|
|
+ imgUrls.push(...this.getRichJsonImgUrls(item.content));
|
|
|
});
|
|
|
|
|
|
// console.log(imgUrls);
|