|
@@ -9,7 +9,7 @@
|
|
@change="seqModeChange"
|
|
@change="seqModeChange"
|
|
>
|
|
>
|
|
<!-- <el-option value="MODE1" label="单题型连续"></el-option>
|
|
<!-- <el-option value="MODE1" label="单题型连续"></el-option>
|
|
- <el-option value="MODE2" label="客观题整体连续"></el-option> -->
|
|
|
|
|
|
+ <el-option value="MODE2" label="客观题整体连续"></el-option> -->
|
|
<el-option value="MODE3" label="按大题独立"></el-option>
|
|
<el-option value="MODE3" label="按大题独立"></el-option>
|
|
<el-option value="MODE5" label="整卷连续"></el-option>
|
|
<el-option value="MODE5" label="整卷连续"></el-option>
|
|
</el-select>
|
|
</el-select>
|
|
@@ -29,17 +29,29 @@
|
|
>
|
|
>
|
|
</el-option>
|
|
</el-option>
|
|
</el-select>
|
|
</el-select>
|
|
- <el-button type="primary" size="small" @click="toDownload"
|
|
|
|
|
|
+ <el-button
|
|
|
|
+ type="primary"
|
|
|
|
+ size="small"
|
|
|
|
+ :loading="downloading"
|
|
|
|
+ @click="toAction('downloadPdf')"
|
|
>下载试卷</el-button
|
|
>下载试卷</el-button
|
|
>
|
|
>
|
|
|
|
+ <el-button
|
|
|
|
+ type="primary"
|
|
|
|
+ size="small"
|
|
|
|
+ :loading="downloading"
|
|
|
|
+ @click="toAction('buildPackge')"
|
|
|
|
+ >生成数据包</el-button
|
|
|
|
+ >
|
|
</div>
|
|
</div>
|
|
<paper-build-config
|
|
<paper-build-config
|
|
ref="PaperBuildConfig"
|
|
ref="PaperBuildConfig"
|
|
:config-sources="configSources"
|
|
:config-sources="configSources"
|
|
- @confirm="buildConfigChange"
|
|
|
|
|
|
+ :showConfirmBtn="false"
|
|
></paper-build-config>
|
|
></paper-build-config>
|
|
<paper-template-view
|
|
<paper-template-view
|
|
ref="PaperTemplateView"
|
|
ref="PaperTemplateView"
|
|
|
|
+ id="paper-template-view"
|
|
class="preview-body"
|
|
class="preview-body"
|
|
:pages="pages"
|
|
:pages="pages"
|
|
:page-config="paperTempJson.pageConfig"
|
|
:page-config="paperTempJson.pageConfig"
|
|
@@ -96,17 +108,15 @@
|
|
:data="elem"
|
|
:data="elem"
|
|
></elem-rich-text>
|
|
></elem-rich-text>
|
|
</div>
|
|
</div>
|
|
- </div>
|
|
|
|
- <div
|
|
|
|
- v-if="answerPreviewUrl && viewType !== 'iframe'"
|
|
|
|
- class="design-preview-frame"
|
|
|
|
- >
|
|
|
|
- <iframe
|
|
|
|
- :src="answerPreviewUrl"
|
|
|
|
- frameborder="0"
|
|
|
|
- width="1000"
|
|
|
|
- height="800"
|
|
|
|
- ></iframe>
|
|
|
|
|
|
+
|
|
|
|
+ <!-- answer dom -->
|
|
|
|
+ <answer-template-view
|
|
|
|
+ ref="AnswerTemplateView"
|
|
|
|
+ id="answer-template-view"
|
|
|
|
+ class="preview-body"
|
|
|
|
+ :answerData="paperJson"
|
|
|
|
+ :pageCountMode="configModalForm.pageCountMode"
|
|
|
|
+ ></answer-template-view>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
@@ -115,24 +125,25 @@
|
|
import ElemRichText from "../elements/rich-text/ElemRichText.vue";
|
|
import ElemRichText from "../elements/rich-text/ElemRichText.vue";
|
|
import PaperTemplateView from "../components/PaperTemplateView.vue";
|
|
import PaperTemplateView from "../components/PaperTemplateView.vue";
|
|
import PaperBuildConfig from "../components/PaperBuildConfig.vue";
|
|
import PaperBuildConfig from "../components/PaperBuildConfig.vue";
|
|
|
|
+import AnswerTemplateView from "../components/AnswerTemplateView.vue";
|
|
|
|
+
|
|
import { deepCopy } from "../../card/plugins/utils";
|
|
import { deepCopy } from "../../card/plugins/utils";
|
|
-import previewTemp from "../previewTemp";
|
|
|
|
import { paperDetailInfoApi } from "../../paper/api";
|
|
import { paperDetailInfoApi } from "../../paper/api";
|
|
-import {
|
|
|
|
- paperTemplateListApi,
|
|
|
|
- paperPdfDownloadApi,
|
|
|
|
- paperAndAnswerPdfDownloadApi,
|
|
|
|
-} from "../api";
|
|
|
|
-import { downloadByApi } from "@/plugins/download";
|
|
|
|
|
|
+import { paperTemplateListApi, paperAndAnswerPdfDownloadApi } from "../api";
|
|
import paperTemplateBuildMixins from "./paperTemplateBuildMixins";
|
|
import paperTemplateBuildMixins from "./paperTemplateBuildMixins";
|
|
|
|
+import { buildPdf } from "@/plugins/htmlToPdf";
|
|
|
|
|
|
export default {
|
|
export default {
|
|
name: "PaperTemplateBuild",
|
|
name: "PaperTemplateBuild",
|
|
- components: { PaperTemplateView, PaperBuildConfig, ElemRichText },
|
|
|
|
|
|
+ components: {
|
|
|
|
+ PaperTemplateView,
|
|
|
|
+ PaperBuildConfig,
|
|
|
|
+ ElemRichText,
|
|
|
|
+ AnswerTemplateView,
|
|
|
|
+ },
|
|
mixins: [paperTemplateBuildMixins],
|
|
mixins: [paperTemplateBuildMixins],
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- answerPreviewUrl: "",
|
|
|
|
paperId: this.$route.params.paperId,
|
|
paperId: this.$route.params.paperId,
|
|
viewType: this.$route.params.viewType,
|
|
viewType: this.$route.params.viewType,
|
|
seqMode: "MODE3",
|
|
seqMode: "MODE3",
|
|
@@ -156,14 +167,9 @@ export default {
|
|
},
|
|
},
|
|
configSources: [],
|
|
configSources: [],
|
|
prepareDownloadPdf: false,
|
|
prepareDownloadPdf: false,
|
|
- answerHtmlContent: "",
|
|
|
|
- waitingAnswer: true,
|
|
|
|
- creatingZip: false,
|
|
|
|
|
|
+ actionType: "",
|
|
};
|
|
};
|
|
},
|
|
},
|
|
- created() {
|
|
|
|
- this.createGetAnswerFunc();
|
|
|
|
- },
|
|
|
|
mounted() {
|
|
mounted() {
|
|
if (this.viewType === "frame") {
|
|
if (this.viewType === "frame") {
|
|
this.initFrame();
|
|
this.initFrame();
|
|
@@ -171,42 +177,7 @@ export default {
|
|
}
|
|
}
|
|
this.initData();
|
|
this.initData();
|
|
},
|
|
},
|
|
- beforeDestroy() {
|
|
|
|
- delete window.submitPaperTemp;
|
|
|
|
- },
|
|
|
|
- watch: {
|
|
|
|
- waitingAnswer(val) {
|
|
|
|
- if (!val && this.creatingZip) {
|
|
|
|
- this.createPaperAndAnswerZip();
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
methods: {
|
|
methods: {
|
|
- createGetAnswerFunc() {
|
|
|
|
- window.submitPaperTemp = async ({ success, errorMsg, htmlCont }) => {
|
|
|
|
- if (!success) {
|
|
|
|
- this.$message.error(errorMsg);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- this.answerHtmlContent = htmlCont;
|
|
|
|
- this.waitingAnswer = false;
|
|
|
|
- };
|
|
|
|
- window.answerSet = {
|
|
|
|
- pageCountMode: this.configModalForm.pageCountMode,
|
|
|
|
- seqMode: this.seqMode,
|
|
|
|
- };
|
|
|
|
- const { href } = this.$router.resolve({
|
|
|
|
- name: "AnswerTemplateBuild",
|
|
|
|
- params: {
|
|
|
|
- paperId: this.paperId,
|
|
|
|
- viewType: "frame",
|
|
|
|
- },
|
|
|
|
- query: {
|
|
|
|
- t: Date.now(),
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
- this.answerPreviewUrl = href;
|
|
|
|
- },
|
|
|
|
async initFrame() {
|
|
async initFrame() {
|
|
try {
|
|
try {
|
|
const paperSet = window.parent.paperSet;
|
|
const paperSet = window.parent.paperSet;
|
|
@@ -265,21 +236,35 @@ export default {
|
|
this.emitFrameResult(false, "构建pdf错误");
|
|
this.emitFrameResult(false, "构建pdf错误");
|
|
}
|
|
}
|
|
|
|
|
|
- this.$nextTick(() => {
|
|
|
|
- this.emitFrameResult(true, "", this.getPreviewTemp());
|
|
|
|
|
|
+ this.$nextTick(async () => {
|
|
|
|
+ const paperBlob = await buildPdf(
|
|
|
|
+ {
|
|
|
|
+ element: document.getElementById("paper-template-view"),
|
|
|
|
+ pageSize: this.paperTempJson.pageConfig.pageSize,
|
|
|
|
+ },
|
|
|
|
+ true
|
|
|
|
+ ).catch((error) => {
|
|
|
|
+ console.error(error);
|
|
|
|
+ });
|
|
|
|
+ if (!paperBlob) {
|
|
|
|
+ this.emitFrameResult(false, "生成试卷pdf错误");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.emitFrameResult(true, "", paperBlob);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
},
|
|
},
|
|
- emitFrameResult(success = true, errorMsg = "", htmlCont = "") {
|
|
|
|
|
|
+ emitFrameResult(success = true, errorMsg = "", blobCont = null) {
|
|
window.parent &&
|
|
window.parent &&
|
|
window.parent.submitPaperTemp &&
|
|
window.parent.submitPaperTemp &&
|
|
window.parent.submitPaperTemp({
|
|
window.parent.submitPaperTemp({
|
|
success,
|
|
success,
|
|
errorMsg,
|
|
errorMsg,
|
|
- htmlCont,
|
|
|
|
- templateId: this.curPaperTemp.id,
|
|
|
|
|
|
+ blobCont,
|
|
|
|
+ contType: "paper",
|
|
});
|
|
});
|
|
},
|
|
},
|
|
async initData() {
|
|
async initData() {
|
|
@@ -405,31 +390,6 @@ export default {
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
this.buildData();
|
|
this.buildData();
|
|
});
|
|
});
|
|
- setTimeout(() => {
|
|
|
|
- this.createPaperAndAnswerZip();
|
|
|
|
- });
|
|
|
|
- },
|
|
|
|
- async createPaperAndAnswerZip() {
|
|
|
|
- this.creatingZip = true;
|
|
|
|
- if (this.waitingAnswer) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- const paperHtmlCont = this.getPreviewTemp();
|
|
|
|
- const answerHtmlCont = this.answerHtmlContent;
|
|
|
|
- if (!answerHtmlCont) {
|
|
|
|
- this.$message.error("试卷答案获取失败,请刷新页面重试!");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- paperAndAnswerPdfDownloadApi({
|
|
|
|
- paperContent: paperHtmlCont,
|
|
|
|
- templateId: this.curPaperTemp.id,
|
|
|
|
- paperId: Number(this.paperId),
|
|
|
|
- answerContent: answerHtmlCont,
|
|
|
|
- answerSize: "A4",
|
|
|
|
- }).finally(() => {
|
|
|
|
- this.creatingZip = false;
|
|
|
|
- });
|
|
|
|
},
|
|
},
|
|
paperTempChange(paperTemp) {
|
|
paperTempChange(paperTemp) {
|
|
// console.log(paperTemp);
|
|
// console.log(paperTemp);
|
|
@@ -467,7 +427,7 @@ export default {
|
|
this.buildPagesByAutoPage();
|
|
this.buildPagesByAutoPage();
|
|
if (this.prepareDownloadPdf) {
|
|
if (this.prepareDownloadPdf) {
|
|
this.$nextTick(async () => {
|
|
this.$nextTick(async () => {
|
|
- await this.downloadPaperPdf().catch(() => {});
|
|
|
|
|
|
+ await this.runAction().catch(() => {});
|
|
this.prepareDownloadPdf = false;
|
|
this.prepareDownloadPdf = false;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -518,42 +478,101 @@ export default {
|
|
},
|
|
},
|
|
// img ------ end >
|
|
// img ------ end >
|
|
// download ------ start >
|
|
// download ------ start >
|
|
- getPreviewTemp() {
|
|
|
|
- return previewTemp(this.$refs.PaperTemplateView.$el.outerHTML);
|
|
|
|
- },
|
|
|
|
- async toDownload() {
|
|
|
|
|
|
+ async toAction(actionType) {
|
|
const valid = await this.$refs.PaperBuildConfig.checkData().catch(
|
|
const valid = await this.$refs.PaperBuildConfig.checkData().catch(
|
|
() => {}
|
|
() => {}
|
|
);
|
|
);
|
|
if (!valid) return;
|
|
if (!valid) return;
|
|
|
|
|
|
|
|
+ this.actionType = actionType;
|
|
const configData = this.$refs.PaperBuildConfig.getData();
|
|
const configData = this.$refs.PaperBuildConfig.getData();
|
|
if (JSON.stringify(configData) === JSON.stringify(this.configModalForm)) {
|
|
if (JSON.stringify(configData) === JSON.stringify(this.configModalForm)) {
|
|
- this.downloadPaperPdf();
|
|
|
|
|
|
+ this.runAction();
|
|
} else {
|
|
} else {
|
|
this.prepareDownloadPdf = true;
|
|
this.prepareDownloadPdf = true;
|
|
this.buildConfigChange(configData);
|
|
this.buildConfigChange(configData);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ async runAction() {
|
|
|
|
+ if (this.actionType === "downloadPdf") {
|
|
|
|
+ await this.downloadPaperPdf();
|
|
|
|
+ } else {
|
|
|
|
+ await this.buildPackage();
|
|
|
|
+ }
|
|
|
|
+ },
|
|
async downloadPaperPdf() {
|
|
async downloadPaperPdf() {
|
|
- const htmlCont = this.getPreviewTemp();
|
|
|
|
|
|
+ if (this.downloading) return;
|
|
|
|
+ this.downloading = true;
|
|
|
|
+
|
|
|
|
+ let result = true;
|
|
|
|
+ await buildPdf({
|
|
|
|
+ element: document.getElementById("paper-template-view"),
|
|
|
|
+ filename: `${this.fieldData.courseName}(${this.fieldData.courseCode})_${this.fieldData.paperName}.pdf`,
|
|
|
|
+ pageSize: this.paperTempJson.pageConfig.pageSize,
|
|
|
|
+ }).catch((error) => {
|
|
|
|
+ result = false;
|
|
|
|
+ console.error(error);
|
|
|
|
+ this.$message.error(error.message || "下载失败,请重新尝试!");
|
|
|
|
+ });
|
|
|
|
|
|
|
|
+ this.downloading = false;
|
|
|
|
+ if (!result) return;
|
|
|
|
+ this.$message.success("下载成功!");
|
|
|
|
+ },
|
|
|
|
+ async buildPackage() {
|
|
if (this.downloading) return;
|
|
if (this.downloading) return;
|
|
this.downloading = true;
|
|
this.downloading = true;
|
|
|
|
|
|
- const res = await downloadByApi(() => {
|
|
|
|
- return paperPdfDownloadApi({
|
|
|
|
- content: htmlCont,
|
|
|
|
- templateId: this.curPaperTemp.id,
|
|
|
|
- paperId: this.paperId,
|
|
|
|
- });
|
|
|
|
- }).catch((e) => {
|
|
|
|
- this.$message.error(e || "下载失败,请重新尝试!");
|
|
|
|
|
|
+ // 试卷PDF
|
|
|
|
+ const paperPdfName = `${this.fieldData.courseName}(${this.fieldData.courseCode})_${this.fieldData.paperName}.pdf`;
|
|
|
|
+ const paperBlob = await buildPdf(
|
|
|
|
+ {
|
|
|
|
+ element: document.getElementById("paper-template-view"),
|
|
|
|
+ pageSize: this.paperTempJson.pageConfig.pageSize,
|
|
|
|
+ },
|
|
|
|
+ true
|
|
|
|
+ ).catch((error) => {
|
|
|
|
+ this.downloading = false;
|
|
|
|
+ console.error(error);
|
|
|
|
+ this.$message.error("生成试卷pdf失败,请重新尝试!");
|
|
|
|
+ });
|
|
|
|
+ if (!paperBlob) return;
|
|
|
|
+
|
|
|
|
+ // 答案pdf
|
|
|
|
+ const answerPdfName = `${this.fieldData.courseName}(${this.fieldData.courseCode})_${this.fieldData.paperName}_答案.pdf`;
|
|
|
|
+ const answerBlob = await buildPdf(
|
|
|
|
+ {
|
|
|
|
+ element: document.getElementById("answer-template-view"),
|
|
|
|
+ pageSize: "A4",
|
|
|
|
+ },
|
|
|
|
+ true
|
|
|
|
+ ).catch((error) => {
|
|
|
|
+ this.downloading = false;
|
|
|
|
+ console.error(error);
|
|
|
|
+ this.$message.error("生成答案pdf失败,请重新尝试!");
|
|
|
|
+ });
|
|
|
|
+ if (!answerBlob) return;
|
|
|
|
+
|
|
|
|
+ const data = new FormData();
|
|
|
|
+ data.append(
|
|
|
|
+ "paperPdf",
|
|
|
|
+ new File([paperBlob], paperPdfName, { type: "application/pdf" })
|
|
|
|
+ );
|
|
|
|
+ data.append(
|
|
|
|
+ "answerPdf",
|
|
|
|
+ new File([answerBlob], answerPdfName, { type: "application/pdf" })
|
|
|
|
+ );
|
|
|
|
+ data.append("paperId", this.paperId);
|
|
|
|
+
|
|
|
|
+ let result = true;
|
|
|
|
+ await paperAndAnswerPdfDownloadApi(data).catch((error) => {
|
|
|
|
+ result = false;
|
|
|
|
+ console.error(error);
|
|
});
|
|
});
|
|
this.downloading = false;
|
|
this.downloading = false;
|
|
|
|
|
|
- if (!res) return;
|
|
|
|
- this.$message.success("下载成功!");
|
|
|
|
|
|
+ if (!result) return;
|
|
|
|
+ this.$message.success("生成数据包成功!");
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
};
|
|
@@ -592,4 +611,11 @@ export default {
|
|
top: 0;
|
|
top: 0;
|
|
z-index: 1;
|
|
z-index: 1;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+.paper-template-build .answer-template-view {
|
|
|
|
+ position: absolute;
|
|
|
|
+ left: -9999px;
|
|
|
|
+ z-index: 999;
|
|
|
|
+ visibility: hidden;
|
|
|
|
+}
|
|
</style>
|
|
</style>
|