|
@@ -1,11 +1,16 @@
|
|
|
+import { ref } from 'vue';
|
|
|
+
|
|
|
import {
|
|
|
getSingleStudentTaskOfStudentTrack,
|
|
|
studentObjectiveConfirmData,
|
|
|
getSingleStudentCardData,
|
|
|
} from '@/api/task';
|
|
|
import { Task, Track, SpecialTag } from '@/api/types/task';
|
|
|
-import { calcSum, maxNum, randomCode, strGbLen } from '@/utils/utils';
|
|
|
+import { TrackConfigType } from '@/store/modules/app/types';
|
|
|
+import { PictureTypeEnum } from '@/constants/enumerate';
|
|
|
+import { calcSum, maxNum, strGbLen } from '@/utils/utils';
|
|
|
import { DrawTrackItem } from '../../../../electron/preload/types';
|
|
|
+import { TrackTaskData } from '../../../../electron/db/models/trackTask';
|
|
|
|
|
|
type AnswerMap = Record<string, { answer: string; isRight: boolean }>;
|
|
|
|
|
@@ -74,13 +79,45 @@ export default function useDraw() {
|
|
|
let recogDatas: string[] = [];
|
|
|
let rawTask = {} as Task;
|
|
|
let trackData = [] as TrackTtemType[];
|
|
|
+ let isOnlyOrigin = false;
|
|
|
+ let hasPdf = false;
|
|
|
+ const task = ref({} as TrackTaskData);
|
|
|
+ const trackConfig = ref({} as TrackConfigType);
|
|
|
+
|
|
|
+ async function getTrackTask(schoolId: string) {
|
|
|
+ const res = await window.db.getUnfinishTrackTask(schoolId);
|
|
|
+ if (!res) return;
|
|
|
+ task.value = res;
|
|
|
+ trackConfig.value = {
|
|
|
+ pictureType: res.pictureType.split(','),
|
|
|
+ outputDir: res.outputDir,
|
|
|
+ curOutputDir: res.outputDir,
|
|
|
+ outputDirIsDefault: false,
|
|
|
+ };
|
|
|
+ isOnlyOrigin = checkOnlyOrigin();
|
|
|
+ hasPdf = trackConfig.value.pictureType.includes('pdf');
|
|
|
+ }
|
|
|
+
|
|
|
+ function getTrackTaskDetail() {
|
|
|
+ return window.db.getUnfinishTrackTaskDetail(task.value.id);
|
|
|
+ }
|
|
|
|
|
|
async function runTask(studentId: string) {
|
|
|
initData();
|
|
|
+
|
|
|
try {
|
|
|
await getTaskData(studentId);
|
|
|
+ await downloadImages(rawTask.sheetUrls);
|
|
|
+ if (isOnlyOrigin) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
await parseDrawList();
|
|
|
- await drawTask();
|
|
|
+
|
|
|
+ const trackFiles = await drawTask();
|
|
|
+ if (hasPdf) {
|
|
|
+ await window.api.combinePdf(trackFiles, getOutputPath('pdf'));
|
|
|
+ }
|
|
|
} catch (error) {
|
|
|
console.log(error);
|
|
|
return Promise.reject(error);
|
|
@@ -96,6 +133,13 @@ export default function useDraw() {
|
|
|
answerMap = {} as AnswerMap;
|
|
|
}
|
|
|
|
|
|
+ function checkOnlyOrigin() {
|
|
|
+ return (
|
|
|
+ trackConfig.value.pictureType.length === 1 &&
|
|
|
+ trackConfig.value.pictureType[0] === 'track'
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
async function getTaskData(studentId: string) {
|
|
|
rawTask = await getSingleStudentTaskOfStudentTrack(studentId);
|
|
|
if (!rawTask) return;
|
|
@@ -103,6 +147,8 @@ export default function useDraw() {
|
|
|
// rawTask.sheetUrls = ["/1-1.jpg", "/1-2.jpg"];
|
|
|
if (!rawTask.sheetUrls) rawTask.sheetUrls = [];
|
|
|
|
|
|
+ if (isOnlyOrigin) return;
|
|
|
+
|
|
|
// 获取客观题选项信息
|
|
|
const objectiveData = await studentObjectiveConfirmData(studentId);
|
|
|
objectiveData.answers.forEach((item) => {
|
|
@@ -121,14 +167,29 @@ export default function useDraw() {
|
|
|
cardData = cardContent.pages;
|
|
|
}
|
|
|
|
|
|
+ function getOutputPath(type: PictureTypeEnum, index: number | undefined) {
|
|
|
+ let filename = rawTask.studentCode;
|
|
|
+ if (index !== undefined) {
|
|
|
+ filename += `-${index}`;
|
|
|
+ }
|
|
|
+ filename += type === 'pdf' ? '.pdf' : '.jpg';
|
|
|
+ const paths = [
|
|
|
+ trackConfig.value.curOutputDir,
|
|
|
+ task.value.semesterName,
|
|
|
+ task.value.examName,
|
|
|
+ `${rawTask.courseName}(${rawTask.courseCode})`,
|
|
|
+ rawTask.paperNumber,
|
|
|
+ type === 'pdf' ? '' : type,
|
|
|
+ filename,
|
|
|
+ ];
|
|
|
+ return window.api.joinPath(paths);
|
|
|
+ }
|
|
|
+
|
|
|
async function downloadImages(urls: string[]) {
|
|
|
const downloads: Promise<ImageItem>[] = [];
|
|
|
for (let i = 0; i < urls.length; i++) {
|
|
|
downloads.push(
|
|
|
- window.api.downloadImage(
|
|
|
- urls[i],
|
|
|
- `${rawTask.studentId}-${i}-${randomCode(8)}.jpg`
|
|
|
- )
|
|
|
+ window.api.downloadImage(urls[i], getOutputPath('origin', i + 1))
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -186,24 +247,18 @@ export default function useDraw() {
|
|
|
const tasks: Promise<string>[] = [];
|
|
|
for (let i = 0; i < trackData.length; i++) {
|
|
|
const item = trackData[i];
|
|
|
- const outpath = getOutputPath(i + 1);
|
|
|
+ const outpath = getOutputPath('track', i + 1);
|
|
|
tasks.push(window.api.drawTrack(item.url, item.drawTrackList, outpath));
|
|
|
}
|
|
|
const res = await Promise.all(tasks).catch((error) => {
|
|
|
console.log(error);
|
|
|
});
|
|
|
if (!res) {
|
|
|
- return Promise.reject(res);
|
|
|
+ return Promise.reject(new Error('绘制轨迹错误'));
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- function getOutputPath(ind: number) {
|
|
|
- // TODO:
|
|
|
- const no = `000${ind}`.slice(-3);
|
|
|
- return window.api.joinPath(['', `${no}.jpg`]);
|
|
|
- }
|
|
|
-
|
|
|
// track ----- start->
|
|
|
function getDrawTrackItem(track: Track): DrawTrackItem {
|
|
|
return {
|
|
@@ -501,5 +556,7 @@ export default function useDraw() {
|
|
|
|
|
|
return {
|
|
|
runTask,
|
|
|
+ getTrackTask,
|
|
|
+ getTrackTaskDetail,
|
|
|
};
|
|
|
}
|