|
@@ -1,8 +1,8 @@
|
|
<template>
|
|
<template>
|
|
- <div class="paper-template-build card-view paper-page">
|
|
|
|
|
|
+ <div class="paper-template-build">
|
|
<paper-template-view
|
|
<paper-template-view
|
|
ref="PaperTemplateView"
|
|
ref="PaperTemplateView"
|
|
- class="preview-body"
|
|
|
|
|
|
+ :class="['preview-body', { 'is-view': isViewMode }]"
|
|
:pages="pages"
|
|
:pages="pages"
|
|
></paper-template-view>
|
|
></paper-template-view>
|
|
</div>
|
|
</div>
|
|
@@ -28,6 +28,7 @@ const checkRichTextHasCont = function (data) {
|
|
if (!data.sections || !data.sections.length) return false;
|
|
if (!data.sections || !data.sections.length) return false;
|
|
|
|
|
|
if (!data.sections[0].blocks || !data.sections[0].blocks.length) return false;
|
|
if (!data.sections[0].blocks || !data.sections[0].blocks.length) return false;
|
|
|
|
+
|
|
return true;
|
|
return true;
|
|
};
|
|
};
|
|
|
|
|
|
@@ -37,6 +38,8 @@ export default {
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
paperId: this.$route.params.paperId,
|
|
paperId: this.$route.params.paperId,
|
|
|
|
+ viewType: this.$route.params.viewType || "view",
|
|
|
|
+ renderStructList: [],
|
|
pages: [],
|
|
pages: [],
|
|
paperJson: {},
|
|
paperJson: {},
|
|
paperTempJson: [],
|
|
paperTempJson: [],
|
|
@@ -44,12 +47,20 @@ export default {
|
|
maxColumnHeight: 200,
|
|
maxColumnHeight: 200,
|
|
};
|
|
};
|
|
},
|
|
},
|
|
|
|
+ computed: {
|
|
|
|
+ isViewMode() {
|
|
|
|
+ return this.viewType === "view";
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ mounted() {
|
|
|
|
+ this.initData();
|
|
|
|
+ },
|
|
methods: {
|
|
methods: {
|
|
async initData() {
|
|
async initData() {
|
|
// todo: get data
|
|
// todo: get data
|
|
this.paperJson = paperJson;
|
|
this.paperJson = paperJson;
|
|
this.paperTempJson = paperTempJson;
|
|
this.paperTempJson = paperTempJson;
|
|
- this.pages = paperTempJson.papes;
|
|
|
|
|
|
+ this.pages = paperTempJson.pages;
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
this.buildData();
|
|
this.buildData();
|
|
});
|
|
});
|
|
@@ -60,8 +71,8 @@ export default {
|
|
this.parseRenderStructList();
|
|
this.parseRenderStructList();
|
|
this.buildPrePages();
|
|
this.buildPrePages();
|
|
|
|
|
|
- const loadres = await this.waitAllImgLoaded().catch(() => {});
|
|
|
|
- if (!loadres) {
|
|
|
|
|
|
+ const loadRes = await this.waitAllImgLoaded().catch(() => {});
|
|
|
|
+ if (!loadRes) {
|
|
this.$message.error("图片加载有误!");
|
|
this.$message.error("图片加载有误!");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -81,18 +92,18 @@ export default {
|
|
detail.paperDetailUnits.forEach((question) => {
|
|
detail.paperDetailUnits.forEach((question) => {
|
|
let questionInfo = question.question;
|
|
let questionInfo = question.question;
|
|
if (questionInfo.subQuestions && questionInfo.subQuestions.length) {
|
|
if (questionInfo.subQuestions && questionInfo.subQuestions.length) {
|
|
- const bodys = this.parseTitleOption(question.quesBody, "");
|
|
|
|
|
|
+ const bodys = this.parseTitleOption(questionInfo.quesBody, "");
|
|
renderStructList.push(...bodys);
|
|
renderStructList.push(...bodys);
|
|
|
|
|
|
- const isMatches = this.checkIsMatches(question.questionType);
|
|
|
|
|
|
+ const isMatches = this.checkIsMatches(questionInfo.questionType);
|
|
if (
|
|
if (
|
|
isMatches &&
|
|
isMatches &&
|
|
questionInfo.quesOptions &&
|
|
questionInfo.quesOptions &&
|
|
questionInfo.quesOptions.length
|
|
questionInfo.quesOptions.length
|
|
) {
|
|
) {
|
|
- question.quesOptions.forEach((op) => {
|
|
|
|
|
|
+ questionInfo.quesOptions.forEach((op) => {
|
|
const obodys = this.parseTitleOption(
|
|
const obodys = this.parseTitleOption(
|
|
- op.body,
|
|
|
|
|
|
+ op.optionBody,
|
|
`${numberToUpperCase(op.number)}、`,
|
|
`${numberToUpperCase(op.number)}、`,
|
|
"option"
|
|
"option"
|
|
);
|
|
);
|
|
@@ -100,8 +111,14 @@ export default {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 选词填空不展示小题
|
|
|
|
+ if (questionInfo.questionType === "BANKED_CLOZE") {
|
|
|
|
+ renderStructList.push(this.parseLineGap());
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
questionInfo.subQuestions.forEach((sq) => {
|
|
questionInfo.subQuestions.forEach((sq) => {
|
|
- if (isMatches) sq.quesOptions = [];
|
|
|
|
|
|
+ if (isMatches) sq.quesOptions = []; // 选词填空、段落匹配小题中不展示选项
|
|
const contents = this.parseSimpleQuestion(sq, false);
|
|
const contents = this.parseSimpleQuestion(sq, false);
|
|
renderStructList.push(...contents);
|
|
renderStructList.push(...contents);
|
|
if (!isMatches) renderStructList.push(this.parseLineGap());
|
|
if (!isMatches) renderStructList.push(this.parseLineGap());
|
|
@@ -110,8 +127,8 @@ export default {
|
|
questionInfo.number = question.number;
|
|
questionInfo.number = question.number;
|
|
const datas = this.parseSimpleQuestion(questionInfo, true);
|
|
const datas = this.parseSimpleQuestion(questionInfo, true);
|
|
renderStructList.push(...datas);
|
|
renderStructList.push(...datas);
|
|
- renderStructList.push(this.parseLineGap());
|
|
|
|
}
|
|
}
|
|
|
|
+ renderStructList.push(this.parseLineGap());
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
@@ -162,15 +179,15 @@ export default {
|
|
let contents = [];
|
|
let contents = [];
|
|
|
|
|
|
const tbodys = this.parseTitleOption(
|
|
const tbodys = this.parseTitleOption(
|
|
- question.body,
|
|
|
|
- isCommon ? `${question.number}、` : `${question.subNumber})`
|
|
|
|
|
|
+ question.quesBody,
|
|
|
|
+ isCommon ? `${question.number}、` : `${question.subNumber}、`
|
|
);
|
|
);
|
|
contents.push(...tbodys);
|
|
contents.push(...tbodys);
|
|
|
|
|
|
if (question.quesOptions && question.quesOptions.length) {
|
|
if (question.quesOptions && question.quesOptions.length) {
|
|
question.quesOptions.forEach((op) => {
|
|
question.quesOptions.forEach((op) => {
|
|
const obodys = this.parseTitleOption(
|
|
const obodys = this.parseTitleOption(
|
|
- op.body,
|
|
|
|
|
|
+ op.optionBody,
|
|
`${numberToUpperCase(op.number)}、`,
|
|
`${numberToUpperCase(op.number)}、`,
|
|
"option"
|
|
"option"
|
|
);
|
|
);
|
|
@@ -180,10 +197,12 @@ export default {
|
|
return contents;
|
|
return contents;
|
|
},
|
|
},
|
|
parseDetailTitle(data) {
|
|
parseDetailTitle(data) {
|
|
- let content = this.getRichStruct({
|
|
|
|
- type: "text",
|
|
|
|
- value: `${data.cnNum}、${data.name}`,
|
|
|
|
- });
|
|
|
|
|
|
+ let content = this.getRichStruct([
|
|
|
|
+ {
|
|
|
|
+ type: "text",
|
|
|
|
+ value: `${data.cnNum}、${data.name}`,
|
|
|
|
+ },
|
|
|
|
+ ]);
|
|
return getRichTextModel({
|
|
return getRichTextModel({
|
|
styles: { width: "100%", fontWeight: 600 },
|
|
styles: { width: "100%", fontWeight: 600 },
|
|
content,
|
|
content,
|
|
@@ -193,7 +212,7 @@ export default {
|
|
if (!richJson) return [];
|
|
if (!richJson) return [];
|
|
const bodys = this.transformRichJson(richJson);
|
|
const bodys = this.transformRichJson(richJson);
|
|
|
|
|
|
- return bodys.forEach((body, index) => {
|
|
|
|
|
|
+ return bodys.map((body, index) => {
|
|
if (index === 0 && noVal) {
|
|
if (index === 0 && noVal) {
|
|
body.sections[0].blocks.unshift({
|
|
body.sections[0].blocks.unshift({
|
|
type: "text",
|
|
type: "text",
|
|
@@ -201,18 +220,18 @@ export default {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- return this.getRichTextModel({
|
|
|
|
|
|
+ return getRichTextModel({
|
|
contType,
|
|
contType,
|
|
- styles: { width: "100%" },
|
|
|
|
|
|
+ styles: { width: contType !== "option" ? "100%" : "auto" },
|
|
content: body,
|
|
content: body,
|
|
});
|
|
});
|
|
});
|
|
});
|
|
},
|
|
},
|
|
parseLineGap() {
|
|
parseLineGap() {
|
|
- return this.getRichTextModel({
|
|
|
|
|
|
+ return getRichTextModel({
|
|
contType: "gap",
|
|
contType: "gap",
|
|
styles: { width: "100%", height: "20px" },
|
|
styles: { width: "100%", height: "20px" },
|
|
- content: this.getRichStruct({ type: "text", value: "" }),
|
|
|
|
|
|
+ content: this.getRichStruct([{ type: "text", value: "" }]),
|
|
});
|
|
});
|
|
},
|
|
},
|
|
checkIsMatches(structType) {
|
|
checkIsMatches(structType) {
|
|
@@ -220,14 +239,15 @@ export default {
|
|
return matchesTypes.includes(structType);
|
|
return matchesTypes.includes(structType);
|
|
},
|
|
},
|
|
buildPrePages() {
|
|
buildPrePages() {
|
|
- let pages = deepCopy(this.paperTempJson);
|
|
|
|
- pages[0].columns[0].elements.push(...this.renderStructList);
|
|
|
|
|
|
+ let pages = deepCopy(this.paperTempJson.pages);
|
|
|
|
+ pages[0].columns[0].texts = [];
|
|
|
|
+ pages[0].columns[0].texts.push(...this.renderStructList);
|
|
this.pages = pages;
|
|
this.pages = pages;
|
|
},
|
|
},
|
|
|
|
|
|
buildReleasePages() {
|
|
buildReleasePages() {
|
|
this.resetRenderStructSize();
|
|
this.resetRenderStructSize();
|
|
- this.autoPage();
|
|
|
|
|
|
+ this.buildPageAutoPage();
|
|
},
|
|
},
|
|
resetRenderStructSize() {
|
|
resetRenderStructSize() {
|
|
let curOptions = [];
|
|
let curOptions = [];
|
|
@@ -278,7 +298,7 @@ export default {
|
|
curOptions = [];
|
|
curOptions = [];
|
|
});
|
|
});
|
|
},
|
|
},
|
|
- autoPage() {
|
|
|
|
|
|
+ buildPageAutoPage() {
|
|
let pages = [];
|
|
let pages = [];
|
|
let curPage = null,
|
|
let curPage = null,
|
|
curElem = null;
|
|
curElem = null;
|
|
@@ -306,34 +326,61 @@ export default {
|
|
curElem.contType !== "option" ||
|
|
curElem.contType !== "option" ||
|
|
(curElem.contType === "option" && curElem._percent === 1)
|
|
(curElem.contType === "option" && curElem._percent === 1)
|
|
) {
|
|
) {
|
|
|
|
+ // 非选项,单独占整行
|
|
curLinePercent = 1;
|
|
curLinePercent = 1;
|
|
if (curElem.h + curColumnHeight > this.maxColumnHeight) {
|
|
if (curElem.h + curColumnHeight > this.maxColumnHeight) {
|
|
// 当前栏满了
|
|
// 当前栏满了
|
|
|
|
+ if (curColumnNo >= curPage.columnNumber) {
|
|
|
|
+ // 当前页满了
|
|
|
|
+ pages.push(curPage);
|
|
|
|
+ curPage = null;
|
|
|
|
+ curColumnNo = null;
|
|
|
|
+ }
|
|
|
|
+ curColumn = null;
|
|
|
|
+ curColumnHeight = 0;
|
|
} else {
|
|
} else {
|
|
- // 未满
|
|
|
|
- curColumn.push(curElem);
|
|
|
|
|
|
+ // 当前栏未满
|
|
|
|
+ curColumnHeight += curElem.h;
|
|
|
|
+ curColumn.texts.push(curElem);
|
|
curElem = getNextElem();
|
|
curElem = getNextElem();
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
|
|
+ // 选项的处理
|
|
if (curLinePercent + curElem._percent > 1) {
|
|
if (curLinePercent + curElem._percent > 1) {
|
|
- // 放下一行
|
|
|
|
|
|
+ // 行满了,放下一行
|
|
if (curElem.h + curColumnHeight > this.maxColumnHeight) {
|
|
if (curElem.h + curColumnHeight > this.maxColumnHeight) {
|
|
curLinePercent = 1;
|
|
curLinePercent = 1;
|
|
// 当前栏满了
|
|
// 当前栏满了
|
|
|
|
+ if (curColumnNo >= curPage.columnNumber) {
|
|
|
|
+ // 当前页满了
|
|
|
|
+ pages.push(curPage);
|
|
|
|
+ curPage = null;
|
|
|
|
+ curColumnNo = null;
|
|
|
|
+ }
|
|
|
|
+ curColumn = null;
|
|
|
|
+ curColumnHeight = 0;
|
|
} else {
|
|
} else {
|
|
- // 未满
|
|
|
|
|
|
+ // 当前栏未满,放下一行
|
|
curLinePercent = curElem._percent;
|
|
curLinePercent = curElem._percent;
|
|
- curColumn.push(curElem);
|
|
|
|
|
|
+ curColumnHeight += curElem.h;
|
|
|
|
+ curColumn.texts.push(curElem);
|
|
curElem = getNextElem();
|
|
curElem = getNextElem();
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- // 放当前行
|
|
|
|
|
|
+ // 行未满,放当前行
|
|
curLinePercent += curElem._percent;
|
|
curLinePercent += curElem._percent;
|
|
- curColumn.push(curElem);
|
|
|
|
|
|
+ curColumn.texts.push(curElem);
|
|
curElem = getNextElem();
|
|
curElem = getNextElem();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (curPage) {
|
|
|
|
+ pages.push(curPage);
|
|
|
|
+ curPage = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.pages = pages;
|
|
},
|
|
},
|
|
getNewPageModel(pageNo) {
|
|
getNewPageModel(pageNo) {
|
|
let pNo = pageNo % 2;
|
|
let pNo = pageNo % 2;
|
|
@@ -349,8 +396,15 @@ export default {
|
|
let nelem = deepCopy(elem);
|
|
let nelem = deepCopy(elem);
|
|
nelem.id = getElementId();
|
|
nelem.id = getElementId();
|
|
nelem.key = randomCode();
|
|
nelem.key = randomCode();
|
|
|
|
+
|
|
|
|
+ if (pNo === 1 && nelem.type === "GUTTER") {
|
|
|
|
+ nelem.direction = "right";
|
|
|
|
+ }
|
|
return nelem;
|
|
return nelem;
|
|
});
|
|
});
|
|
|
|
+ newPage.columns.forEach((column) => {
|
|
|
|
+ column.texts = [];
|
|
|
|
+ });
|
|
|
|
|
|
if (pageNo > 1) return newPage;
|
|
if (pageNo > 1) return newPage;
|
|
|
|
|
|
@@ -367,6 +421,7 @@ export default {
|
|
}
|
|
}
|
|
return nelem;
|
|
return nelem;
|
|
});
|
|
});
|
|
|
|
+ column.texts = [];
|
|
});
|
|
});
|
|
return newPage;
|
|
return newPage;
|
|
},
|
|
},
|