extend.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. sortChange(index) {
  87. console.log('sortChange', index)
  88. },
  89. // 打开简答题关键词分数设置
  90. openShortScoreDialog(row, index) {
  91. let answer = row.answer
  92. if (typeof answer == 'string') {
  93. answer = JSON.parse(answer)
  94. }
  95. console.log('openShortScoreDialog', row, index, answer)
  96. this.shortScoreConfig = [...answer.config]
  97. this.shortScoreIndex = index
  98. this.shortScoreDialogVisible = true
  99. },
  100. // 提交简答题关键词分数设置
  101. shortScoreSubmit() {
  102. console.log('shortScoreSubmit', this.shortScoreConfig, this.questions[this.shortScoreIndex])
  103. let answer = this.questions[this.shortScoreIndex].answer
  104. if (typeof answer == 'string') {
  105. answer = JSON.parse(answer)
  106. }
  107. answer.config = this.shortScoreConfig
  108. this.questions[this.shortScoreIndex].answer = answer
  109. this.shortScoreConfig = null
  110. this.shortScoreIndex = 0
  111. this.shortScoreDialogVisible = false
  112. // 统计题目信息
  113. this.statistics()
  114. },
  115. // 删除试题
  116. deleteQuestion(index) {
  117. console.log('deleteQuestion', index)
  118. this.questions.splice(index, 1)
  119. // 统计题目信息
  120. this.statistics()
  121. },
  122. // 统计题目信息
  123. statistics() {
  124. console.log('statistics')
  125. this.summary.total_score = 0
  126. this.summary.total_quantity = 0
  127. this.summary.judge_quantity = 0
  128. this.summary.judge_score = 0
  129. this.summary.single_quantity = 0
  130. this.summary.single_score = 0
  131. this.summary.multi_quantity = 0
  132. this.summary.multi_score = 0
  133. this.summary.fill_quantity = 0
  134. this.summary.fill_score = 0
  135. this.summary.short_quantity = 0
  136. this.summary.short_score = 0
  137. this.summary.material_quantity = 0
  138. this.summary.material_score = 0
  139. for (let i = 0; i < this.questions.length; i++) {
  140. let question = this.questions[i]
  141. this.summary.total_score += question.score
  142. this.summary.total_quantity += 1
  143. switch (question.kind) {
  144. case 'JUDGE':
  145. this.summary.judge_quantity += 1
  146. this.summary.judge_score += question.score
  147. break
  148. case 'SINGLE':
  149. this.summary.single_quantity += 1
  150. this.summary.single_score += question.score
  151. break
  152. case 'MULTI':
  153. this.summary.multi_quantity += 1
  154. this.summary.multi_score += question.score
  155. break
  156. case 'FILL':
  157. this.summary.fill_quantity += 1
  158. this.summary.fill_score += question.score
  159. break
  160. case 'SHORT':
  161. this.summary.short_quantity += 1
  162. this.summary.short_score += question.score
  163. break
  164. case 'MATERIAL':
  165. this.summary.material_quantity += 1
  166. this.summary.material_score += question.score
  167. break
  168. }
  169. }
  170. },
  171. // 验证
  172. valid() {
  173. var quantity = $('#c-quantity').val()
  174. var total_score = $('#c-total_score').val()
  175. console.log('trigger valid', this.mode, quantity, total_score)
  176. switch (this.mode) {
  177. case 'FIX':
  178. if (quantity == 0) {
  179. Toastr.error('固定模式下,试卷题数不能为0')
  180. return false
  181. }
  182. if (total_score == 0) {
  183. Toastr.error('固定模式下,试卷总分不能为0')
  184. return false
  185. }
  186. if (this.questions.length == 0) {
  187. Toastr.error('固定模式下,试卷题目不能为空')
  188. return false
  189. }
  190. if (this.summary.total_score != total_score) {
  191. Toastr.error('固定模式下,试卷总分与题目总分不一致')
  192. return false
  193. }
  194. if (this.summary.total_quantity != quantity) {
  195. Toastr.error('固定模式下,试卷题数与题目总数不一致')
  196. return false
  197. }
  198. // 将试题信息转换为JSON字符串
  199. let questions = []
  200. for (let i = 0; i < this.questions.length; i++) {
  201. let question = this.questions[i]
  202. questions.push({
  203. id: question.id,
  204. score: question.score,
  205. answer: question.answer,
  206. sort: question.sort
  207. })
  208. }
  209. $('#c-questions').val(JSON.stringify(questions))
  210. valid_result = true
  211. return true
  212. default:
  213. valid_result = true
  214. return true
  215. }
  216. },
  217. // 刷新排序
  218. refreshSort() {
  219. // 按照sort排序,数值大靠前
  220. this.questions.sort((a, b) => {
  221. return b.sort - a.sort
  222. })
  223. }
  224. }
  225. })
  226. </script>
  227. <style>
  228. .w-60 {
  229. width: 60px;
  230. }
  231. .m-l-25 {
  232. margin-left: 25px !important;
  233. }
  234. .p-l-80 {
  235. margin-left: 80px !important;
  236. }
  237. .el-input-number--mini {
  238. width: 90px;
  239. line-height: 26px;
  240. }
  241. </style>