OfflineExamList.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <div class="list">
  3. <table>
  4. <tbody class="list-row">
  5. <tr class="list-header qm-primary-strong-text">
  6. <td>课程</td>
  7. <td>专业</td>
  8. <td>考试开放时间</td>
  9. <td>状态</td>
  10. <td style="max-width: 200px;">操作</td>
  11. </tr>
  12. <tr v-for="(course, courseIndex) in courses" :key="courseIndex">
  13. <td>{{ course.courseName }}</td>
  14. <td>{{ course.specialtyName }}</td>
  15. <td>
  16. {{ course.startTime }} <br />
  17. ~ <br />
  18. {{ course.endTime }}
  19. </td>
  20. <td>
  21. <div v-if="course.offlineFiles">
  22. <div v-for="(file, index) in course.offlineFiles" :key="index">
  23. <a
  24. :href="file.offlineFileUrl"
  25. download
  26. :title="file.originalFileName"
  27. ondragstart="return false;"
  28. @click="
  29. () =>
  30. downloadOfflineFile(
  31. file.offlineFileUrl,
  32. file.originalFileName
  33. )
  34. "
  35. >
  36. <i-icon type="ios-cloud-download"></i-icon>下载作答
  37. </a>
  38. </div>
  39. </div>
  40. <div v-else>未上传</div>
  41. </td>
  42. <td style="min-width: 180px;">
  43. <template v-if="!course.isvalid">
  44. <div v-if="course.paperId" style="display: grid; grid-gap: 10px;">
  45. <i-button
  46. class="qm-primary-button"
  47. @click="previewPaper(course)"
  48. >
  49. 查看试卷
  50. </i-button>
  51. <a
  52. v-show="!downloadingCourse(course)"
  53. class="qm-primary-button"
  54. href="#"
  55. download
  56. ondragstart="return false;"
  57. @click="() => tempDisableBtnAndDownloadPaper(course)"
  58. >
  59. 下载试卷
  60. </a>
  61. <i-button
  62. v-if="downloadingCourse(course)"
  63. class="qm-primary-button"
  64. >
  65. 下载中
  66. </i-button>
  67. <i-button
  68. class="qm-primary-button"
  69. @click="uploadHandler(course)"
  70. >
  71. 上传答案
  72. </i-button>
  73. </div>
  74. <div v-else style="display: grid; grid-gap: 10px;">
  75. <div
  76. v-if="
  77. new Date(course.startTime) - Date.now() > timeDifference
  78. "
  79. >
  80. 未开始
  81. </div>
  82. <div
  83. v-else-if="
  84. new Date(course.endTime) - Date.now() < timeDifference
  85. "
  86. >
  87. 已结束
  88. </div>
  89. <div v-else>
  90. <i-button
  91. class="qm-primary-button"
  92. @click="enterExam(course)"
  93. >
  94. 抽取试卷
  95. </i-button>
  96. </div>
  97. </div>
  98. </template>
  99. </td>
  100. </tr>
  101. </tbody>
  102. </table>
  103. <ecs-offline-exam-modal
  104. v-if="selectedCourse"
  105. ref="uploadModal"
  106. :course="selectedCourse"
  107. @reloadList="$emit('reloadList')"
  108. ></ecs-offline-exam-modal>
  109. </div>
  110. </template>
  111. <script>
  112. import { mapState as globalMapState, mapGetters } from "vuex";
  113. import { TK_SERVER_HTML_URL } from "@/constants/constants.js";
  114. import OfflineExamModal from "./OfflineExamModal.vue";
  115. export default {
  116. name: "EcsOfflineList",
  117. components: {
  118. "ecs-offline-exam-modal": OfflineExamModal,
  119. },
  120. props: {
  121. courses: {
  122. type: Array,
  123. default() {
  124. return [];
  125. },
  126. },
  127. },
  128. data() {
  129. return {
  130. disableDownloadPaperBtn: false,
  131. downloadPaperIds: new Set(),
  132. selectedCourse: null,
  133. };
  134. },
  135. computed: {
  136. ...globalMapState(["user", "timeDifference"]),
  137. ...mapGetters(["isCug"]),
  138. // enableFeFeature() {
  139. // return !!!this.FE_FEATURE_IMAGE_PDF;
  140. // },
  141. },
  142. methods: {
  143. async enterExam(course) {
  144. // 若出错,直接报网络异常
  145. await this.$http.get("/api/ecs_oe_admin/offlineExam/startOfflineExam", {
  146. params: { examStudentId: course.examStudentId },
  147. });
  148. this.$emit("reloadList");
  149. },
  150. previewPaper(course) {
  151. window._hmt.push(["_trackEvent", "离线考试页面", "预览"]);
  152. var user = {
  153. loginName: course.examStudentId,
  154. backUrl: window.document.location.href,
  155. isOnlineExam: true,
  156. };
  157. window.name = JSON.stringify(user);
  158. window.location.href =
  159. TK_SERVER_HTML_URL +
  160. "/admin/preview_paper/" +
  161. course.paperId +
  162. "?isback=true";
  163. },
  164. async downloadOfflineFile(url, name) {
  165. window._hmt.push(["_trackEvent", "离线考试页面", "下载作答"]);
  166. function toDataURL(url) {
  167. return fetch(url)
  168. .then((response) => {
  169. return response.blob();
  170. })
  171. .then((blob) => {
  172. return URL.createObjectURL(blob);
  173. });
  174. }
  175. if ([".png", ".jpg", ".jpeg"].some((v) => name.endsWith(v))) {
  176. const a = document.createElement("a");
  177. a.href = await toDataURL(url);
  178. a.download = name;
  179. document.body.appendChild(a);
  180. a.click();
  181. document.body.removeChild(a);
  182. } else {
  183. window.location.href = url;
  184. }
  185. },
  186. tempDisableBtnAndDownloadPaper(course) {
  187. window._hmt.push(["_trackEvent", "离线考试页面", "下载试卷"]);
  188. this.downloadPaperIds.add(course.paperId);
  189. this.downloadPaperIds = new Set(this.downloadPaperIds);
  190. // this.$forceUpdate();
  191. // this.disableDownloadPaperBtn = true;
  192. setTimeout(() => {
  193. // this.disableDownloadPaperBtn = false;
  194. this.downloadPaperIds.delete(course.paperId);
  195. this.downloadPaperIds = new Set(this.downloadPaperIds);
  196. // set 并不能正常的reactive
  197. // this.$forceUpdate();
  198. }, 10 * 1000);
  199. window.location.href =
  200. "/api/ecs_ques/paper/export/" +
  201. course.paperId +
  202. "/PAPER/" +
  203. this.user.rootOrgId +
  204. "/" +
  205. course.paperId +
  206. "/offLine?$key=" +
  207. this.user.key +
  208. "&$token=" +
  209. this.user.token;
  210. },
  211. downloadingCourse(course) {
  212. return this.downloadPaperIds.has(course.paperId);
  213. },
  214. uploadHandler(course) {
  215. this.selectedCourse = course;
  216. // setTimeout(() => {
  217. // console.log(this.$refs);
  218. // }, 1000);
  219. this.$nextTick(() => {
  220. // console.log(this.$refs.uploadModal.$refs.uploadModal);
  221. this.$refs.uploadModal.$refs.uploadModal.visible = true;
  222. });
  223. },
  224. },
  225. };
  226. </script>
  227. <style scoped>
  228. .list {
  229. border: 1px solid #eeeeee;
  230. border-radius: 6px;
  231. }
  232. .list table {
  233. width: 100%;
  234. border-collapse: collapse !important;
  235. border-spacing: 0;
  236. }
  237. .list td {
  238. border: 1px solid #eeeeee;
  239. border-radius: 6px;
  240. border-collapse: separate !important;
  241. padding: 10px;
  242. }
  243. </style>