answer.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <div class="container-md">
  3. <div class="tip-box">
  4. 选择用于本节直播课程的题库试题,试题可用于直播间内发送
  5. <el-link
  6. type="primary"
  7. style="margin-left: 5px;"
  8. @click="handleToQuestionBank"
  9. >配置题库试题 >></el-link>
  10. </div>
  11. <el-button type="primary" icon="el-icon-plus" style="margin: 20px 0;" @click="handleAddQuestion">添加试题</el-button>
  12. <!-- 试题列表表格 -->
  13. <el-table
  14. :data="questionLiveList"
  15. style="width: 100%"
  16. v-loading="loading"
  17. >
  18. <!-- 题干列:显示试题的主要内容 -->
  19. <el-table-column
  20. prop="title"
  21. label="题干"
  22. show-overflow-tooltip
  23. ></el-table-column>
  24. <!-- 题型列:显示是单选还是多选 -->
  25. <el-table-column
  26. prop="type"
  27. label="题型"
  28. >
  29. <template slot-scope="scope">
  30. {{ scope.row.type === 1 ? '单选题' : '多选题' }}
  31. </template>
  32. </el-table-column>
  33. <!-- 创建时间列:显示试题创建的时间 -->
  34. <el-table-column
  35. prop="createTime"
  36. label="创建时间"
  37. ></el-table-column>
  38. <!-- 操作列:包含编辑和删除按钮 -->
  39. <el-table-column
  40. label="操作"
  41. width="180"
  42. fixed="right"
  43. >
  44. <template slot-scope="scope">
  45. <!-- 删除按钮:用于移除试题 -->
  46. <el-button
  47. type="text"
  48. size="small"
  49. style="color: #F56C6C;"
  50. @click="handleDelete(scope.row)"
  51. >删除</el-button>
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. <!-- 分页组件:用于分页展示试题列表 -->
  56. <pagination
  57. v-show="questionTotal > 0"
  58. :total="questionTotal"
  59. :page.sync="questionParams.pageNum"
  60. :limit.sync="questionParams.pageSize"
  61. @pagination="getLiveQuestionLiveList"
  62. style="margin-top: 20px;"
  63. />
  64. <!-- 添加试题弹窗 -->
  65. <el-dialog
  66. title="添加试题"
  67. :visible.sync="questionDialogVisible"
  68. width="800px"
  69. :close-on-click-modal="false"
  70. :close-on-press-escape="false"
  71. >
  72. <div class="dialog-content">
  73. <div style="text-align: right; margin-bottom: 20px;">
  74. <el-input
  75. v-model="searchTitle"
  76. placeholder="请输入搜索内容"
  77. style="width: 300px;"
  78. @input="handleQuestionSearch"
  79. ></el-input>
  80. </div>
  81. <el-table
  82. ref="questionTable"
  83. :data="questionList"
  84. style="width: 100%"
  85. v-loading="questionLoading"
  86. @selection-change="handleSelectionChange"
  87. @row-click="handleRowClick"
  88. row-key="id"
  89. >
  90. <!-- 复选框列:用于多选试题 -->
  91. <el-table-column
  92. type="selection"
  93. width="55"
  94. >
  95. </el-table-column>
  96. <!-- 题干列:显示试题的主要内容 -->
  97. <el-table-column
  98. prop="title"
  99. label="题干"
  100. class-name="clickable-column"
  101. ></el-table-column>
  102. <!-- 题型列:显示单选或多选 -->
  103. <el-table-column
  104. prop="type"
  105. label="题型"
  106. class-name="clickable-column"
  107. >
  108. <template slot-scope="scope">
  109. {{ scope.row.type === 1 ? '单选题' : '多选题' }}
  110. </template>
  111. </el-table-column>
  112. <!-- 创建人列 -->
  113. <el-table-column
  114. prop="createBy"
  115. label="创建人"
  116. class-name="clickable-column"
  117. ></el-table-column>
  118. <!-- 创建时间列 -->
  119. <el-table-column
  120. prop="createTime"
  121. label="创建时间"
  122. width="150"
  123. class-name="clickable-column"
  124. ></el-table-column>
  125. </el-table>
  126. <pagination
  127. v-show="total > 0"
  128. :total="total"
  129. :page.sync="queryParams.pageNum"
  130. :limit.sync="queryParams.pageSize"
  131. @pagination="getQuestionList"
  132. style="margin-top: 20px;"
  133. />
  134. </div>
  135. <div slot="footer" class="dialog-footer">
  136. <div style="display: flex; justify-content: space-between; align-items: center;">
  137. <span class="selected-count">当前已选择 <span style="color: #00BFFF; font-style: italic;">{{ selectedQuestions.length }}</span> 题</span>
  138. <div>
  139. <el-button @click="questionDialogVisible = false">取 消</el-button>
  140. <el-button type="primary" @click="confirmAddQuestion">确 定</el-button>
  141. </div>
  142. </div>
  143. </div>
  144. </el-dialog>
  145. </div>
  146. </template>
  147. <script>
  148. import {addLiveQuestionLive, listLiveQuestionLive, listLiveQuestionOptionList} from "@/api/live/liveQuestionLive";
  149. export default {
  150. data() {
  151. return {
  152. questionDialogVisible: false,
  153. questionLoading: false,
  154. questionTotal: 0,
  155. selectedQuestions: [],
  156. questionLiveList: [],
  157. questionList: [],
  158. loading: true,
  159. searchTitle: '',
  160. total: 0,
  161. queryParams: {
  162. pageNum: 1,
  163. pageSize: 10,
  164. title: null,
  165. liveId: null
  166. },
  167. questionParams: {
  168. pageNum: 1,
  169. pageSize: 10,
  170. liveId: null
  171. },
  172. };
  173. },
  174. created() {
  175. this.liveId = this.$route.params.liveId
  176. this.queryParams.liveId = this.liveId
  177. this.questionParams.liveId = this.liveId
  178. this.getLiveQuestionLiveList()
  179. },
  180. methods: {
  181. handleQuestionSearch() {
  182. this.queryParams.pageNum = 1
  183. this.queryParams.title = this.searchTitle
  184. this.getQuestionList()
  185. },
  186. getLiveQuestionLiveList() {
  187. this.loading = true
  188. listLiveQuestionLive(this.questionParams).then(response => {
  189. this.questionLiveList = response.rows
  190. this.questionTotal = response.total
  191. this.loading = false
  192. })
  193. },
  194. handleToQuestionBank() {
  195. this.$router.push('/live/liveQuestionBank')
  196. },
  197. handleAddQuestion() {
  198. this.questionDialogVisible = true
  199. this.getQuestionList()
  200. },
  201. getQuestionList() {
  202. this.questionLoading = true
  203. listLiveQuestionOptionList(this.queryParams).then(response => {
  204. this.questionList = response.rows
  205. this.total = response.total
  206. this.questionLoading = false
  207. })
  208. },
  209. handleSelectionChange(selection) {
  210. this.selectedQuestions = selection
  211. },
  212. confirmAddQuestion() {
  213. if (this.selectedQuestions.length === 0) {
  214. this.$message({
  215. message: '请选择要添加的试题',
  216. type: 'warning'
  217. })
  218. return
  219. }
  220. // 调用添加直播间试题接口
  221. addLiveQuestionLive({
  222. liveId: this.liveId,
  223. questionIds: this.selectedQuestions.map(item => item.id).join(',')
  224. }).then(response => {
  225. this.questionDialogVisible = false
  226. this.getLiveQuestionLiveList()
  227. })
  228. },
  229. handleRowClick(row, column) {
  230. // 如果点击的是复选框列,不进行处理
  231. if (column.type === 'selection') {
  232. return
  233. }
  234. // 获取表格实例
  235. const table = this.$refs.questionTable[0]
  236. if (!table) {
  237. return
  238. }
  239. // 判断当前行是否已经被选中
  240. const isSelected = this.selectedQuestions.some(item => item.id === row.id)
  241. // 切换选中状态
  242. table.toggleRowSelection(row, !isSelected)
  243. },
  244. }
  245. };
  246. </script>