123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- <template>
- <el-dialog
- class="paper-params"
- :visible.sync="modalIsShow"
- top="10px"
- width="785px"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- append-to-body
- @open="dialogOpen"
- >
- <h1 class="params-dialog-title" slot="title">
- 请上传阅卷参数
- <span
- >卷面总分合计:<em class="param-sum-score">{{ pageSumScore }}分</em>
- </span>
- </h1>
- <div class="params-main">
- <div class="params-head">
- <el-button
- :type="!topicType ? 'primary' : 'default'"
- @click="selectType(0)"
- >客观题区</el-button
- >
- <el-button
- :type="topicType ? 'primary' : 'default'"
- @click="selectType(1)"
- >主观题区</el-button
- >
- </div>
- <div class="params-body">
- <div style="text-align:right;">
- <upload-button
- btn-icon="icon icon-share"
- btn-content="选择上传主观题标答文件(doc/docx)"
- btn-type="warning"
- :upload-url="uploadUrl"
- :format="['doc', 'docx']"
- @upload-error="uplaodError"
- @upload-success="uploadSuccess"
- style="margin: 0;"
- v-if="topicType"
- >
- </upload-button>
- </div>
- <div class="params-part" v-for="topic in curTopicList" :key="topic.id">
- <h2 class="params-title">{{ topic.topicName }}</h2>
- <p class="params-subtitle">
- <span>题型:{{ topic.name }}</span>
- <span v-if="topic.type !== 'COMPOSITION'">
- 通配小题分值:
- <el-input-number
- v-model="topic.commonQuestionScore"
- size="small"
- :min="0.1"
- :max="200"
- :step="0.1"
- step-strictly
- :controls="false"
- @change="commonQuestionScoreChange(topic)"
- ></el-input-number
- >分,</span
- >
- <span
- >本大题总分合计:<em class="param-sum-score"
- >{{ topic.sumScore }}分</em
- ></span
- >
- </p>
- <div class="params-table" v-if="topic.type !== 'COMPOSITION'">
- <table class="table table-striped">
- <tr>
- <th>题号</th>
- <th>分值</th>
- <th>题号</th>
- <th>分值</th>
- </tr>
- <tr v-for="(group, gindex) in topic.questions" :key="gindex">
- <template v-for="question in group">
- <td :key="`${question.questionNo}-1`">
- <span>{{ question.questionNo }}</span>
- </td>
- <td :key="`${question.questionNo}-2`">
- <el-input-number
- v-model="question.score"
- size="small"
- :min="0.1"
- :max="200"
- :step="0.1"
- step-strictly
- :controls="false"
- @change="questionScoreChange(topic)"
- v-if="question.questionNo"
- ></el-input-number>
- </td>
- </template>
- </tr>
- </table>
- </div>
- <div class="params-table" v-else>
- <el-input-number
- v-model="topic.sumScore"
- :min="0.1"
- :max="200"
- :step="0.1"
- step-strictly
- :controls="false"
- @change="getPageSumScore"
- ></el-input-number>
- </div>
- </div>
- </div>
- </div>
- <div slot="footer" style="text-align: right;">
- <el-button type="primary" @click="submit">确认</el-button>
- <el-button type="danger" @click="cancel" plain>取消</el-button>
- </div>
- </el-dialog>
- </template>
- <script>
- import { calcSum, isEmptyObject, objAssign } from "../plugins/utils";
- import UploadButton from "./UploadButton";
- export default {
- name: "paper-params",
- components: { UploadButton },
- props: {
- pages: {
- type: Array,
- default() {
- return [];
- }
- },
- paperParams: {
- type: Object,
- default() {
- return {};
- }
- }
- },
- data() {
- return {
- modalIsShow: false,
- topicType: 0,
- pageSumScore: 0,
- subjectiveAttachmentId: "",
- curTopicList: [],
- objectives: [],
- subjectives: [],
- cacheScores: {},
- initTopic: {
- id: "",
- topicNo: "",
- topicName: "",
- type: ""
- },
- // import
- uploadUrl: "/api/print/basic/sys/saveAttachment"
- };
- },
- methods: {
- selectType(topicType) {
- this.topicType = topicType;
- this.curTopicList = topicType ? this.subjectives : this.objectives;
- },
- listIncludeItem(list, item) {
- const index = list.findIndex(elem => elem.id === item.id);
- return index !== -1;
- },
- dialogOpen() {
- if (!isEmptyObject(this.paperParams)) {
- this.getCacheScore([
- ...this.paperParams.objectives,
- ...this.paperParams.subjectives
- ]);
- this.subjectiveAttachmentId = this.paperParams.subjectiveAttachmentId;
- }
- // 每次打开时,重新生成试题结构,以便避免题卡结构变化之后,当前页面的试题结构没有变的问题
- let objectiveList = [];
- let subjectiveList = [];
- let objectives = [];
- let subjectives = [];
- this.pages.forEach(page => {
- page.columns.forEach(column => {
- column.elements.forEach(element => {
- if (
- element.sign &&
- element.type !== "TOPIC_HEAD" &&
- element.type !== "CARD_HEAD"
- ) {
- if (element.sign === "objective") objectiveList.push(element);
- if (element.sign === "subjective") subjectiveList.push(element);
- }
- });
- });
- });
- // 客观题
- objectiveList.forEach(item => {
- const topic = item.parent || item;
- if (this.listIncludeItem(objectives, topic)) return;
- let data = {
- sumScore: 0,
- commonQuestionScore: 1,
- name: this.getObjectiveTopicName(topic),
- choiceList: this.getChoiceList(topic),
- questions: this.getQuestions(topic),
- ...objAssign(this.initTopic, topic)
- };
- data.sumScore = this.getTopicSumScore(data);
- objectives.push(data);
- });
- // 主观题
- subjectiveList.forEach(item => {
- const topic = item.parent || item;
- if (this.listIncludeItem(subjectives, topic)) return;
- let data = {
- sumScore: 0,
- commonQuestionScore: 1,
- name: this.getSubjectiveTopicName(topic),
- ...objAssign(this.initTopic, topic)
- };
- if (topic.type === "COMPOSITION") {
- data.sumScore = this.cacheScores[topic.topicNo] || 1;
- } else {
- data.questions = this.getQuestions(topic);
- data.sumScore = this.getTopicSumScore(data);
- }
- subjectives.push(data);
- });
- this.subjectives = subjectives;
- this.objectives = objectives;
- this.getPageSumScore();
- this.selectType(0);
- },
- getQuestions(topic) {
- let questions = [];
- let numPerColumn = Math.ceil(topic.questionsCount / 2);
- for (let j = topic.startNumber; j <= numPerColumn; j++) {
- let group = [];
- let question = {
- questionNo: j,
- score: this.cacheScores[`${topic.topicNo}-${j}`] || 1
- };
- if (topic.type === "FILL_QUESTION")
- question.answers = topic.isMultiply ? [] : "";
- group[0] = question;
- if (numPerColumn + j <= topic.questionsCount) {
- group[1] = {
- questionNo: numPerColumn + j,
- score:
- this.cacheScores[`${topic.topicNo}-${numPerColumn + j}`] || 1,
- answers:
- topic.type === "FILL_QUESTION" && topic.isMultiply ? [] : ""
- };
- } else {
- group[1] = { questionNo: "" };
- }
- questions.push(group);
- }
- return questions;
- },
- getObjectiveTopicName(data) {
- if (data.isMultiply) {
- return "选择题(多选)";
- } else if (data.isBoolean) {
- return "填空题";
- } else {
- return "选择题(单选)";
- }
- },
- getSubjectiveTopicName(data) {
- const names = {
- EXPLAIN: "解答题",
- COMPOSITION: "作文题",
- FILL_LINE: "填空题"
- };
- return names[data.type];
- },
- getChoiceList(data) {
- const options = data.isBoolean
- ? data.booleanType
- : "abcdefghijklmnopqrstuv";
- return options
- .toUpperCase()
- .slice(0, data.optionCount)
- .split("");
- },
- commonQuestionScoreChange(topic) {
- topic.questions.map(group => {
- group.map(question => {
- question.score = topic.commonQuestionScore;
- });
- });
- this.questionScoreChange(topic);
- },
- questionScoreChange(topic) {
- topic.sumScore = this.getTopicSumScore(topic);
- this.getPageSumScore();
- },
- getTopicSumScore(topic) {
- const scoreList = topic.questions.map(group => {
- return calcSum(group.map(question => question.score || 0));
- });
- return calcSum(scoreList);
- },
- getPageSumScore() {
- this.pageSumScore =
- calcSum(this.objectives.map(item => item.sumScore)) +
- calcSum(this.subjectives.map(item => item.sumScore));
- },
- getCacheScore(topics) {
- topics = topics || [...this.objectives, ...this.subjectives];
- let cacheScores = {};
- topics.map(topic => {
- if (topic.type === "COMPOSITION") {
- cacheScores[`${topic.topicNo}`] = topic.sumScore;
- } else {
- topic.questions.map(group => {
- group.map(question => {
- cacheScores[`${topic.topicNo}-${question.questionNo}`] =
- question.score;
- });
- });
- }
- });
- this.cacheScores = cacheScores;
- },
- // import
- uplaodError(errorData) {
- this.$notify.error({ title: "错误提示", message: errorData.message });
- },
- uploadSuccess(response) {
- this.$message.success("上传成功!");
- this.subjectiveAttachmentId = response.data.id;
- },
- // dialog
- cancel() {
- this.modalIsShow = false;
- },
- open() {
- this.modalIsShow = true;
- },
- submit() {
- this.$emit("confirm", {
- pageSumScore: this.pageSumScore,
- objectives: this.objectives,
- subjectives: this.subjectives,
- subjectiveAttachmentId: this.subjectiveAttachmentId
- });
- this.modalIsShow = false;
- }
- }
- };
- </script>
|