index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <!--
  2. Description: 我的作业界面
  3. Author: BaiQi
  4. Created Date: 2024-7-3
  5. -->
  6. <template>
  7. <el-card style="margin: 10px auto 0;height: 100%; width: 80%" shadow="never">
  8. <el-button :icon="Refresh" circle @click="doRefresh"></el-button>
  9. <el-select
  10. v-model="state"
  11. placeholder="状态"
  12. size="default"
  13. style="width: 150px; margin-left: 10px;"
  14. >
  15. <el-option
  16. v-for="item in stateOptions"
  17. :key="item.value"
  18. :label="item.label"
  19. :value="item.value"
  20. />
  21. </el-select>
  22. <el-input v-model="assignmentName" placeholder="请输入作业名称" clearable style="width: 180px;"/>
  23. <el-button @click="handleSearch" color="#597D3B">
  24. <el-icon style="margin-right: 3px" ><Search/></el-icon>
  25. 查询
  26. </el-button>
  27. <el-table :data="pageInfo.tableData" style="width: 100%" height="100%" show-overflow-tooltip>
  28. <template #empty>
  29. 暂无作业
  30. </template>
  31. <el-table-column type="index"/>
  32. <el-table-column prop="assignmentName" label="课程名称" width="400"/>
  33. <!-- <el-table-column prop="description" label="描述" width="400"/>-->
  34. <el-table-column prop="endTime" label="截止时间" sortable/>
  35. <el-table-column prop="status" label="状态" sortable>
  36. <template #default="{row}">
  37. <el-tag v-if="row.status === AssignmentStatus.NOT_STARTED" type="info">未发布</el-tag>
  38. <el-tag v-else-if="row.status === AssignmentStatus.PROCEEDING" type="success">进行中</el-tag>
  39. <el-tag v-else-if="row.status === AssignmentStatus.FINISHED" type="danger">已截止</el-tag>
  40. </template>
  41. </el-table-column>
  42. <el-table-column label="操作" width="100">
  43. <template #default="scope">
  44. <el-button @click="handleShowDetail(scope.row.assignmentId)" style="margin-right: 0; margin-left: 0;padding-left: 10px; padding-right: 10px" color="#597D3B">
  45. <el-icon style="margin-right: 3px"><ZoomIn/></el-icon>
  46. 详情
  47. </el-button>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="查看" width="150">
  51. <template #default="scope">
  52. <el-button @click="viewCorrection(scope.row.assignmentId,store.user.id)" style="margin-right: 0; margin-left: 0;padding-left: 10px; padding-right: 10px" color="#597D3B">
  53. <el-icon style="margin-right: 3px"><ZoomIn/></el-icon>
  54. 批改结果
  55. </el-button>
  56. </template>
  57. </el-table-column>
  58. </el-table>
  59. <el-pagination
  60. small
  61. style="font-size: 16px;margin-top: 10px;margin-left: 450px"
  62. @current-change="handleCurrentChange"
  63. @size-change="handleSizeChange"
  64. :page-sizes="[5, 10, 15]"
  65. :current-page="pageInfo.pages"
  66. :page-size="pageInfo.size"
  67. layout="total, sizes, prev, pager, next, jumper"
  68. :total="pageInfo.total">
  69. </el-pagination>
  70. </el-card>
  71. </template>
  72. <script lang="ts" setup>
  73. import {Refresh, ZoomIn, Search} from "@element-plus/icons-vue";
  74. import {inject, onMounted, reactive, ref} from "vue";
  75. import useApis from "@/apis";
  76. import {useStore} from "@/store";
  77. import type {CourseVO, IAssignment} from "@/types/vo";
  78. import router from "@/router";
  79. import {AssignmentStatus} from "@/types/enums";
  80. import {useFormatDate} from "@/hooks/useFormatDate";
  81. const apis = useApis()
  82. const store = useStore()
  83. const doRefresh:Function = inject("reload")
  84. const {formatDate} = useFormatDate()
  85. const role:'teachers' | 'student' = store.user.role === 'STUDENT' ? 'student':'teachers';
  86. // 获取的所有作业
  87. let homeworkList = reactive<{
  88. tableData: IAssignment[]
  89. }>({
  90. tableData: []
  91. })
  92. // 符合查询条件的作业
  93. let processedHomeworkList = reactive<{
  94. tableData: IAssignment[],
  95. }>({
  96. tableData: [],
  97. })
  98. // 最终展示的作业
  99. let pageInfo = reactive<{
  100. tableData: IAssignment[],
  101. size: number, // 分页大小
  102. pages: number, // 总页数
  103. total: number
  104. }>({
  105. tableData: [],
  106. size: 10,
  107. pages: 1,
  108. total: null,
  109. })
  110. // 查看教师批改结果 跳转至批改页面
  111. const viewCorrection = (assignmentId:number,studentId:number) => {
  112. router.push(`/home/assignment/${assignmentId}/correct?studentId=${studentId}`)
  113. }
  114. const handleShowDetail = (assignmentId:number) => {
  115. router.push(`/home/homeworkDetail/${assignmentId}`)
  116. }
  117. const handleCurrentChange = (pageNum: number) => {
  118. Object.assign(pageInfo, {
  119. tableData: getSlice(pageNum, pageInfo.size),
  120. size: pageInfo.size,
  121. pages: pageNum,
  122. total: processedHomeworkList.tableData.length,
  123. })
  124. }
  125. const handleSizeChange = (pageSize: number) => {
  126. Object.assign(pageInfo, {
  127. tableData: getSlice(1, pageSize),
  128. size: pageSize,
  129. pages: 1,
  130. total: processedHomeworkList.tableData.length,
  131. })
  132. }
  133. const fetchData = () => {
  134. if (role === 'student') {
  135. apis.getCourseByStudentId()
  136. .then((res: any) => {
  137. // 获取课程总数
  138. let total = res.data.data.total;
  139. apis.getCourseByStudentId(1, total)
  140. .then((res: any) => {
  141. let data:CourseVO[] = res.data.data.records
  142. for(let i = 0; i < data.length; i++){
  143. fetchHomeworkListByCourseId(data[i].courseId)
  144. }
  145. })
  146. })
  147. } else if (role === "teachers") {
  148. apis.getCourseByTeacherId()
  149. .then((res: any) => {
  150. // 获取课程总数
  151. let total = res.data.data.total;
  152. apis.getCourseByTeacherId(1, total)
  153. .then((res: any) => {
  154. let data:CourseVO[] = res.data.data.records
  155. for(let i = 0; i < data.length; i++){
  156. fetchHomeworkListByCourseId(data[i].courseId)
  157. }
  158. })
  159. })
  160. }
  161. }
  162. const fetchHomeworkListByCourseId = (courseId:number) => {
  163. apis.getAssignmentByCourseId(courseId)
  164. .then((res: any) => {
  165. let total = res.data.data.total
  166. apis.getAssignmentByCourseId(courseId, 1, total)
  167. .then((res: any) => {
  168. let data = res.data.data.records
  169. for(let i = 0; i < data.length; i++) {
  170. data[i].endTime = formatDate(data[i].endTime)
  171. homeworkList.tableData.push(data[i])
  172. }
  173. processedHomeworkList.tableData = homeworkList.tableData
  174. Object.assign(pageInfo, {
  175. tableData: getSlice(pageInfo.pages, pageInfo.size),
  176. size: pageInfo.size,
  177. pages: pageInfo.pages,
  178. total: processedHomeworkList.tableData.length,
  179. })
  180. })
  181. })
  182. }
  183. const handleSearch = () => {
  184. processedHomeworkList.tableData = []
  185. for(let i = 0; i < homeworkList.tableData.length; i++){
  186. let assignmentItem = homeworkList.tableData[i]
  187. let input = true;
  188. if(state.value != null && state.value != assignmentItem.status) input = false;
  189. if(assignmentName.value != '' && !assignmentItem.assignmentName.includes(assignmentName.value)) input = false;
  190. if(input) processedHomeworkList.tableData.push(assignmentItem);
  191. Object.assign(pageInfo, {
  192. tableData: getSlice(pageInfo.pages, pageInfo.size),
  193. size: pageInfo.size,
  194. pages: pageInfo.pages,
  195. total: processedHomeworkList.tableData.length,
  196. })
  197. }
  198. }
  199. //用于分页展示,截取数据
  200. const getSlice = (page: number, size: number) => {
  201. return processedHomeworkList.tableData.slice((page-1)*size, page*size)
  202. }
  203. onMounted(() => {
  204. fetchData()
  205. })
  206. let state = ref(null)
  207. const stateOptions = [
  208. {
  209. value: AssignmentStatus.NOT_STARTED,
  210. label: "未发布"
  211. },
  212. {
  213. value: AssignmentStatus.PROCEEDING,
  214. label: "进行中"
  215. },
  216. {
  217. value: AssignmentStatus.FINISHED,
  218. label: "已截止"
  219. },
  220. ]
  221. let assignmentName = ref('')
  222. </script>
  223. <script lang="ts">
  224. export default {
  225. name: "HomeworkPage"
  226. }
  227. </script>