HomeworkDetail.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div class="homework-details">
  3. <div class="homework-details-title">
  4. 作业详情
  5. </div>
  6. <div class="homework-details-info">
  7. <div class="homework-details-text">
  8. <div class="title">
  9. {{data.assignmentName}}
  10. </div>
  11. <div class="item">
  12. <span style="font-weight: 600">作业描述: </span>
  13. {{data.description}}
  14. </div>
  15. <div class="item">
  16. <span style="font-weight: 600">发布老师: </span>
  17. {{data.teacherId}}
  18. </div>
  19. <div class="item">
  20. <span style="font-weight: 600">截止日期: </span>
  21. {{new Date(Date.parse(data.endTime)).toLocaleString()}}
  22. </div>
  23. <div class="item">
  24. <el-link type="primary" @click="downloadFile(data.descriptionFile, `${data.assignmentName}-描述文件`)">相关文件下载</el-link>
  25. <el-button color="#597d3b" size="large" style="margin-left: 660px" @click="handleWriting()" :disabled="new Date() > new Date(data.endTime)">开始写作</el-button>
  26. </div>
  27. </div>
  28. </div>
  29. <!-- <div class="homework-details-title">-->
  30. <!-- 评论区-->
  31. <!-- </div>-->
  32. <!-- <div class="homework-remark">-->
  33. <!-- <div>-->
  34. <!-- <el-skeleton style="width: 240px" animated >-->
  35. <!-- <template #template>-->
  36. <!-- <el-skeleton-item variant="circle" style="&#45;&#45;el-skeleton-circle-size: 40px"></el-skeleton-item>-->
  37. <!-- <el-skeleton-item variant="text" style="height: 40px;width: 200px; margin-left: 30px"></el-skeleton-item>-->
  38. <!-- </template>-->
  39. <!-- </el-skeleton>-->
  40. <!-- </div>-->
  41. <!-- <div>-->
  42. <!-- <el-input type="textarea" style="width: 100%;margin: 20px 0"></el-input>-->
  43. <!-- <el-button color="#597d3b" size="large" style="float: right" :disabled="true">发布</el-button>-->
  44. <!-- </div>-->
  45. <!-- </div>-->
  46. </div>
  47. </template>
  48. <script lang="ts" setup>
  49. import useApis from "@/apis";
  50. import {useRoute} from "vue-router";
  51. import {onMounted, reactive} from "vue";
  52. import type {IAssignment} from "@/types/vo";
  53. import './homeworkDetail.scss'
  54. import {useStore} from "@/store";
  55. import router from "@/router";
  56. import {ElMessage} from "element-plus";
  57. const apis = useApis()
  58. const store = useStore()
  59. const route = useRoute()
  60. const assignmentId = +route.params.assignmentId //string转number
  61. let data = reactive<IAssignment>({
  62. assignmentId: null,
  63. assignmentName: "",
  64. description: "",
  65. descriptionFile: null,
  66. attachments: null,
  67. teacherId: null,
  68. courseId: null,
  69. startTime: "",
  70. endTime: "",
  71. createTime: "",
  72. status: ""
  73. })
  74. function handleWriting(){
  75. getEngagement()
  76. router.push(`/home/assignment/${assignmentId}/edit`)
  77. }
  78. function downloadFile(url:string, fileName:string) {
  79. const link = document.createElement('a');
  80. link.href = url;
  81. //link.download = fileName;
  82. //link.target = "_blank"; // 可选,如果希望在新窗口中下载文件,请取消注释此行
  83. link.click();
  84. }
  85. async function getEngagement(){
  86. apis.getEngagement(store.user.id, assignmentId)
  87. .then((_res:any) => {
  88. console.log(_res)
  89. //还未参加作业,则先加入作业
  90. if(_res.data.data == null){
  91. apis.engageAssignment(assignmentId)
  92. .then((res:any) => {
  93. ElMessage({
  94. message: '参加作业成功',
  95. type: 'success',
  96. })
  97. })
  98. .catch((_err:any) => {
  99. console.log("参加做业的错误",_err)
  100. })
  101. }
  102. }).catch((_err:any) => {
  103. console.log(_err)
  104. })
  105. }
  106. const fetchData = () => {
  107. apis.getAssignmentById(assignmentId)
  108. .then((res: any) => {
  109. Object.assign(data, res.data.data)
  110. })
  111. }
  112. onMounted(() => {
  113. fetchData()
  114. })
  115. </script>
  116. <script lang="ts">
  117. export default {
  118. name: "HomeworkDetail"
  119. }
  120. </script>