index.vue 13 KB

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