topic.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <div class="c_box">
  3. <div class="c_box_title">{{ title }}</div>
  4. <div class="c_box_score">
  5. <span>总分:{{ score }}</span>
  6. <span v-if="name" style="margin-left: 10px;">答题人:{{ name }}</span>
  7. <span style="margin-left: 10px;">总得分:{{ score2 }}</span>
  8. </div>
  9. <div class="c_body">
  10. <div v-if="type == 3">
  11. <div v-for="(item, index) in checkArray[page].array" :key="index" class="check_box">
  12. <div class="title">{{ selectType(item, index) }}</div>
  13. <div v-if="item.ttype == 1" class="answerBox">
  14. <choiceV :cJson.sync="item.json" :checktype="checktype" v-if="item.type == 1" :see="see" :isTeacher="isTeacher"></choiceV>
  15. <gapV :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 3" :see="see" :isTeacher="isTeacher"></gapV>
  16. <fileV :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 5" :see="see" :isTeacher="isTeacher"></fileV>
  17. <!-- <span v-else>暂未设置题目</span> -->
  18. </div>
  19. <div v-for="(item2, index2) in item.array" :key="`${index}-${index2}`" class="check_box_xia">
  20. <div class="title">{{ selectType(item2, index2) }}</div>
  21. <div v-if="item2.ttype == 1" class="answerBox">
  22. <choiceV :cJson.sync="item2.json" :checktype="checktype" v-if="item2.type == 1" :see="see" :isTeacher="isTeacher"></choiceV>
  23. <gapV :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 3" :see="see" :isTeacher="isTeacher"></gapV>
  24. <gapV :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 5" :see="see" :isTeacher="isTeacher"></gapV>
  25. <!-- <span v-else>暂未设置题目</span> -->
  26. </div>
  27. </div>
  28. </div>
  29. </div>
  30. <div v-else>
  31. <div v-for="(item, index) in checkArray" :key="index" class="check_box">
  32. <div class="title">{{ selectType(item, index) }}</div>
  33. <div v-if="item.ttype == 1" class="answerBox">
  34. <choiceV :cJson.sync="item.json" :checktype="checktype" v-if="item.type == 1" :see="see" :isTeacher="isTeacher"></choiceV>
  35. <gapV :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 3" :see="see" :isTeacher="isTeacher"></gapV>
  36. <fileV :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 5" :see="see" :isTeacher="isTeacher"></fileV>
  37. <!-- <span v-else>暂未设置题目</span> -->
  38. </div>
  39. <div v-for="(item2, index2) in item.array" :key="`${index}-${index2}`" class="check_box_xia">
  40. <div class="title">{{ selectType(item2, index2) }}</div>
  41. <div v-if="item2.ttype == 1" class="answerBox">
  42. <choiceV :cJson.sync="item2.json" :checktype="checktype" v-if="item2.type == 1" :see="see" :isTeacher="isTeacher"></choiceV>
  43. <gapV :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 3" :see="see" :isTeacher="isTeacher"></gapV>
  44. <fileV :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 5" :see="see" :isTeacher="isTeacher"></fileV>
  45. <!-- <span v-else>暂未设置题目</span> -->
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. <div v-if="checkArray.length > 1 && type == 3" class="page">
  51. <el-button type="primary" size="mini" :disabled="page == 0" @click="page--">上一页</el-button>
  52. <div class="p_page">
  53. <span>{{ page + 1 }}</span><span>/</span><span>{{ checkArray.length }}</span>
  54. </div>
  55. <el-button type="primary" size="mini" :disabled="page == checkArray.length - 1" @click="page++">下一页</el-button>
  56. </div>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. import choiceV from "./choice.vue";
  62. import gapV from './gap.vue';
  63. import fileV from './file.vue';
  64. export default {
  65. props: {
  66. cJson: {
  67. type: Array,
  68. },
  69. title: {
  70. type: String,
  71. },
  72. checktype: {
  73. type: Number,
  74. default: 1,
  75. },
  76. see: {
  77. type: Boolean,
  78. default: false
  79. },
  80. isTeacher: {
  81. type: Number,
  82. default: 2
  83. },
  84. name: {
  85. type: String,
  86. default: ''
  87. }
  88. },
  89. components: {
  90. choiceV,
  91. gapV,
  92. fileV
  93. },
  94. data() {
  95. return {
  96. checkArray: [],
  97. type: 1,
  98. page: 0,
  99. options2: {
  100. 1: "选择题",
  101. // 2: "问答题",
  102. 3: "问答题",
  103. 4: "添加文档",
  104. 5: "附件",
  105. },
  106. };
  107. },
  108. computed: {
  109. selectType() {
  110. return function (item, index) {
  111. if (item.ttype == 1) {
  112. return index + 1 + "、" + this.options2[item.type];
  113. } else if (item.ttype == 2) {
  114. return `第${index + 1}组 (共${item.array.length}题)`;
  115. } else if (item.ttype == 3) {
  116. return `分页${index + 1}`;
  117. }
  118. };
  119. },
  120. score() {
  121. let score = 0
  122. this.checkArray.forEach(el => {
  123. if ((el.ttype == 3 || el.ttype == 2) && el.array.length > 0) {
  124. el.array.forEach(item => {
  125. if (item.ttype == 2 && item.array.length > 0) {
  126. item.array.forEach(item2 => {
  127. if (item2.ttype == 1 && item2.json) {
  128. score += item2.json.score ? parseFloat(item2.json.score) : 0
  129. }
  130. })
  131. } else if (item.ttype == 1 && item.json) {
  132. score += item.json.score ? parseFloat(item.json.score) : 0
  133. }
  134. })
  135. } else if (el.ttype == 1 && el.json) {
  136. score += el.json.score ? parseFloat(el.json.score) : 0
  137. }
  138. })
  139. return score > 0 ? score + '分' : '未设置分数'
  140. },
  141. score2() {
  142. let score = 0
  143. // let type = 1
  144. this.checkArray.forEach(el => {
  145. if ((el.ttype == 3 || el.ttype == 2) && el.array.length > 0) {
  146. el.array.forEach(item => {
  147. if (item.ttype == 2 && item.array.length > 0) {
  148. item.array.forEach(item2 => {
  149. if (item2.ttype == 1 && item2.json) {
  150. score += item2.json.score2 ? parseFloat(item2.json.score2) : 0
  151. }
  152. })
  153. } else if (item.ttype == 1 && item.json) {
  154. score += item.json.score2 ? parseFloat(item.json.score2) : 0
  155. }
  156. })
  157. } else if (el.ttype == 1 && el.json) {
  158. score += el.json.score2 ? parseFloat(el.json.score2) : 0
  159. }
  160. })
  161. return score + '分'
  162. }
  163. },
  164. watch: {
  165. cJson: {
  166. handler(newVal, oldVal) {
  167. console.log(newVal);
  168. console.log(oldVal);
  169. this.checkArray = this.setJson(this.depthCopy(newVal));
  170. },
  171. deep: true,
  172. },
  173. },
  174. methods: {
  175. depthCopy(s) {
  176. return JSON.parse(JSON.stringify(s));
  177. },
  178. setJson(json) {
  179. if (json.length > 0) {
  180. let _json = this.depthCopy(json);
  181. this.type = _json[0].ttype;
  182. let checkArray = _json.filter((item) => {
  183. if (item.array) {
  184. item.array = item.array.filter((item2) => {
  185. if (item2.ttype == 1 && item2.json && !item2.json.answer2) {
  186. item2.json.answer2 = [];
  187. }
  188. if (item2.array) {
  189. item2.array = item2.array.filter((item3) => {
  190. if (item3.ttype == 1 && item3.json && !item3.json.answer2) {
  191. item3.json.answer2 = [];
  192. }
  193. return item3;
  194. });
  195. }
  196. return (
  197. (item2.ttype != 1 && item2.array.length > 0) || item2.ttype == 1
  198. );
  199. });
  200. }
  201. if (item.ttype == 1 && item.json && !item.json.answer2) {
  202. item.json.answer2 = [];
  203. }
  204. console.log(item.array);
  205. return (item.ttype != 1 && item.array.length > 0) || item.ttype == 1;
  206. });
  207. console.log(checkArray);
  208. return checkArray;
  209. } else {
  210. return [];
  211. }
  212. },
  213. },
  214. mounted() {
  215. this.checkArray = this.setJson(this.depthCopy(this.cJson));
  216. },
  217. };
  218. </script>
  219. <style scoped>
  220. .c_box {
  221. width: 95%;
  222. margin: 0 auto;
  223. background: #fff;
  224. height: calc(100% - 55px);
  225. overflow: auto;
  226. }
  227. .c_box_title {
  228. width: 90%;
  229. text-align: center;
  230. font-size: 24px;
  231. font-weight: bold;
  232. word-break: break-all;
  233. margin: 10px auto;
  234. }
  235. .c_box_score {
  236. width: 90%;
  237. text-align: center;
  238. word-break: break-all;
  239. margin: 0 auto 20px;
  240. font-size: 16px;
  241. color: #373737;
  242. }
  243. .c_body {
  244. width: 90%;
  245. margin: 0 auto;
  246. }
  247. .check_box {}
  248. .check_box+.check_box {
  249. margin-top: 10px;
  250. padding-top: 10px;
  251. border-top: 1px solid #eee;
  252. }
  253. .check_box>.title {
  254. font-size: 20px;
  255. word-break: break-all;
  256. font-weight: bold;
  257. }
  258. .check_box>.answerBox {
  259. margin-top: 10px;
  260. }
  261. .check_box>.noanswerBox {
  262. margin-top: 10px;
  263. }
  264. .check_box_xia {
  265. padding: 15px 0;
  266. }
  267. .check_box_xia + .check_box_xia {
  268. border-top: 1px solid #eee;
  269. }
  270. .check_box_xia>.title {
  271. font-size: 18px;
  272. font-weight: bold;
  273. }
  274. .check_box_xia>.answerBox {
  275. margin-top: 10px;
  276. }
  277. .check_box_xia>.noanswerBox {
  278. margin-top: 10px;
  279. }
  280. .page {
  281. margin: 20px;
  282. display: flex;
  283. align-items: center;
  284. }
  285. .p_page {
  286. margin: 0 10px;
  287. }
  288. </style>