TestCard.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <el-card class="test" shadow="hover" @click="toTestInfo">
  3. <div :style="{borderBottom: type==='eval' ? '30px solid #f5b86e' : '30px solid #8dc9e2'}"
  4. style="float: right; width: 0; height: 0; position: absolute;right: 0;bottom: 0;border-left: 30px solid transparent;">
  5. <div v-if="type==='eval'" style="padding: 0 4px 0 4px; position: absolute; right: 0; bottom: -30px; color: white">
  6. E
  7. </div>
  8. <div v-else style="padding: 0 3px 0 3px; position: absolute; right: 0; bottom: -30px; color: white">
  9. C
  10. </div>
  11. </div>
  12. <el-row>
  13. <el-col :span="16">
  14. <el-col class="title">
  15. {{ title }}
  16. </el-col>
  17. </el-col>
  18. <el-col :span="8" class="status">
  19. <el-tag v-if="state==='NOT_STARTED'" size="small" type="info">未开始</el-tag>
  20. <el-tag v-else-if="state==='RUNNING_IN' && !isPublicTest" size="small" type="success">已参加</el-tag>
  21. <el-tag v-else-if="state==='RUNNING_NOT' && !isPublicTest" size="small">未参加</el-tag>
  22. <el-tag v-else-if="isPublicTest" size="small">开放中</el-tag>
  23. <el-tag v-else-if="state==='FINISHED'" size="small" type="danger">已结束</el-tag>
  24. <el-tag v-else-if="state==='CLOSED'" size="small" type="info">已关闭</el-tag>
  25. </el-col>
  26. </el-row>
  27. <el-row class="course" v-if="course!==''">
  28. {{ course }}
  29. </el-row>
  30. <el-row class="teacher">
  31. {{ teacherName }}
  32. </el-row>
  33. <el-row class="time">
  34. {{ timePeriod }}
  35. </el-row>
  36. <el-row v-if="type==='eval'" class="comment">
  37. {{ testVO.comment }}
  38. </el-row>
  39. </el-card>
  40. </template>
  41. <script>
  42. import {ElMessage, ElMessageBox} from "element-plus";
  43. import store from "@/store";
  44. export default {
  45. name: "TestCard",
  46. props: {
  47. testVO: Object,
  48. isPublicTest: {
  49. type: Boolean,
  50. default: false,
  51. },
  52. },
  53. data() {
  54. return {
  55. teacher: Object,
  56. };
  57. },
  58. computed: {
  59. isLogin() {
  60. return store.state.user.token;
  61. },
  62. isCreator() {
  63. if (this.testVO.examId) {
  64. return Number(this.testVO.course.teacherId) === Number(this.$store.state.user.id);
  65. }else{
  66. return this.testVO.creator.username === this.$store.state.user.phone;
  67. }
  68. },
  69. isTeacher() {
  70. return this.$store.getters.isTeacher;
  71. },
  72. isStudent() {
  73. return this.$store.getters.isStudent;
  74. },
  75. type() {
  76. if (this.testVO.examId) {
  77. return "eval";
  78. } else {
  79. return "coder";
  80. }
  81. },
  82. title() {
  83. if (this.type === "eval") {
  84. return this.testVO.examName;
  85. } else {
  86. return this.testVO.name;
  87. }
  88. },
  89. course() {
  90. if (this.type === "eval") {
  91. return "";
  92. } else {
  93. return "所属课程: " + this.testVO.course;
  94. }
  95. },
  96. teacherName() {
  97. if (this.type === "eval") {
  98. return "教师: " + this.teacher.name;
  99. } else {
  100. return "教师: " + this.teacher;
  101. }
  102. },
  103. timePeriod() {
  104. if (this.type === "eval") {
  105. return "时间: " + this.testVO.startTime.substring(0, 16) + "至" + this.testVO.endTime.substring(0, 16);
  106. } else {
  107. return "时间: " + this.timestampToTime(this.testVO.startAt) + "至" + this.timestampToTime(this.testVO.endAt);
  108. }
  109. },
  110. state() {
  111. const now = new Date();
  112. if (this.type === "eval") {
  113. if (new Date(this.testVO.endTime) < now) {
  114. return "FINISHED";
  115. } else if (new Date(this.testVO.startTime) > now) {
  116. return "NOT_STARTED";
  117. } else if (this.testVO.isJoined) {
  118. return "RUNNING_IN";
  119. } else {
  120. return "RUNNING_NOT";
  121. }
  122. } else {
  123. if (this.testVO.status === "CLOSED") {
  124. return "CLOSED";
  125. } else if (this.testVO.startAt * 1000 > now) {
  126. return "NOT_STARTED";
  127. } else if (this.testVO.endAt * 1000 < now) {
  128. return "FINISHED";
  129. } else if (this.testVO.joined) {
  130. return "RUNNING_IN";
  131. } else {
  132. return "RUNNING_NOT";
  133. }
  134. }
  135. },
  136. },
  137. async created() {
  138. if (this.type === "eval") {
  139. this.teacher = (await this.$apis.getUserAPI(this.testVO.course["teacherId"])).data.data;
  140. } else {
  141. this.teacher = (await this.$apis.getNameByUsernameAPI(this.testVO.creator.username)).data.data;
  142. }
  143. },
  144. methods: {
  145. timestampToTime(timestamp) {
  146. const date = new Date(timestamp * 1000);
  147. const Y = date.getFullYear() + "-";
  148. const M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-";
  149. const D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
  150. const h = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
  151. const m = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes());
  152. return Y + M + D + h + m;
  153. },
  154. // TODO 分情况处理跳转
  155. async toTestInfo() {
  156. if (!this.isLogin) {
  157. ElMessage({
  158. showClose: true,
  159. message: "请先登录",
  160. type: "warning",
  161. duration: 1000,
  162. });
  163. await this.$router.push({name: "Auth", params: {login_to: "/portal"}});
  164. return;
  165. }
  166. console.log(this.testVO);
  167. if (this.isCreator) {
  168. if (this.type === "eval") {
  169. this.$router.push(`/exam/${this.testVO.examId}`);
  170. // window.open("https://eval.seec.seecoder.cn/teacher/exam/" + this.testVO.examId + "/details?id_token" + this.$store.state.user.token);
  171. } else {
  172. this.$router.push(`/exam/${this.testVO.id}`); //跳转到考试详情页
  173. // window.open("https://coder.seec.seecoder.cn/exam/" + this.testVO.id + "?id_token=" + this.$store.state.user.token);
  174. }
  175. } else if (this.isTeacher) {
  176. this.$message.error("无权访问其他教师创建的课程");
  177. } else {
  178. let messageBoxContent = "";
  179. let messageBoxTitle = "";
  180. let confirmButtonText = "";
  181. let cancelButtonText = "让我想想";
  182. let nextURL = "";
  183. if (this.type === "eval") {
  184. messageBoxTitle = "Eval";
  185. if (this.testVO.isJoined) {
  186. nextURL = "https://eval.seec.seecoder.cn/exam/" + this.testVO.id + "/before-exam/?id_token=" + this.$store.state.user.token;
  187. window.open(nextURL);
  188. return;
  189. } else {
  190. const courseId = (await this.$apis.getCourseByEvalId(this.testVO.course.id)).data.data;
  191. if (courseId) {
  192. const isCourseSelected = (await this.$apis.checkCourseSelection(courseId, this.$store.state.user.id)).data.data;
  193. if (isCourseSelected) {
  194. messageBoxContent = "是否立即查看测试详情";
  195. confirmButtonText = "立即查看";
  196. nextURL = "https://eval.seec.seecoder.cn/student/home/?id_token=" + this.$store.state.user.token;
  197. } else {
  198. messageBoxContent = "尚未参加课程,是否立即参加?";
  199. confirmButtonText = "立即选课";
  200. nextURL = "/course/" + courseId;
  201. }
  202. } else {
  203. messageBoxContent = "是否立即查看测试详情";
  204. confirmButtonText = "立即查看";
  205. nextURL = "https://eval.seec.seecoder.cn/student/home/?id_token=" + this.$store.state.user.token;
  206. }
  207. }
  208. } else {
  209. messageBoxTitle = "Coder";
  210. if (this.testVO.joined) {
  211. nextURL = "https://coder.seec.seecoder.cn/exam/" + this.testVO.id + "?id_token=" + this.$store.state.user.token;
  212. window.open(nextURL);
  213. return;
  214. } else {
  215. const courseId = (await this.$apis.getCourseByCoderId(this.testVO.courseId)).data.data;
  216. if (courseId) {
  217. const isCourseSelected = (await this.$apis.checkCourseSelection(courseId, this.$store.state.user.id)).data.data;
  218. if (isCourseSelected) {
  219. messageBoxContent = "是否立即查看测试详情";
  220. confirmButtonText = "立即查看";
  221. nextURL = "https://coder.seec.seecoder.cn/exam?id_token=" + this.$store.state.user.token;
  222. } else {
  223. messageBoxContent = "尚未选择课程,是否立即参加?";
  224. confirmButtonText = "立即选课";
  225. nextURL = "/course/" + courseId;
  226. }
  227. } else {
  228. messageBoxContent = "是否立即查看测试详情";
  229. confirmButtonText = "立即查看";
  230. nextURL = "https://coder.seec.seecoder.cn/exam?id_token=" + this.$store.state.user.token;
  231. }
  232. }
  233. }
  234. ElMessageBox.confirm(messageBoxContent, messageBoxTitle, {
  235. distinguishCancelAndClose: true,
  236. confirmButtonText,
  237. cancelButtonText,
  238. }).then(() => {
  239. if (nextURL.startsWith("http")) {
  240. window.open(nextURL);
  241. } else {
  242. this.$router.push(nextURL);
  243. }
  244. });
  245. }
  246. },
  247. }
  248. };
  249. </script>
  250. <style scoped>
  251. .test {
  252. min-height: 180px;
  253. border-radius: 8px;
  254. height: calc(100% - 14px);
  255. position: relative;
  256. border: 1px solid #cccccc;
  257. }
  258. .test:hover {
  259. cursor: pointer;
  260. border: 1px solid #aaaaaa;
  261. }
  262. .title {
  263. font-weight: bold;
  264. font-size: medium;
  265. }
  266. .status {
  267. text-align: right;
  268. }
  269. .course {
  270. font-size: 10px;
  271. margin-top: 4px;
  272. color: #999999;
  273. }
  274. .teacher {
  275. font-size: 10px;
  276. margin-top: 10px;
  277. color: #999999;
  278. }
  279. .time {
  280. margin-top: 4px;
  281. font-size: 10px;
  282. margin-bottom: 16px;
  283. color: #999999;
  284. }
  285. .comment {
  286. background-color: #f6f6f6;
  287. color: #777777;
  288. margin-top: 10px;
  289. border-radius: 8px;
  290. padding: 10px;
  291. font-size: 10px;
  292. margin-bottom: 16px;
  293. }
  294. </style>