index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div>
  3. <page-header :routes="[{ name: '代码作业', path: 'code' }]">
  4. <template slot="title">
  5. 代码作业列表
  6. </template>
  7. <template slot="content">
  8. 共有 {{ codeData.length }} 份作业
  9. </template>
  10. <template slot="action">
  11. <create-assignment
  12. @sendCreatedAssignment="pushNewAssignment($event)"
  13. :course-id="course.id"
  14. :assign-type="assignType"
  15. ></create-assignment>
  16. </template>
  17. </page-header>
  18. <page-body>
  19. <div class="data-table">
  20. <b-table :data="codeData" detailed detail-key="id">
  21. <template slot-scope="props">
  22. <b-table-column field="id" label="ID" numeric sortable centered>
  23. {{ props.row.id }}
  24. </b-table-column>
  25. <b-table-column label="作业名称" centered>
  26. <router-link
  27. :to="{
  28. path: `code/${props.row.id}`,
  29. query: {
  30. assignmentInfo: props.row.problem,
  31. title: props.row.name
  32. }
  33. }"
  34. >
  35. {{ props.row.name }}
  36. </router-link>
  37. </b-table-column>
  38. <b-table-column label="状态" centered>
  39. {{ props.row.status }}
  40. </b-table-column>
  41. <b-table-column label="开始时间" centered>
  42. {{ displayUnixTime(props.row.startAt) }}
  43. </b-table-column>
  44. <b-table-column label="结束时间" centered>
  45. {{ displayUnixTime(props.row.endAt) }}
  46. </b-table-column>
  47. <b-table-column label="修改" centered>
  48. <update-assignment
  49. :assign-type="assignType"
  50. :update-item="props.row"
  51. @updateDocData="updateData($event)"
  52. ></update-assignment>
  53. </b-table-column>
  54. <b-table-column label="删除" centered>
  55. <delete-assignment
  56. :del-id="props.row.id"
  57. :assign-type="assignType"
  58. @del="deleteAssignment(props.row.id)"
  59. ></delete-assignment>
  60. </b-table-column>
  61. </template>
  62. <template slot="detail" slot-scope="props">
  63. <article class="media">
  64. <div class="media-content">
  65. <div class="content">
  66. <p>
  67. <strong>作业描述:</strong>
  68. <small>{{ props.row.description }}</small> <br />
  69. </p>
  70. </div>
  71. </div>
  72. </article>
  73. </template>
  74. </b-table>
  75. </div>
  76. </page-body>
  77. </div>
  78. </template>
  79. <script>
  80. import PageHeader from "@/components/PageHeader";
  81. import PageBody from "@/components/PageBody/index";
  82. import { getCodeAssignmentListByTeacher } from "@/api/assignment";
  83. import timeMixins from "@/mixins/time";
  84. import { mapState } from "vuex";
  85. import DeleteAssignment from "@/components/AssignmentCRUD/DeleteAssignment";
  86. import UpdateAssignment from "@/components/AssignmentCRUD/UpdateAssignment";
  87. import CreateAssignment from "@/components/AssignmentCRUD/CreateAssignment";
  88. export default {
  89. components: {
  90. PageBody,
  91. PageHeader,
  92. DeleteAssignment,
  93. UpdateAssignment,
  94. CreateAssignment
  95. },
  96. mixins: [timeMixins],
  97. mounted() {
  98. getCodeAssignmentListByTeacher(this.course.id).then(res => {
  99. this.codeData = res.data;
  100. });
  101. },
  102. data() {
  103. return {
  104. codeData: [],
  105. assignType: 0
  106. };
  107. },
  108. methods: {
  109. pushNewAssignment(item) {
  110. this.codeData.push(item);
  111. },
  112. updateData(modifiedItem) {
  113. let length = this.codeData.length;
  114. for (let i = 0; i < length; i++) {
  115. if (modifiedItem.id === this.codeData[i].id) {
  116. this.codeData.splice(i, 1, modifiedItem);
  117. break;
  118. }
  119. }
  120. },
  121. deleteAssignment(delId) {
  122. let length = this.codeData.length;
  123. for (let i = 0; i < length; i++) {
  124. if (this.codeData[i].id === delId) {
  125. this.codeData.splice(i, 1);
  126. break;
  127. }
  128. }
  129. }
  130. },
  131. computed: {
  132. ...mapState({
  133. course: state => state.course.currentCourse
  134. })
  135. }
  136. };
  137. </script>
  138. <style lang="scss" scoped>
  139. .card {
  140. padding: 30px;
  141. .title {
  142. font-size: 1.25rem;
  143. small {
  144. color: gray;
  145. font-size: 1rem;
  146. }
  147. }
  148. .content {
  149. a {
  150. margin-top: 30px;
  151. width: 100%;
  152. }
  153. }
  154. }
  155. </style>