homework.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div class="app-container">
  3. <el-card>
  4. <div class="fx-row fx-end-cen mb10">
  5. <el-button icon="el-icon-refresh" circle @click="queryParams.pageNum=1,getList()"></el-button>
  6. </div>
  7. <dynamic-table :columns="columns" :rows="rows">
  8. <template #type="{display}">
  9. {{ translateType(display) }}
  10. </template>
  11. <template #status="{row}">
  12. {{ row.isDo ? '已完成' : '未完成' }}
  13. </template>
  14. <template #action="{row}">
  15. <el-button v-if="useVideoAction(row)" type="text" icon="el-icon-video-camera"
  16. @click="handleVideo(row)">观看
  17. </el-button>
  18. <el-button v-if="usePaperAction(row)" type="text" :icon="row.isDo?'el-icon-view':'el-icon-edit'"
  19. @click="handlePaper(row)">{{ row.isDo ? '查看' : '做题' }}
  20. </el-button>
  21. </template>
  22. </dynamic-table>
  23. <pagination v-if="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
  24. @pagination="getList"></pagination>
  25. <el-dialog v-if="videoOption.visible" :visible.sync="videoOption.visible" :title="videoOption.title"
  26. :close-on-click-modal="false" width="800px" @close="handleVideoClosed">
  27. <mx-video :src="videoOption.src" :ali-id-type="videoOption.aliIdType"></mx-video>
  28. </el-dialog>
  29. <!--elDrawer不要内嵌在elDialog中,否则遮罩可能重迭-->
  30. <el-drawer v-if="paperOption.visible" :visible.sync="paperOption.visible" :title="paperOption.title"
  31. :close-on-click-modal="false" size="100%" @close="handlePaperClose">
  32. <div class="pl30 pr30 pb30">
  33. <homework-paper :params="paperOption.params"></homework-paper>
  34. </div>
  35. </el-drawer>
  36. </el-card>
  37. </div>
  38. </template>
  39. <script>
  40. import DynamicTable from '@/components/dynamic-table/index'
  41. import { getStudentHomeworks } from '@/api/webApi/homework'
  42. import consts from '@/common/mx-const'
  43. import HomeworkPaper from '@/views/questioncenter/components/homework-paper'
  44. export default {
  45. name: 'homework',
  46. components: { HomeworkPaper, DynamicTable },
  47. data() {
  48. return {
  49. queryParams: {
  50. pageNum: 1,
  51. pageSize: 20
  52. },
  53. columns: [
  54. { prop: 'id', label: 'ID', width: '80px' },
  55. { prop: 'type', label: '类型', width: '120px', slotBody: 'type' },
  56. { prop: 'createTime', label: '创建时间', width: '180px' },
  57. { prop: 'title', label: '标题' },
  58. { prop: 'remark', label: '备注' },
  59. { prop: 'status', label: '状态', width: '80px', slotBody: 'status' },
  60. { prop: 'action', label: '操作', width: '120px', slotBody: 'action' }
  61. ],
  62. rows: [],
  63. total: 0,
  64. // dialog video
  65. videoOption: {
  66. visible: false,
  67. title: '',
  68. src: null,
  69. aliIdType: consts.enum.aliIdType.AliIdResourcePerson
  70. },
  71. paperOption: {
  72. visible: false,
  73. params: {
  74. id: '',
  75. type: ''
  76. },
  77. title: ''
  78. }
  79. }
  80. },
  81. mounted() {
  82. this.getList()
  83. },
  84. deactivated() {
  85. // NOTE: 强制跳出时(如浏览器后退),主动隐藏弹层,否则遮罩可能不会自动隐藏
  86. this.videoOption.visible = false
  87. this.paperOption.visible = false
  88. },
  89. methods: {
  90. async getList() {
  91. const res = await getStudentHomeworks(this.queryParams)
  92. this.rows = res.rows || res.data
  93. this.total = res.total || this.rows.length
  94. },
  95. translateType(type) {
  96. const enumType = consts.enum.homeworkTypes.find(t => t.value == type)
  97. return enumType?.label || type
  98. },
  99. usePaperAction(row) {
  100. return consts.enum.homeworkTypes.find(t => t.value == row.type)?.usePaper
  101. },
  102. useVideoAction(row) {
  103. return consts.enum.homeworkTypes.find(t => t.value == row.type)?.useVideo
  104. },
  105. handleVideo(row) {
  106. this.videoOption.src = row.content
  107. this.videoOption.title = row.title
  108. this.videoOption.visible = true
  109. },
  110. handleVideoClosed() {
  111. // 稍等,先让视频观看记录自动提交,再触发刷新,以获取到新的作业完成状态
  112. setTimeout(() => this.getList(), 200)
  113. },
  114. handlePaper(row) {
  115. this.paperOption.params.id = row.id
  116. this.paperOption.params.type = row.type
  117. this.paperOption.title = this.translateType(row.type)
  118. this.paperOption.visible = true
  119. },
  120. handlePaperClose() {
  121. setTimeout(() => this.getList(), 200)
  122. }
  123. }
  124. }
  125. </script>
  126. <style scoped>
  127. </style>