topic.vue 13 KB

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