taskProgress.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <a-modal
  3. v-model:visible="visible"
  4. :width="500"
  5. title-align="start"
  6. top="10vh"
  7. :align-center="false"
  8. :mask-closable="false"
  9. :esc-to-close="false"
  10. @before-open="modalBeforeOpen"
  11. >
  12. <template #title> 任务进度 </template>
  13. <a-descriptions
  14. :data="taskInfo"
  15. title="任务详情"
  16. layout="inline-horizontal"
  17. :align="{ label: 'right' }"
  18. />
  19. <a-descriptions title="进度">
  20. <a-descriptions-item label="">
  21. <a-progress :percent="progressNum" :stroke-width="10" />
  22. </a-descriptions-item>
  23. </a-descriptions>
  24. <template #footer>
  25. <a-button @click="close">取消</a-button>
  26. </template>
  27. </a-modal>
  28. </template>
  29. <script setup lang="ts">
  30. import { ref } from 'vue';
  31. import { DescData, Message } from '@arco-design/web-vue';
  32. import useModal from '@/hooks/modal';
  33. import useTimeout from '@/hooks/timout';
  34. import { PICTURE_TYPE, PictureTypeEnum } from '@/constants/enumerate';
  35. import { useUserStore } from '@/store';
  36. import { TrackTaskData } from '../../../../electron/db/models/trackTask';
  37. defineOptions({
  38. name: 'ModifySet',
  39. });
  40. /* modal */
  41. const { visible, open, close } = useModal();
  42. defineExpose({ open, close });
  43. const { addSetTimeout, clearSetTimeout } = useTimeout();
  44. const userStore = useUserStore();
  45. const PROGRESS_KEY = 'progress';
  46. const taskInfo = ref<DescData[]>([]);
  47. const task = ref<TrackTaskData>({} as TrackTaskData);
  48. const total = ref(0);
  49. const finishCount = ref(0);
  50. const progressNum = ref(0);
  51. async function updateProgress() {
  52. clearSetTimeout(PROGRESS_KEY);
  53. finishCount.value = await window.db.getTrackTaskDetailCount({
  54. trackTaskId: task.value?.id as number,
  55. status: 'FINISH',
  56. });
  57. progressNum.value = !total.value
  58. ? 0
  59. : Math.floor((10000 * finishCount.value) / total.value) / 10000;
  60. if (finishCount.value === total.value) {
  61. await window.db.updateTrackTaskStatus({
  62. id: task.value.id,
  63. status: 'FINISH',
  64. });
  65. window.electron.stopWinProcess();
  66. return;
  67. }
  68. addSetTimeout(PROGRESS_KEY, updateProgress, 1 * 1000);
  69. }
  70. function getExportUrl() {
  71. const page = '#/track-task-export';
  72. const user = window.btoa(JSON.stringify(userStore.userInfo));
  73. return `${page}?user=${user}`;
  74. }
  75. /* init modal */
  76. async function modalBeforeOpen() {
  77. const res = await window.db.getUnfinishTrackTask(
  78. userStore.curSchoolInfo.id
  79. );
  80. if (!res) {
  81. Message.warning('没有未完成任务');
  82. close();
  83. return;
  84. }
  85. task.value = res;
  86. taskInfo.value = [
  87. {
  88. value: res.semesterName,
  89. label: '学期',
  90. },
  91. {
  92. value: res.examName,
  93. label: '考试',
  94. },
  95. ];
  96. if (res.courseId) {
  97. taskInfo.value.push({
  98. value: `${res.courseName}(${res.courseCode})`,
  99. label: '科目',
  100. });
  101. }
  102. if (res.paperNumber) {
  103. taskInfo.value.push({
  104. value: res.paperNumber,
  105. label: '试卷编码',
  106. });
  107. }
  108. taskInfo.value.push(
  109. ...[
  110. {
  111. value: (res.pictureType.split(',') as PictureTypeEnum[])
  112. .map((k) => PICTURE_TYPE[k])
  113. .join(','),
  114. label: '下载文件',
  115. },
  116. {
  117. value: res.outputDir,
  118. label: '保存目录',
  119. },
  120. ]
  121. );
  122. total.value = await window.db.getTrackTaskDetailCount({
  123. trackTaskId: res.id,
  124. });
  125. updateProgress();
  126. window.electron.startWinProcess(2, getExportUrl());
  127. }
  128. </script>