ExamPaper.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <el-container>
  3. <el-header height="220">
  4. <el-row>
  5. <el-select
  6. v-model="queryInfo.subjectId"
  7. clearable
  8. placeholder="请选择科目"
  9. style="margin-left: 5px"
  10. @change="subjectChange"
  11. >
  12. <el-option
  13. v-for="item in allSubject"
  14. :key="item.key"
  15. :label="item.value"
  16. :value="item.key"
  17. />
  18. </el-select>
  19. <el-button type="plain" icon="el-icon-plus" style="margin-left: 5px" @click="addExamPaper">添加</el-button>
  20. </el-row>
  21. </el-header>
  22. <el-main>
  23. <el-table
  24. :data="dataList"
  25. border
  26. style="width: 100%"
  27. >
  28. <el-table-column
  29. fixed="left"
  30. label="No"
  31. type="index"
  32. />
  33. <el-table-column
  34. prop="examName"
  35. label="试卷名称"
  36. width="150"
  37. />
  38. <el-table-column
  39. prop="type"
  40. label="所属科目"
  41. width="90"
  42. />
  43. <el-table-column
  44. prop="startTime"
  45. label="考试时间"
  46. width="150"
  47. />
  48. <el-table-column
  49. prop="duration"
  50. label="考试时长(分钟)"
  51. width="150"
  52. />
  53. <el-table-column
  54. prop="totalScore"
  55. label="考试总分"
  56. />
  57. <el-table-column
  58. prop="passScore"
  59. label="及格分数"
  60. />
  61. <el-table-column
  62. prop="passScore"
  63. label="试卷状态"
  64. />
  65. <el-table-column
  66. fixed="right"
  67. label="操作"
  68. width="320"
  69. >
  70. <template slot-scope="scope">
  71. <el-button
  72. size="mini"
  73. type="warning"
  74. @click="previewPaper(scope.$index, scope.row)"
  75. >预览</el-button>
  76. <el-button
  77. size="mini"
  78. type="warning"
  79. @click="handleDelete(scope.$index, scope.row)"
  80. >删除</el-button>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. <el-pagination
  85. background
  86. :small="screenWidth <= 768"
  87. layout="prev, pager, next"
  88. :page-size="pageSize"
  89. :current-page="currentPage"
  90. :total="totalSize"
  91. @current-change="handleCurrentChange"
  92. @prev-click="handleCurrentChange"
  93. @next-click="handleCurrentChange"
  94. />
  95. </el-main>
  96. </el-container>
  97. </template>
  98. <script>
  99. import { getSubjectKV, getPapers, deletePaper } from '@/api/exam'
  100. export default {
  101. name: 'ExamPaper',
  102. data() {
  103. return {
  104. // 屏幕宽度, 为了控制分页条的大小
  105. screenWidth: document.body.clientWidth,
  106. currentPage: 1,
  107. pageSize: 20,
  108. totalSize: 0,
  109. dataList: [],
  110. // **********************************************************************
  111. queryInfo: {
  112. subjectId: null,
  113. pageNumber: 1,
  114. pageSize: 10
  115. },
  116. allSubject: []
  117. }
  118. },
  119. created() {
  120. document.title = '试卷管理'
  121. this.getData(this.queryInfo)
  122. this.getSubjects()
  123. },
  124. methods: {
  125. handleCurrentChange(pageNumber) {
  126. this.currentPage = pageNumber
  127. this.queryInfo.pageNumber = this.currentPage
  128. this.queryInfo.pageSize = this.pageSize
  129. this.getData(this.queryInfo)
  130. // 回到顶部
  131. scrollTo(0, 0)
  132. },
  133. getData(queryInfo) {
  134. getPapers(queryInfo).then(resp => {
  135. if (resp.code === 0) {
  136. this.dataList = resp.data.list
  137. this.totalSize = resp.data.totalSize
  138. } else {
  139. this.$notify({
  140. title: '提示',
  141. message: resp.msg,
  142. type: 'warning',
  143. duration: 3000
  144. })
  145. }
  146. }).catch(error => {
  147. this.$notify({
  148. title: '提示',
  149. message: error.message,
  150. type: 'error',
  151. duration: 3000
  152. })
  153. })
  154. },
  155. getSubjects() {
  156. getSubjectKV().then((resp) => {
  157. if (resp.code === 0) {
  158. this.allSubject = resp.data
  159. }
  160. })
  161. },
  162. // 题库变化
  163. subjectChange(val) {
  164. this.queryInfo.subjectId = val
  165. this.queryInfo.pageNumber = this.currentPage
  166. this.queryInfo.pageSize = this.pageSize
  167. this.getData(this.queryInfo)
  168. },
  169. handleDelete(index, row) {
  170. this.$confirm('确定要删除 ' + row.examName + '?', '提示', {
  171. confirmButtonText: '确定',
  172. cancelButtonText: '取消',
  173. type: 'warning'
  174. }).then(() => {
  175. deletePaper(row.examId).then(resp => {
  176. if (resp.code === 0) {
  177. this.$notify({
  178. title: '提示',
  179. message: '稿件已删除',
  180. type: 'warning',
  181. duration: 3000
  182. })
  183. this.$router.go(0)
  184. }
  185. })
  186. }).catch(() => {
  187. this.$message({
  188. type: 'info',
  189. message: '已取消'
  190. })
  191. })
  192. },
  193. addExamPaper() {
  194. this.$router.push('/exam/paper/add')
  195. },
  196. previewPaper(index, row) {
  197. const paperId = row.examId
  198. const routeUrl = this.$router.resolve({
  199. path: '/exam/paper/card/' + paperId,
  200. query: {
  201. status: 1
  202. }
  203. })
  204. window.open(routeUrl.href, '_blank')
  205. }
  206. }
  207. }
  208. </script>
  209. <style>
  210. </style>