123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- <template>
- <div class="c_box">
- <div class="c_box_title">{{ title }}</div>
- <div class="c_box_score">
- <span>总分:{{ score }}</span>
- <span v-if="name" style="margin-left: 10px;">答题人:{{ name }}</span>
- <span style="margin-left: 10px;">总得分:{{ score2 }}</span>
- </div>
- <div class="c_body">
- <div v-if="type == 3">
- <div v-for="(item, index) in checkArray[page].array" :key="index" class="check_box">
- <div class="title">{{ selectType(item, index) }}</div>
- <div v-if="item.ttype == 1" class="answerBox">
- <choiceV :cJson.sync="item.json" :checktype="checktype" v-if="item.type == 1" :see="see" :isTeacher="isTeacher"></choiceV>
- <gapV :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 3" :see="see" :isTeacher="isTeacher"></gapV>
- <fileV :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 5" :see="see" :isTeacher="isTeacher"></fileV>
- <!-- <span v-else>暂未设置题目</span> -->
- </div>
- <div v-for="(item2, index2) in item.array" :key="`${index}-${index2}`" class="check_box_xia">
- <div class="title">{{ selectType(item2, index2) }}</div>
- <div v-if="item2.ttype == 1" class="answerBox">
- <choiceV :cJson.sync="item2.json" :checktype="checktype" v-if="item2.type == 1" :see="see" :isTeacher="isTeacher"></choiceV>
- <gapV :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 3" :see="see" :isTeacher="isTeacher"></gapV>
- <gapV :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 5" :see="see" :isTeacher="isTeacher"></gapV>
- <!-- <span v-else>暂未设置题目</span> -->
- </div>
- </div>
- </div>
- </div>
- <div v-else>
- <div v-for="(item, index) in checkArray" :key="index" class="check_box">
- <div class="title">{{ selectType(item, index) }}</div>
- <div v-if="item.ttype == 1" class="answerBox">
- <choiceV :cJson.sync="item.json" :checktype="checktype" v-if="item.type == 1" :see="see" :isTeacher="isTeacher"></choiceV>
- <gapV :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 3" :see="see" :isTeacher="isTeacher"></gapV>
- <fileV :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 5" :see="see" :isTeacher="isTeacher"></fileV>
- <!-- <span v-else>暂未设置题目</span> -->
- </div>
- <div v-for="(item2, index2) in item.array" :key="`${index}-${index2}`" class="check_box_xia">
- <div class="title">{{ selectType(item2, index2) }}</div>
- <div v-if="item2.ttype == 1" class="answerBox">
- <choiceV :cJson.sync="item2.json" :checktype="checktype" v-if="item2.type == 1" :see="see" :isTeacher="isTeacher"></choiceV>
- <gapV :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 3" :see="see" :isTeacher="isTeacher"></gapV>
- <fileV :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 5" :see="see" :isTeacher="isTeacher"></fileV>
- <!-- <span v-else>暂未设置题目</span> -->
- </div>
- </div>
- </div>
- </div>
- <div v-if="checkArray.length > 1 && type == 3" class="page">
- <el-button type="primary" size="mini" :disabled="page == 0" @click="page--">上一页</el-button>
- <div class="p_page">
- <span>{{ page + 1 }}</span><span>/</span><span>{{ checkArray.length }}</span>
- </div>
- <el-button type="primary" size="mini" :disabled="page == checkArray.length - 1" @click="page++">下一页</el-button>
- </div>
- </div>
- </div>
- </template>
- <script>
- import choiceV from "./choice.vue";
- import gapV from './gap.vue';
- import fileV from './file.vue';
- export default {
- props: {
- cJson: {
- type: Array,
- },
- title: {
- type: String,
- },
- checktype: {
- type: Number,
- default: 1,
- },
- see: {
- type: Boolean,
- default: false
- },
- isTeacher: {
- type: Number,
- default: 2
- },
- name: {
- type: String,
- default: ''
- }
- },
- components: {
- choiceV,
- gapV,
- fileV
- },
- data() {
- return {
- checkArray: [],
- type: 1,
- page: 0,
- options2: {
- 1: "选择题",
- // 2: "问答题",
- 3: "问答题",
- 4: "添加文档",
- 5: "附件",
- },
- };
- },
- computed: {
- selectType() {
- return function (item, index) {
- if (item.ttype == 1) {
- return index + 1 + "、" + this.options2[item.type];
- } else if (item.ttype == 2) {
- return `第${index + 1}组 (共${item.array.length}题)`;
- } else if (item.ttype == 3) {
- return `分页${index + 1}`;
- }
- };
- },
- score() {
- let score = 0
- this.checkArray.forEach(el => {
- if ((el.ttype == 3 || el.ttype == 2) && el.array.length > 0) {
- el.array.forEach(item => {
- if (item.ttype == 2 && item.array.length > 0) {
- item.array.forEach(item2 => {
- if (item2.ttype == 1 && item2.json) {
- score += item2.json.score ? parseFloat(item2.json.score) : 0
- }
- })
- } else if (item.ttype == 1 && item.json) {
- score += item.json.score ? parseFloat(item.json.score) : 0
- }
- })
- } else if (el.ttype == 1 && el.json) {
- score += el.json.score ? parseFloat(el.json.score) : 0
- }
- })
- return score > 0 ? score + '分' : '未设置分数'
- },
- score2() {
- let score = 0
- // let type = 1
- this.checkArray.forEach(el => {
- if ((el.ttype == 3 || el.ttype == 2) && el.array.length > 0) {
- el.array.forEach(item => {
- if (item.ttype == 2 && item.array.length > 0) {
- item.array.forEach(item2 => {
- if (item2.ttype == 1 && item2.json) {
- score += item2.json.score2 ? parseFloat(item2.json.score2) : 0
- }
- })
- } else if (item.ttype == 1 && item.json) {
- score += item.json.score2 ? parseFloat(item.json.score2) : 0
- }
- })
- } else if (el.ttype == 1 && el.json) {
- score += el.json.score2 ? parseFloat(el.json.score2) : 0
- }
- })
- return score + '分'
- }
- },
- watch: {
- cJson: {
- handler(newVal, oldVal) {
- console.log(newVal);
- console.log(oldVal);
- this.checkArray = this.setJson(this.depthCopy(newVal));
- },
- deep: true,
- },
- },
- methods: {
- depthCopy(s) {
- return JSON.parse(JSON.stringify(s));
- },
- setJson(json) {
- if (json.length > 0) {
- let _json = this.depthCopy(json);
- this.type = _json[0].ttype;
- let checkArray = _json.filter((item) => {
- if (item.array) {
- item.array = item.array.filter((item2) => {
- if (item2.ttype == 1 && item2.json && !item2.json.answer2) {
- item2.json.answer2 = [];
- }
- if (item2.array) {
- item2.array = item2.array.filter((item3) => {
- if (item3.ttype == 1 && item3.json && !item3.json.answer2) {
- item3.json.answer2 = [];
- }
- return item3;
- });
- }
- return (
- (item2.ttype != 1 && item2.array.length > 0) || item2.ttype == 1
- );
- });
- }
- if (item.ttype == 1 && item.json && !item.json.answer2) {
- item.json.answer2 = [];
- }
- console.log(item.array);
- return (item.ttype != 1 && item.array.length > 0) || item.ttype == 1;
- });
- console.log(checkArray);
- return checkArray;
- } else {
- return [];
- }
- },
- },
- mounted() {
- this.checkArray = this.setJson(this.depthCopy(this.cJson));
- },
- };
- </script>
- <style scoped>
- .c_box {
- width: 95%;
- margin: 0 auto;
- background: #fff;
- height: calc(100% - 55px);
- overflow: auto;
- }
- .c_box_title {
- width: 90%;
- text-align: center;
- font-size: 24px;
- font-weight: bold;
- word-break: break-all;
- margin: 10px auto;
- }
- .c_box_score {
- width: 90%;
- text-align: center;
- word-break: break-all;
- margin: 0 auto 20px;
- font-size: 16px;
- color: #373737;
- }
- .c_body {
- width: 90%;
- margin: 0 auto;
- }
- .check_box {}
- .check_box+.check_box {
- margin-top: 10px;
- padding-top: 10px;
- border-top: 1px solid #eee;
- }
- .check_box>.title {
- font-size: 20px;
- word-break: break-all;
- font-weight: bold;
- }
- .check_box>.answerBox {
- margin-top: 10px;
- }
- .check_box>.noanswerBox {
- margin-top: 10px;
- }
- .check_box_xia {
- padding: 15px 0;
- }
- .check_box_xia + .check_box_xia {
- border-top: 1px solid #eee;
- }
- .check_box_xia>.title {
- font-size: 18px;
- font-weight: bold;
- }
- .check_box_xia>.answerBox {
- margin-top: 10px;
- }
- .check_box_xia>.noanswerBox {
- margin-top: 10px;
- }
- .page {
- margin: 20px;
- display: flex;
- align-items: center;
- }
- .p_page {
- margin: 0 10px;
- }
- </style>
|