| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <template>
- <el-card class="coder" shadow="hover" @click="toTestInfo">
- <div
- style="border-bottom: 30px solid #8dc9e2; float: right; width: 0; height: 0; position: absolute;right: 0;bottom: 0;border-left: 30px solid transparent;">
- <div style="padding: 0 3px 0 3px; position: absolute; right: 0; bottom: -30px; color: white">
- C
- </div>
- </div>
- <el-row>
- <el-col :span="16" class="name">
- {{ coderVO.name }}
- </el-col>
- <el-col :span="8" class="status">
- <el-tag v-if="state==='NOT_STARTED'" size="small" type="info">未开始</el-tag>
- <el-tag v-else-if="state==='RUNNING'" size="small">进行中</el-tag>
- <el-tag v-else-if="state==='CLOSED'" size="small" type="info">已关闭</el-tag>
- <el-tag v-else-if="state==='FINISHED'" size="small" type="danger">已结束</el-tag>
- </el-col>
- </el-row>
- <el-row class="teacher">
- 教师: {{ teacher.name }}
- </el-row>
- <el-row class="course">
- 所属课程: {{ coderVO.course }}
- </el-row>
- <el-row class="time">
- 时间: {{ timestampToTime(coderVO.startAt) }} 至 {{ timestampToTime(coderVO.endAt) }}
- </el-row>
- <!-- <el-row class="button">-->
- <!-- <el-col :span="24">-->
- <!-- <el-button v-if="state==='FINISHED'" size="small" type="success" plain>结果报告</el-button>-->
- <!-- <el-button v-else size="small" type="primary" plain>查看详情</el-button>-->
- <!-- </el-col>-->
- <!-- </el-row>-->
- </el-card>
- </template>
- <script>
- import {ElMessageBox, ElMessage} from "element-plus";
- export default {
- name: "CoderCard",
- props: {
- coderVO: {
- type: Object,
- default: () => {
- },
- }
- },
- data() {
- return {
- teacher: {
- type: Object,
- default: {
- name: "暂无信息",
- },
- },
- };
- },
- computed: {
- state: function () {
- if (this.coderVO.status === "CLOSED") {
- return "CLOSED";
- } else if (this.coderVO.startAt * 1000 > new Date()) {
- return "NOT_STARTED";
- } else if (this.coderVO.endAt * 1000 < new Date()) {
- return "FINISHED";
- } else {
- return "RUNNING";
- }
- },
- isTeacher() {
- return this.$store.state.user.role === "TEACHER";
- }
- },
- async mounted() {
- const res = await this.$apis.getUserAPI(this.coderVO.creator.id);
- if (res.data.code === 0) {
- this.teacher = res.data.data;
- } else {
- this.teacher = {name: this.coderVO.creator.username};
- }
- },
- methods: {
- timestampToTime(timestamp) {
- const date = new Date(timestamp * 1000);
- const Y = date.getFullYear() + "-";
- const M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-";
- const D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());
- return Y + M + D;
- },
- async toTestInfo() {
- if (!this.$store.state.user.token) {
- await this.$router.push("/auth");
- return;
- }
- let messageBoxContent = "";
- let messageBoxTitle = "Coder";
- let confirmButtonText = "";
- let cancelButtonText = "让我想想";
- let nextURL = "";
- if (this.isTeacher) {
- if (this.$store.state.user.id === this.coderVO.id) {
- nextURL = "https://coder.seec.seecoder.cn/exam/" + this.coderVO.id + "?id_token=" + this.$store.state.user.token;
- window.open(nextURL);
- } else {
- ElMessage.error("无权访问其他教师创建的测试");
- }
- } else {
- // todo: 跳转流程中还需要考虑CoderExam的状态
- const res = await this.$apis.getStudentCoderExams({});
- const userCoderExams = res.data.data.res;
- for (let userCoderExam of userCoderExams) {
- if (this.coderVO.id === userCoderExam.id) {
- if (userCoderExam.joined) {
- nextURL = "https://coder.seec.seecoder.cn/exam/" + this.coderVO.id + "?id_token=" + this.$store.state.user.token;
- window.open(nextURL);
- return;
- } else {
- messageBoxContent = "尚未参加该测试,是否立即参加?";
- confirmButtonText = "立即参加";
- nextURL = "https://coder.seec.seecoder.cn/exam?id_token=" + this.$store.state.user.token;
- }
- }
- }
- if (messageBoxContent === "") {
- const res = await this.$apis.getCourseByCoderId(this.coderVO.courseId);
- if (res.data.data === null) {
- nextURL = "https://coder.seec.seecoder.cn/course/select?id_token=" + this.$store.state.user.token;
- messageBoxContent = "尚未选择该Coder课程,是否前往Coder系统?";
- confirmButtonText = "前往选课";
- } else {
- nextURL = "/course/" + res.data.data.id;
- messageBoxContent = "尚未选择该课程,是否前往选课?";
- confirmButtonText = "前往选课";
- }
- }
- ElMessageBox.confirm(messageBoxContent, messageBoxTitle, {
- distinguishCancelAndClose: true,
- confirmButtonText,
- cancelButtonText,
- })
- .then(() => {
- if (nextURL.startsWith("http")) {
- window.open(nextURL);
- } else {
- this.$router.push(nextURL);
- }
- })
- .catch(action => {
- });
- }
- },
- },
- };
- </script>
- <style scoped>
- .coder {
- border-radius: 8px;
- height: calc(100% - 14px);
- position: relative;
- border: 1px solid #cccccc;
- }
- .coder:hover {
- cursor: pointer;
- border: 1px solid #aaaaaa;
- }
- .name {
- font-weight: bold;
- font-size: medium;
- }
- .status {
- text-align: right;
- }
- .teacher {
- font-size: 10px;
- margin-top: 10px;
- color: #999999;
- }
- .course {
- font-size: 10px;
- margin-top: 4px;
- color: #999999;
- }
- .time {
- margin-top: 4px;
- font-size: 10px;
- margin-bottom: 16px;
- color: #999999;
- }
- /*.button {*/
- /* margin-top: 12px;*/
- /* text-align: center;*/
- /*}*/
- </style>
|