index.vue 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <div class="body">
  3. <el-card class="box-card" shadow="never" body-style="padding:0">
  4. <div slot="header" class="clearfix">
  5. <h3 style="float:left">题库列表</h3>
  6. <el-button
  7. type="primary"
  8. style="float: right"
  9. icon="el-icon-plus"
  10. @click="handleAdd"
  11. >添加题目</el-button>
  12. </div>
  13. <ul style="list-style-type: none;margin:24px 0 0 -40px">
  14. <li v-for="item,index in tableData" :key="index" class="questionli" @click="handleEdit(item)">
  15. <span style="width:45px">第{{ index+1 }}题</span>
  16. <span style="width:45px">{{ item.optType === '1'?'单选题':item.optType==='2'?'多选题':'判断题' }}</span>
  17. <span style="flex:1">{{ item.title }}</span>
  18. <el-popconfirm
  19. style="width:30px"
  20. icon="el-icon-info"
  21. icon-color="red"
  22. title="确定删除这个问题吗?"
  23. @onConfirm="handleDelete(item)"
  24. >
  25. <el-button slot="reference" type="text" style="color:red">删除</el-button>
  26. </el-popconfirm>
  27. </li>
  28. </ul>
  29. <el-pagination
  30. v-show="questionTotal!==0"
  31. style="float:right; margin:24px 0"
  32. :total="questionTotal"
  33. :current-page="currentPage"
  34. :page-size="pageSize"
  35. layout="total, prev, pager, next, sizes"
  36. @size-change="handleSizeChange"
  37. @current-change="handleCurrentChange"
  38. />
  39. </el-card>
  40. </div>
  41. </template>
  42. <script>
  43. import { getQuestionList, deleteQuestion } from '@/api/question'
  44. export default {
  45. props: {
  46. gameId: String
  47. },
  48. data() {
  49. return {
  50. tableData: [],
  51. pageSize: 20,
  52. currentPage: 1,
  53. questionTotal: 0// 条目总数
  54. }
  55. },
  56. watch: {
  57. gameId: {
  58. handler(val) {
  59. if (this.gameId) {
  60. this.onSearch()
  61. }
  62. },
  63. immediate: true // 页面加载时就启动
  64. }
  65. },
  66. methods: {
  67. handleSizeChange(val) {
  68. this.pageSize = val
  69. this.changePagination()
  70. },
  71. handleCurrentChange(val) {
  72. this.currentPage = val
  73. this.changePagination()
  74. },
  75. changePagination() {
  76. getQuestionList({ gameId: this.gameId, pageSize: this.pageSize, pageNum: this.currentPage }).then(
  77. (res) => {
  78. this.tableData = res.data.records
  79. }
  80. )
  81. },
  82. // 添加问题
  83. handleAdd() {
  84. this.$emit('handleAddQuestion', true)
  85. },
  86. handleEdit(row) {
  87. // 向外传送数据row.questionId
  88. this.$emit('handleEditQuestion', row.questionId)
  89. },
  90. handleDelete(row) {
  91. deleteQuestion(row.questionId).then(() => {
  92. this.$message('删除问题成功')
  93. this.onSearch()
  94. // 关闭编辑问题页面防止编辑页面还没关闭就删除当前问题了
  95. this.$emit('handleCloseQuestion', true)
  96. })
  97. },
  98. onSearch() {
  99. getQuestionList({ gameId: this.gameId, endDate: this.endDate, pageSize: this.pageSize }).then(
  100. (res) => {
  101. this.tableData = res.data.records
  102. this.questionTotal = res.data.total
  103. this.pageSize = res.data.size
  104. }
  105. )
  106. }
  107. }
  108. }
  109. </script>
  110. <style scoped lang="scss">
  111. .questionli {
  112. width: 100%;
  113. overflow: hidden;
  114. display: flex;
  115. line-height:40px;
  116. background-color: white;
  117. padding:0 8px;
  118. border: 1px solid #f0f2f5;
  119. }
  120. .questionli:nth-of-type(even) {
  121. background: #f0f2f5;
  122. }
  123. .questionli:hover {
  124. background-color: rgb(230, 247, 255);
  125. }
  126. </style>