OnlinePracticeHome.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <main-layout>
  3. <Breadcrumb
  4. style="
  5. text-align: left;
  6. padding-left: 20px;
  7. height: 40px;
  8. line-height: 40px;
  9. background-color: #fafafa;
  10. "
  11. >
  12. 当前所在位置:
  13. <BreadcrumbItem>{{ locationTitle }}</BreadcrumbItem>
  14. </Breadcrumb>
  15. <div class="home">
  16. <div style="text-align: left; margin-bottom: 20px;">
  17. 选择考试批次:
  18. <Select
  19. v-model="examId"
  20. style="width: 200px;"
  21. filterable
  22. @on-change="fetchList"
  23. >
  24. <Option
  25. v-for="item in examList"
  26. :key="item.id"
  27. :value="item.id"
  28. :label="item.name"
  29. >
  30. </Option>
  31. </Select>
  32. </div>
  33. <OnlinePracticeList
  34. :courses="courses"
  35. :exam-list="examList"
  36. ></OnlinePracticeList>
  37. </div>
  38. </main-layout>
  39. </template>
  40. <script>
  41. import OnlinePracticeList from "./OnlinePracticeList.vue";
  42. import { mapState as globalMapState } from "vuex";
  43. export default {
  44. name: "OnlinePracticeHome",
  45. components: {
  46. OnlinePracticeList,
  47. },
  48. data() {
  49. return {
  50. examId: null,
  51. examList: [],
  52. courses: [],
  53. };
  54. },
  55. computed: {
  56. ...globalMapState(["user", "menus"]),
  57. locationTitle() {
  58. return (
  59. this.menus.find(
  60. (v) => v.link.toUpperCase() === this.$route.path.toUpperCase()
  61. ) || {}
  62. ).name;
  63. },
  64. },
  65. async mounted() {
  66. window._hmt.push(["_trackEvent", "在线练习列表页面", "进入页面"]);
  67. this.logger({ page: "在线练习列表页面", action: "进入页面" });
  68. if (this.$route.query.examId) {
  69. this.examId = this.$route.query.examId - 0;
  70. try {
  71. await this.fetchList(this.examId);
  72. } catch (error) {
  73. return;
  74. }
  75. }
  76. try {
  77. const res = await this.$http.get(
  78. "/api/ecs_exam_work/exam/queryByNameLike?name=&examTypes=PRACTICE&studentId=" +
  79. this.user.id
  80. );
  81. this.examList = (res.data || []).filter((e) => e.enable);
  82. if (this.$route.query.examId === undefined && this.examList[0]) {
  83. const examId = this.examList[0].id;
  84. // this.$router.replace({ query: { examId } });
  85. this.examId = examId;
  86. try {
  87. await this.fetchList(this.examId);
  88. } catch (error) {
  89. return;
  90. }
  91. }
  92. } catch (error) {
  93. this.$Message.error({
  94. content: "查询练习列表失败!",
  95. duration: 15,
  96. closable: true,
  97. });
  98. }
  99. },
  100. methods: {
  101. async fetchList(examId) {
  102. this.$router.replace({ query: { examId } });
  103. try {
  104. const res = await this.$http.get(
  105. "/api/branch_ecs_oe_admin/practice/queryPracticeCourseList?examId=" +
  106. examId
  107. );
  108. this.courses = res.data;
  109. } catch (error) {
  110. this.$Message.error({
  111. content: "获取课程列表失败",
  112. duration: 15,
  113. closable: true,
  114. });
  115. }
  116. },
  117. },
  118. };
  119. </script>
  120. <style scoped>
  121. .home {
  122. margin: 20px;
  123. }
  124. </style>