CoderCard.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <el-card class="coder" shadow="hover" @click="toTestInfo">
  3. <div
  4. style="border-bottom: 30px solid #8dc9e2; float: right; width: 0; height: 0; position: absolute;right: 0;bottom: 0;border-left: 30px solid transparent;">
  5. <div style="padding: 0 3px 0 3px; position: absolute; right: 0; bottom: -30px; color: white">
  6. C
  7. </div>
  8. </div>
  9. <el-row>
  10. <el-col :span="16" class="name">
  11. {{ coderVO.name }}
  12. </el-col>
  13. <el-col :span="8" class="status">
  14. <el-tag v-if="state==='NOT_STARTED'" size="small" type="info">未开始</el-tag>
  15. <el-tag v-else-if="state==='RUNNING'" size="small">进行中</el-tag>
  16. <el-tag v-else-if="state==='CLOSED'" size="small" type="info">已关闭</el-tag>
  17. <el-tag v-else-if="state==='FINISHED'" size="small" type="danger">已结束</el-tag>
  18. </el-col>
  19. </el-row>
  20. <el-row class="teacher">
  21. 教师: {{ teacher.name }}
  22. </el-row>
  23. <el-row class="course">
  24. 所属课程: {{ coderVO.course }}
  25. </el-row>
  26. <el-row class="time">
  27. 时间: {{ timestampToTime(coderVO.startAt) }} 至 {{ timestampToTime(coderVO.endAt) }}
  28. </el-row>
  29. <!-- <el-row class="button">-->
  30. <!-- <el-col :span="24">-->
  31. <!-- <el-button v-if="state==='FINISHED'" size="small" type="success" plain>结果报告</el-button>-->
  32. <!-- <el-button v-else size="small" type="primary" plain>查看详情</el-button>-->
  33. <!-- </el-col>-->
  34. <!-- </el-row>-->
  35. </el-card>
  36. </template>
  37. <script>
  38. import {ElMessageBox, ElMessage} from "element-plus";
  39. export default {
  40. name: "CoderCard",
  41. props: {
  42. coderVO: {
  43. type: Object,
  44. default: () => {
  45. },
  46. }
  47. },
  48. data() {
  49. return {
  50. teacher: {
  51. type: Object,
  52. default: {
  53. name: "暂无信息",
  54. },
  55. },
  56. };
  57. },
  58. computed: {
  59. state: function () {
  60. if (this.coderVO.status === "CLOSED") {
  61. return "CLOSED";
  62. } else if (this.coderVO.startAt * 1000 > new Date()) {
  63. return "NOT_STARTED";
  64. } else if (this.coderVO.endAt * 1000 < new Date()) {
  65. return "FINISHED";
  66. } else {
  67. return "RUNNING";
  68. }
  69. },
  70. isTeacher() {
  71. return this.$store.state.user.role === "TEACHER";
  72. }
  73. },
  74. async mounted() {
  75. const res = await this.$apis.getUserAPI(this.coderVO.creator.id);
  76. if (res.data.code === 0) {
  77. this.teacher = res.data.data;
  78. } else {
  79. this.teacher = {name: this.coderVO.creator.username};
  80. }
  81. },
  82. methods: {
  83. timestampToTime(timestamp) {
  84. const date = new Date(timestamp * 1000);
  85. const Y = date.getFullYear() + "-";
  86. const M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-";
  87. const D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());
  88. return Y + M + D;
  89. },
  90. async toTestInfo() {
  91. if (!this.$store.state.user.token) {
  92. await this.$router.push("/auth");
  93. return;
  94. }
  95. let messageBoxContent = "";
  96. let messageBoxTitle = "Coder";
  97. let confirmButtonText = "";
  98. let cancelButtonText = "让我想想";
  99. let nextURL = "";
  100. if (this.isTeacher) {
  101. if (this.$store.state.user.id === this.coderVO.id) {
  102. nextURL = "https://coder.seec.seecoder.cn/exam/" + this.coderVO.id + "?id_token=" + this.$store.state.user.token;
  103. window.open(nextURL);
  104. } else {
  105. ElMessage.error("无权访问其他教师创建的测试");
  106. }
  107. } else {
  108. // todo: 跳转流程中还需要考虑CoderExam的状态
  109. const res = await this.$apis.getStudentCoderExams({});
  110. const userCoderExams = res.data.data.res;
  111. for (let userCoderExam of userCoderExams) {
  112. if (this.coderVO.id === userCoderExam.id) {
  113. if (userCoderExam.joined) {
  114. nextURL = "https://coder.seec.seecoder.cn/exam/" + this.coderVO.id + "?id_token=" + this.$store.state.user.token;
  115. window.open(nextURL);
  116. return;
  117. } else {
  118. messageBoxContent = "尚未参加该测试,是否立即参加?";
  119. confirmButtonText = "立即参加";
  120. nextURL = "https://coder.seec.seecoder.cn/exam?id_token=" + this.$store.state.user.token;
  121. }
  122. }
  123. }
  124. if (messageBoxContent === "") {
  125. const res = await this.$apis.getCourseByCoderId(this.coderVO.courseId);
  126. if (res.data.data === null) {
  127. nextURL = "https://coder.seec.seecoder.cn/course/select?id_token=" + this.$store.state.user.token;
  128. messageBoxContent = "尚未选择该Coder课程,是否前往Coder系统?";
  129. confirmButtonText = "前往选课";
  130. } else {
  131. nextURL = "/course/" + res.data.data.id;
  132. messageBoxContent = "尚未选择该课程,是否前往选课?";
  133. confirmButtonText = "前往选课";
  134. }
  135. }
  136. ElMessageBox.confirm(messageBoxContent, messageBoxTitle, {
  137. distinguishCancelAndClose: true,
  138. confirmButtonText,
  139. cancelButtonText,
  140. })
  141. .then(() => {
  142. if (nextURL.startsWith("http")) {
  143. window.open(nextURL);
  144. } else {
  145. this.$router.push(nextURL);
  146. }
  147. })
  148. .catch(action => {
  149. });
  150. }
  151. },
  152. },
  153. };
  154. </script>
  155. <style scoped>
  156. .coder {
  157. border-radius: 8px;
  158. height: calc(100% - 14px);
  159. position: relative;
  160. border: 1px solid #cccccc;
  161. }
  162. .coder:hover {
  163. cursor: pointer;
  164. border: 1px solid #aaaaaa;
  165. }
  166. .name {
  167. font-weight: bold;
  168. font-size: medium;
  169. }
  170. .status {
  171. text-align: right;
  172. }
  173. .teacher {
  174. font-size: 10px;
  175. margin-top: 10px;
  176. color: #999999;
  177. }
  178. .course {
  179. font-size: 10px;
  180. margin-top: 4px;
  181. color: #999999;
  182. }
  183. .time {
  184. margin-top: 4px;
  185. font-size: 10px;
  186. margin-bottom: 16px;
  187. color: #999999;
  188. }
  189. /*.button {*/
  190. /* margin-top: 12px;*/
  191. /* text-align: center;*/
  192. /*}*/
  193. </style>