ExamPaperList.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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="paperName"
  35. label="试卷名称"
  36. width="150"
  37. />
  38. <el-table-column
  39. prop="subject"
  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="scope"
  59. label="试卷用户"
  60. >
  61. <template slot-scope="scope">
  62. <el-tag
  63. v-if="scope.row.scope === 1"
  64. size="mini"
  65. >所有用户</el-tag>
  66. <el-tag
  67. v-else
  68. size="mini"
  69. type="success"
  70. >VIP用户</el-tag>
  71. </template>
  72. </el-table-column>
  73. <el-table-column
  74. prop="markType"
  75. label="阅卷类型"
  76. >
  77. <template slot-scope="scope">
  78. <el-tag
  79. v-if="scope.row.markType === 1"
  80. size="mini"
  81. >管理员阅卷</el-tag>
  82. <el-tag
  83. v-else
  84. size="mini"
  85. type="success"
  86. >自主阅卷</el-tag>
  87. </template>
  88. </el-table-column>
  89. <el-table-column
  90. label="测评码"
  91. >
  92. <template slot-scope="scope">
  93. <el-tag
  94. v-if="scope.row.passcode === undefined"
  95. size="mini"
  96. >不需要</el-tag>
  97. <el-tag
  98. v-else
  99. size="mini"
  100. type="success"
  101. >{{ scope.row.passcode }}</el-tag>
  102. </template>
  103. </el-table-column>
  104. <el-table-column
  105. label="状态"
  106. >
  107. <template slot-scope="scope">
  108. <el-tag
  109. v-if="scope.row.expired"
  110. size="mini"
  111. type="danger"
  112. >已过期</el-tag>
  113. <el-tag
  114. v-else
  115. size="mini"
  116. type="success"
  117. >未过期</el-tag>
  118. </template>
  119. </el-table-column>
  120. <el-table-column
  121. fixed="right"
  122. label="操作"
  123. width="320"
  124. >
  125. <template slot-scope="scope">
  126. <el-button
  127. size="mini"
  128. type="warning"
  129. @click="previewPaper(scope.$index, scope.row)"
  130. >预览</el-button>
  131. <el-button
  132. size="mini"
  133. type="warning"
  134. @click="handleDelete(scope.$index, scope.row)"
  135. >删除</el-button>
  136. </template>
  137. </el-table-column>
  138. </el-table>
  139. <el-pagination
  140. background
  141. :small="screenWidth <= 768"
  142. layout="prev, pager, next"
  143. :page-size="pageSize"
  144. :current-page="currentPage"
  145. :total="totalSize"
  146. @current-change="handleCurrentChange"
  147. @prev-click="handleCurrentChange"
  148. @next-click="handleCurrentChange"
  149. />
  150. </el-main>
  151. </el-container>
  152. </template>
  153. <script>
  154. import { getSubjectKV, getPapers, deletePaper } from '@/api/exam'
  155. export default {
  156. name: 'ExamPaperList',
  157. data() {
  158. return {
  159. // 屏幕宽度, 为了控制分页条的大小
  160. screenWidth: document.body.clientWidth,
  161. currentPage: 1,
  162. pageSize: 20,
  163. totalSize: 0,
  164. dataList: [],
  165. // **********************************************************************
  166. queryInfo: {
  167. subjectId: null,
  168. pageNumber: 1,
  169. pageSize: 10
  170. },
  171. allSubject: []
  172. }
  173. },
  174. created() {
  175. document.title = '试卷管理'
  176. this.getData(this.queryInfo)
  177. this.getSubjects()
  178. },
  179. methods: {
  180. handleCurrentChange(pageNumber) {
  181. this.currentPage = pageNumber
  182. this.queryInfo.pageNumber = this.currentPage
  183. this.queryInfo.pageSize = this.pageSize
  184. this.getData(this.queryInfo)
  185. // 回到顶部
  186. scrollTo(0, 0)
  187. },
  188. getData(queryInfo) {
  189. getPapers(queryInfo).then(resp => {
  190. if (resp.code === 0) {
  191. this.dataList = resp.data.list
  192. this.totalSize = resp.data.totalSize
  193. } else {
  194. this.$notify({
  195. title: '提示',
  196. message: resp.msg,
  197. type: 'warning',
  198. duration: 3000
  199. })
  200. }
  201. }).catch(error => {
  202. this.$notify({
  203. title: '提示',
  204. message: error.message,
  205. type: 'error',
  206. duration: 3000
  207. })
  208. })
  209. },
  210. getSubjects() {
  211. getSubjectKV().then((resp) => {
  212. if (resp.code === 0) {
  213. this.allSubject = resp.data
  214. }
  215. })
  216. },
  217. // 题库变化
  218. subjectChange(val) {
  219. this.queryInfo.subjectId = val
  220. this.queryInfo.pageNumber = this.currentPage
  221. this.queryInfo.pageSize = this.pageSize
  222. this.getData(this.queryInfo)
  223. },
  224. handleDelete(index, row) {
  225. this.$confirm('确定要删除 ' + row.paperName + '?', '提示', {
  226. confirmButtonText: '确定',
  227. cancelButtonText: '取消',
  228. type: 'warning'
  229. }).then(() => {
  230. deletePaper(row.paperId).then(resp => {
  231. if (resp.code === 0) {
  232. this.$notify({
  233. title: '提示',
  234. message: '稿件已删除',
  235. type: 'warning',
  236. duration: 3000
  237. })
  238. this.$router.go(0)
  239. }
  240. })
  241. }).catch(() => {
  242. this.$message({
  243. type: 'info',
  244. message: '已取消'
  245. })
  246. })
  247. },
  248. addExamPaper() {
  249. this.$router.push('/exam/paper/add')
  250. },
  251. previewPaper(index, row) {
  252. const paperId = row.paperId
  253. const routeUrl = this.$router.resolve({
  254. path: '/exam/paper/detail',
  255. query: {
  256. paperId: paperId,
  257. viewType: 1,
  258. userId: ''
  259. }
  260. })
  261. window.open(routeUrl.href, '_blank')
  262. }
  263. }
  264. }
  265. </script>
  266. <style>
  267. </style>