extend.html 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <script>
  2. var valid_result = false
  3. {notempty name="row"}
  4. var row = {:json_encode($row, 256)};
  5. {else/}
  6. var row = {};
  7. {/notempty}
  8. var app = new Vue({
  9. el: '#app',
  10. data: {
  11. mode: 'RANDOM',
  12. questions: [],
  13. summary: {
  14. // 总分数及题数
  15. total_score: 0,
  16. total_quantity: 0,
  17. // 各类题目的分数及题数
  18. judge_quantity: 0,
  19. judge_score: 0,
  20. single_quantity: 0,
  21. single_score: 0,
  22. multi_quantity: 0,
  23. multi_score: 0,
  24. fill_quantity: 0,
  25. fill_score: 0,
  26. short_quantity: 0,
  27. short_score: 0,
  28. material_quantity: 0,
  29. material_score: 0,
  30. },
  31. // 简答题分数设置
  32. shortScoreDialogVisible: false,
  33. shortScoreConfig: [],
  34. shortScoreIndex: 0,
  35. },
  36. created() {
  37. if (row && row.mode) {
  38. this.mode = row.mode
  39. // $('input[name="row[mode]"][value="' + row.mode + '"]').prop('checked', true)
  40. // $('#row[mode]-' + row.mode).click()
  41. console.log('row.mode', row.mode, this.mode, row)
  42. this.questions = row.questions ? row.questions : []
  43. this.statistics()
  44. } else {
  45. this.mode = 'RANDOM'
  46. }
  47. },
  48. methods: {
  49. // 修改选题模式
  50. changeMode(e) {
  51. console.log('changeMode', e.target.value)
  52. this.mode = e.target.value
  53. },
  54. // 打开试题选择
  55. openQuestionSelect() {
  56. console.log('openQuestionSelect')
  57. Fast.api.open('exam/question/select', '选择试题', {
  58. area: ['90%', '90%'],
  59. callback: (data) => {
  60. console.log('question select callback', data)
  61. for (let i = 0; i < data.length; i++) {
  62. data[i].score = 1
  63. }
  64. // 排除已经存在的试题
  65. for (let i = 0; i < this.questions.length; i++) {
  66. for (let j = 0; j < data.length; j++) {
  67. if (this.questions[i].id == data[j].id) {
  68. data.splice(j, 1)
  69. }
  70. }
  71. }
  72. // 合并数组
  73. this.questions = this.questions.concat(data)
  74. // 统计题目信息
  75. this.statistics()
  76. }
  77. })
  78. },
  79. // 修改分数
  80. scoreChange(index) {
  81. console.log('scoreChange', index)
  82. // 统计题目信息
  83. this.statistics()
  84. },
  85. // 打开简答题关键词分数设置
  86. openShortScoreDialog(row, index) {
  87. let answer = row.answer
  88. if (typeof answer == 'string') {
  89. answer = JSON.parse(answer)
  90. }
  91. console.log('openShortScoreDialog', row, index, answer)
  92. this.shortScoreConfig = [...answer.config]
  93. this.shortScoreIndex = index
  94. this.shortScoreDialogVisible = true
  95. },
  96. // 提交简答题关键词分数设置
  97. shortScoreSubmit() {
  98. console.log('shortScoreSubmit', this.shortScoreConfig, this.questions[this.shortScoreIndex])
  99. let answer = this.questions[this.shortScoreIndex].answer
  100. if (typeof answer == 'string') {
  101. answer = JSON.parse(answer)
  102. }
  103. answer.config = this.shortScoreConfig
  104. this.questions[this.shortScoreIndex].answer = answer
  105. this.shortScoreConfig = null
  106. this.shortScoreIndex = 0
  107. this.shortScoreDialogVisible = false
  108. // 统计题目信息
  109. this.statistics()
  110. },
  111. // 删除试题
  112. deleteQuestion(index) {
  113. console.log('deleteQuestion', index)
  114. this.questions.splice(index, 1)
  115. // 统计题目信息
  116. this.statistics()
  117. },
  118. // 统计题目信息
  119. statistics() {
  120. console.log('statistics')
  121. this.summary.total_score = 0
  122. this.summary.total_quantity = 0
  123. this.summary.judge_quantity = 0
  124. this.summary.judge_score = 0
  125. this.summary.single_quantity = 0
  126. this.summary.single_score = 0
  127. this.summary.multi_quantity = 0
  128. this.summary.multi_score = 0
  129. this.summary.fill_quantity = 0
  130. this.summary.fill_score = 0
  131. this.summary.short_quantity = 0
  132. this.summary.short_score = 0
  133. this.summary.material_quantity = 0
  134. this.summary.material_score = 0
  135. for (let i = 0; i < this.questions.length; i++) {
  136. let question = this.questions[i]
  137. this.summary.total_score += question.score
  138. this.summary.total_quantity += 1
  139. switch (question.kind) {
  140. case 'JUDGE':
  141. this.summary.judge_quantity += 1
  142. this.summary.judge_score += question.score
  143. break
  144. case 'SINGLE':
  145. this.summary.single_quantity += 1
  146. this.summary.single_score += question.score
  147. break
  148. case 'MULTI':
  149. this.summary.multi_quantity += 1
  150. this.summary.multi_score += question.score
  151. break
  152. case 'FILL':
  153. this.summary.fill_quantity += 1
  154. this.summary.fill_score += question.score
  155. break
  156. case 'SHORT':
  157. this.summary.short_quantity += 1
  158. this.summary.short_score += question.score
  159. break
  160. case 'MATERIAL':
  161. this.summary.material_quantity += 1
  162. this.summary.material_score += question.score
  163. break
  164. }
  165. }
  166. },
  167. // 验证
  168. valid() {
  169. var quantity = $('#c-quantity').val()
  170. var total_score = $('#c-total_score').val()
  171. console.log('trigger valid', this.mode, quantity, total_score)
  172. switch (this.mode) {
  173. case 'FIX':
  174. if (quantity == 0) {
  175. Toastr.error('固定模式下,试卷题数不能为0')
  176. return false
  177. }
  178. if (total_score == 0) {
  179. Toastr.error('固定模式下,试卷总分不能为0')
  180. return false
  181. }
  182. if (this.questions.length == 0) {
  183. Toastr.error('固定模式下,试卷题目不能为空')
  184. return false
  185. }
  186. if (this.summary.total_score != total_score) {
  187. Toastr.error('固定模式下,试卷总分与题目总分不一致')
  188. return false
  189. }
  190. if (this.summary.total_quantity != quantity) {
  191. Toastr.error('固定模式下,试卷题数与题目总数不一致')
  192. return false
  193. }
  194. // 将试题信息转换为JSON字符串
  195. let questions = []
  196. for (let i = 0; i < this.questions.length; i++) {
  197. let question = this.questions[i]
  198. questions.push({
  199. id: question.id,
  200. score: question.score,
  201. answer: question.answer
  202. })
  203. }
  204. $('#c-questions').val(JSON.stringify(questions))
  205. valid_result = true
  206. return true
  207. default:
  208. valid_result = true
  209. return true
  210. }
  211. }
  212. }
  213. })
  214. </script>
  215. <style>
  216. .w-60 {
  217. width: 60px;
  218. }
  219. .m-l-25 {
  220. margin-left: 25px !important;
  221. }
  222. .p-l-80 {
  223. margin-left: 80px !important;
  224. }
  225. .el-input-number--mini {
  226. width: 90px;
  227. line-height: 26px;
  228. }
  229. </style>