Bläddra i källkod

feat: 下载设置以及图片保存规则调整

zhangjie 1 år sedan
förälder
incheckning
4ad30fc16e

+ 4 - 11
electron/db/models/trackTask.ts

@@ -34,9 +34,7 @@ class TrackTask extends Model<
 
   declare paperNumber: string | null;
 
-  declare pictureType: string;
-
-  declare outputDir: string;
+  declare trackConfig: string;
 
   declare status: number;
 
@@ -90,15 +88,10 @@ TrackTask.init(
       type: DataTypes.STRING,
       allowNull: true,
     },
-    pictureType: {
-      type: DataTypes.STRING,
-      allowNull: false,
-      comment: '图片类型',
-    },
-    outputDir: {
-      type: DataTypes.STRING,
+    trackConfig: {
+      type: DataTypes.TEXT,
       allowNull: false,
-      comment: '保存目录',
+      comment: '导出设置',
     },
     status: {
       type: DataTypes.INTEGER,

+ 8 - 0
electron/db/models/trackTaskDetail.ts

@@ -25,6 +25,8 @@ class TrackTaskDetail extends Model<
 
   declare studentCode: string;
 
+  declare className: string;
+
   declare status: number;
 
   declare error: string | null;
@@ -57,6 +59,10 @@ TrackTaskDetail.init(
       type: DataTypes.STRING,
       allowNull: false,
     },
+    className: {
+      type: DataTypes.STRING,
+      allowNull: false,
+    },
     status: {
       type: DataTypes.INTEGER,
       allowNull: false,
@@ -86,4 +92,6 @@ export type TrackTaskDetailCreationAttributes = InferCreationAttributes<
   { omit: 'id' | 'createdAt' | 'updatedAt' | 'error' }
 >;
 
+export type TrackTaskDetailData = InferAttributes<TrackTaskDetail>;
+
 export default TrackTaskDetail;

+ 1 - 1
package.json

@@ -1,7 +1,7 @@
 {
   "name": "teachcloud-mark-tool",
   "description": "teachcloud mark tool",
-  "version": "1.0.0",
+  "version": "1.0.1",
   "main": "./out/main/index.js",
   "author": "chulinice",
   "license": "MIT",

+ 1 - 0
src/api/types/task.ts

@@ -209,5 +209,6 @@ export interface TrackExportDetailItem {
   studentName: string;
   studentCode: string;
   sheetUrls: string[] | null;
+  className: string;
 }
 export type TrackExportDetailListPageRes = PageResult<TrackExportDetailItem>;

+ 11 - 8
src/constants/enumerate.ts

@@ -8,13 +8,6 @@ export const ABLE_TYPE = {
 };
 
 // 基础 -------------->
-// 导出文件类型
-export const EXT_TYPE = {
-  img: '图片',
-  pdf: 'PDF',
-};
-export type ExtTypeEnum = keyof typeof EXT_TYPE;
-
 // 导出文件类型
 export const PICTURE_TYPE = {
   track: '轨迹图',
@@ -24,4 +17,14 @@ export const PICTURE_TYPE = {
 
 export type PictureTypeEnum = keyof typeof PICTURE_TYPE;
 
-export const IMAGE_SAVE_RULE = 'semester/exam/course/paperNumber';
+export const TRACK_COLOR_TYPE = {
+  DEFAULT: '默认颜色',
+  ALL_RED: '全部红色轨迹',
+};
+export type TrackColorTypeEnum = keyof typeof TRACK_COLOR_TYPE;
+
+export const STUDENT_FILE_RULE = {
+  CODE: '学号',
+  CODE_NAME: '学号-姓名',
+};
+export type StudentFileRuleEnum = keyof typeof STUDENT_FILE_RULE;

+ 2 - 0
src/store/modules/app/index.ts

@@ -11,6 +11,8 @@ const useAppStore = defineStore('app', {
       outputDir: '',
       curOutputDir: '',
       outputDirIsDefault: true,
+      trackColorType: 'DEFAULT',
+      studentFileRule: 'CODE',
     },
   }),
 

+ 7 - 1
src/store/modules/app/types.ts

@@ -1,10 +1,16 @@
-import { PictureTypeEnum } from '@/constants/enumerate';
+import {
+  PictureTypeEnum,
+  TrackColorTypeEnum,
+  StudentFileRuleEnum,
+} from '@/constants/enumerate';
 
 export interface TrackConfigType {
   pictureType: PictureTypeEnum[];
   outputDir: string;
   curOutputDir: string;
   outputDirIsDefault: boolean;
+  trackColorType: TrackColorTypeEnum;
+  studentFileRule: StudentFileRuleEnum;
 }
 
 export interface AppState {

+ 2 - 4
src/views/base/track-export/index.vue

@@ -229,8 +229,7 @@
       ...seNames,
       paperNumber: null,
       schoolId: userStore.curSchoolInfo.id,
-      pictureType: appStore.trackConfig.pictureType.join(),
-      outputDir: appStore.trackConfig.curOutputDir,
+      trackConfig: JSON.stringify(appStore.trackConfig),
       status: 0,
       courseId: '',
     }).catch(() => {
@@ -282,8 +281,7 @@
       courseId: '',
       paperNumber: row.paperNumber,
       schoolId: userStore.curSchoolInfo.id,
-      pictureType: appStore.trackConfig.pictureType.join(),
-      outputDir: appStore.trackConfig.curOutputDir,
+      trackConfig: JSON.stringify(appStore.trackConfig),
       status: 0,
     }).catch(() => {
       result = false;

+ 30 - 2
src/views/base/track-export/modifySet.vue

@@ -3,7 +3,7 @@
     v-model:visible="visible"
     :width="560"
     title-align="start"
-    top="10vh"
+    top="10px"
     :align-center="false"
     :mask-closable="false"
     :esc-to-close="false"
@@ -37,6 +37,26 @@
           >设为默认下载路径</a-checkbox
         >
       </a-form-item>
+      <a-form-item field="trackColorType" label="轨迹颜色">
+        <a-radio-group v-model="formData.trackColorType">
+          <a-radio
+            v-for="(val, key) in TRACK_COLOR_TYPE"
+            :key="key"
+            :value="key"
+            >{{ val }}</a-radio
+          >
+        </a-radio-group>
+      </a-form-item>
+      <a-form-item field="studentFileRule" label="轨迹颜色">
+        <a-radio-group v-model="formData.studentFileRule">
+          <a-radio
+            v-for="(val, key) in STUDENT_FILE_RULE"
+            :key="key"
+            :value="key"
+            >{{ val }}</a-radio
+          >
+        </a-radio-group>
+      </a-form-item>
     </a-form>
 
     <template #footer>
@@ -59,7 +79,13 @@
   import useDictOption from '@/hooks/dict-option';
   import { useAppStore } from '@/store';
   import { TrackConfigType } from '@/store/modules/app/types';
-  import { PictureTypeEnum } from '@/constants/enumerate';
+  import {
+    PictureTypeEnum,
+    TRACK_COLOR_TYPE,
+    TrackColorTypeEnum,
+    STUDENT_FILE_RULE,
+    StudentFileRuleEnum,
+  } from '@/constants/enumerate';
 
   defineOptions({
     name: 'ModifySet',
@@ -83,6 +109,8 @@
     outputDir: '',
     curOutputDir: '',
     outputDirIsDefault: true,
+    trackColorType: 'DEFAULT' as TrackColorTypeEnum,
+    studentFileRule: 'CODE' as StudentFileRuleEnum,
   };
 
   const emit = defineEmits(['modified']);

+ 5 - 5
src/views/base/track-export/taskProgress.vue

@@ -45,8 +45,9 @@
   import { DescData, Message } from '@arco-design/web-vue';
   import useModal from '@/hooks/modal';
   import useTimeout from '@/hooks/timout';
-  import { PICTURE_TYPE, PictureTypeEnum } from '@/constants/enumerate';
+  import { PICTURE_TYPE } from '@/constants/enumerate';
   import { useUserStore } from '@/store';
+  import { TrackConfigType } from '@/store/modules/app/types';
 
   import { modalConfirm } from '../../../utils/arco';
   import { TrackTaskData } from '../../../../electron/db/models/trackTask';
@@ -115,6 +116,7 @@
     await window.db.releaseAllRunningTaskDetail(res.id);
 
     task.value = res;
+    const trackConfig = JSON.parse(res.trackConfig) as TrackConfigType;
     taskInfo.value = [
       {
         value: res.semesterName,
@@ -140,13 +142,11 @@
     taskInfo.value.push(
       ...[
         {
-          value: (res.pictureType.split(',') as PictureTypeEnum[])
-            .map((k) => PICTURE_TYPE[k])
-            .join(','),
+          value: trackConfig.pictureType.map((k) => PICTURE_TYPE[k]).join(','),
           label: '下载文件',
         },
         {
-          value: res.outputDir,
+          value: trackConfig.outputDir,
           label: '保存目录',
         },
       ]

+ 1 - 1
src/views/base/track-export/trackTaskExport.vue

@@ -46,7 +46,7 @@
     }
 
     let result = true;
-    await runTask(res.studentId).catch(() => {
+    await runTask().catch(() => {
       result = false;
     });
 

+ 40 - 18
src/views/base/track-export/useDraw.ts

@@ -8,11 +8,12 @@ import {
 import { Task, Track, SpecialTag, Question } from '@/api/types/task';
 import { TrackConfigType } from '@/store/modules/app/types';
 import { PictureTypeEnum, PICTURE_TYPE } from '@/constants/enumerate';
-import { calcSum, maxNum, strGbLen } from '@/utils/utils';
+import { calcSum, deepCopy, maxNum, strGbLen } from '@/utils/utils';
 import { useAppStore } from '@/store';
 
 import { DrawTrackItem } from '../../../../electron/preload/types';
 import { TrackTaskData } from '../../../../electron/db/models/trackTask';
+import { TrackTaskDetailData } from '../../../../electron/db/models/trackTaskDetail';
 
 type AnswerMap = Record<string, { answer: string; isRight: boolean }>;
 
@@ -107,10 +108,25 @@ export default function useDraw(winId: number) {
   let isOnlyOrigin = false;
   let hasPdf = false;
   let curStudentId = '';
+  const defaultColorConfig = {
+    track: ['red', 'blue', 'gray'],
+    head: 'green',
+  };
+  let colorConfig = { track: ['red', 'blue', 'gray'], head: 'green' };
   const task = ref({} as TrackTaskData);
+  const taskDetail = ref({} as TrackTaskDetailData);
   const trackConfig = ref({} as TrackConfigType);
   const appStore = useAppStore();
 
+  function updateColorConfig() {
+    if (trackConfig.value.trackColorType === 'ALL_RED') {
+      colorConfig.head = 'red';
+      colorConfig.track = ['red', 'red', 'red'];
+    } else {
+      colorConfig = deepCopy(defaultColorConfig);
+    }
+  }
+
   function addLog(content: string, type?: 'info' | 'error') {
     window.api.logger(`win:${curWinId} ${content}`, type);
   }
@@ -119,28 +135,27 @@ export default function useDraw(winId: number) {
     const res = await window.db.getUnfinishTrackTask(schoolId);
     if (!res) return Promise.reject(new Error('无任务'));
     task.value = res;
-    trackConfig.value = {
-      pictureType: res.pictureType.split(',') as PictureTypeEnum[],
-      outputDir: res.outputDir,
-      curOutputDir: res.outputDir,
-      outputDirIsDefault: false,
-    };
+    trackConfig.value = JSON.parse(res.trackConfig) as TrackConfigType;
     isOnlyOrigin = checkOnlyOrigin();
     hasPdf = trackConfig.value.pictureType.includes('pdf');
+    updateColorConfig();
     return res.id;
   }
 
-  function getTrackTaskDetail() {
-    return window.db.getUnfinishTrackTaskDetail(task.value.id);
+  async function getTrackTaskDetail() {
+    const res = await window.db.getUnfinishTrackTaskDetail(task.value.id);
+    if (!res) return null;
+    taskDetail.value = res;
+    return taskDetail.value;
   }
 
-  async function runTask(studentId: string) {
+  async function runTask() {
     initData();
-    curStudentId = studentId;
+    curStudentId = taskDetail.value.studentId;
     addLog(`[${curStudentId}] 01-开始任务`);
 
     try {
-      await getTaskData(studentId);
+      await getTaskData(curStudentId);
       addLog(`[${curStudentId}] 02-获取任务数据成功`);
 
       originImgs = await downloadImages(rawTask.sheetUrls);
@@ -193,7 +208,6 @@ export default function useDraw(winId: number) {
     rawTask = await getSingleStudentTaskOfStudentTrack(studentId);
     if (!rawTask) return;
 
-    // rawTask.sheetUrls = ["/1-1.jpg", "/1-2.jpg"];
     if (!rawTask.sheetUrls) rawTask.sheetUrls = [];
 
     if (isOnlyOrigin) return;
@@ -216,8 +230,15 @@ export default function useDraw(winId: number) {
     cardData = cardContent.pages;
   }
 
+  /**
+   * 获取文件存储路径,规则:学期/考试/课程/试卷编号/教学班/下载文件类型/学生图片
+   */
   function getOutputPath(type: PictureTypeEnum, index?: number) {
-    let filename = rawTask.studentCode;
+    let filename =
+      trackConfig.value.studentFileRule === 'CODE_NAME'
+        ? `${rawTask.studentCode}-${rawTask.studentName}`
+        : rawTask.studentCode;
+
     if (index !== undefined) {
       filename += `-${index}`;
     }
@@ -228,6 +249,7 @@ export default function useDraw(winId: number) {
       task.value.examName,
       `${rawTask.courseName}(${rawTask.courseCode})`,
       rawTask.paperNumber,
+      taskDetail.value.className,
       PICTURE_TYPE[type],
       filename,
     ];
@@ -379,7 +401,7 @@ export default function useDraw(winId: number) {
 
   function addHeaderTrackColorAttr(headerTrack: Track[]): Track[] {
     return headerTrack.map((item) => {
-      item.color = 'green';
+      item.color = colorConfig.head;
       return item;
     });
   }
@@ -392,11 +414,11 @@ export default function useDraw(winId: number) {
     for (let i = 0; i < markerIds.length; i++) {
       const mId = markerIds[i];
       if (i === 0) {
-        colorMap[mId] = 'red';
+        colorMap[mId] = colorConfig.track[0];
       } else if (i === 1) {
-        colorMap[mId] = 'blue';
+        colorMap[mId] = colorConfig.track[1];
       } else if (i > 1) {
-        colorMap[mId] = 'gray';
+        colorMap[mId] = colorConfig.track[2];
       }
     }
     type ColorK = keyof typeof colorMap;

+ 1 - 0
src/views/base/track-export/useTask.ts

@@ -100,6 +100,7 @@ export default function useTask() {
           studentId: item.studentId,
           studentName: item.studentName,
           studentCode: item.studentCode,
+          className: item.className,
           status: TRACK_TASK_DETAIL_STATUS.INIT,
         };
       });