浏览代码

feat: 新增系统配置

zhangjie 1 年之前
父节点
当前提交
4e9ce22c99
共有 4 个文件被更改,包括 76 次插入6 次删除
  1. 3 0
      config.sample.json
  2. 2 0
      electron/preload/api.ts
  3. 49 0
      electron/preload/utils.ts
  4. 22 6
      src/views/base/track-export/taskProgress.vue

+ 3 - 0
config.sample.json

@@ -0,0 +1,3 @@
+{
+  "downloadProcessCount": 2
+}

+ 2 - 0
electron/preload/api.ts

@@ -11,6 +11,7 @@ import {
   getTempPath,
   makeDirSync,
   getGmFontPath,
+  getConfigData,
 } from './utils';
 
 import {
@@ -182,6 +183,7 @@ const commonApi = {
   downloadImage,
   imagesToPdf,
   logger,
+  getConfigData,
 };
 
 export type CommonApi = typeof commonApi;

+ 49 - 0
electron/preload/utils.ts

@@ -52,3 +52,52 @@ export function makeDirSync(pathContent: string) {
 }
 
 makeDirSync(getTempPath());
+
+// 系统配置
+interface ConfitSetType {
+  downloadProcessCount: number;
+}
+type PartConfitSetType = Partial<ConfitSetType>;
+type ConfitSetTypeEnum = keyof ConfitSetType;
+
+const configSets = [
+  {
+    field: 'downloadProcessCount',
+    validate(val: any) {
+      return [1, 2, 3, 4, 5, 6].includes(val);
+    },
+    default: 2,
+  },
+];
+
+function getConfig(datas: PartConfitSetType) {
+  const configData = {} as ConfitSetType;
+  configSets.forEach((config) => {
+    const field = config.field as ConfitSetTypeEnum;
+    if (config.validate(datas[field])) {
+      configData[field] = datas[field] as ConfitSetType[ConfitSetTypeEnum];
+    } else {
+      configData[field] = config.default;
+    }
+  });
+  return configData;
+}
+
+export function getConfigData(data: PartConfitSetType) {
+  let configData = getConfig(data);
+  if (process.env.NODE_ENV === 'development') return configData;
+
+  const configPath = path.join(getRootDir(), 'config.json');
+  if (fs.existsSync(configPath)) {
+    try {
+      const configFileData = JSON.parse(
+        fs.readFileSync(configPath, 'utf8')
+      ) as PartConfitSetType;
+      configData = getConfig(configFileData);
+    } catch (error) {
+      console.log(error);
+    }
+  }
+
+  return configData;
+}

+ 22 - 6
src/views/base/track-export/taskProgress.vue

@@ -178,7 +178,11 @@
     updateProgress();
 
     // 开启导出进程
-    window.electron.startWinProcess(2, getExportUrl());
+    const appConfig = window.api.getConfigData({});
+    window.electron.startWinProcess(
+      appConfig.downloadProcessCount,
+      getExportUrl()
+    );
   }
 
   function updateTaskFilerInfo(data: FilterDataType | null) {
@@ -222,21 +226,33 @@
       },
       {
         label: '学号区间',
-        value: `${datas.startStudentCode}~${datas.endStudentCode}`,
+        value:
+          datas.startStudentCode || datas.endStudentCode
+            ? `${datas.startStudentCode}~${datas.endStudentCode}`
+            : '',
       },
       {
         label: '成绩区间',
-        value: `${datas.startScore}~${datas.endScore}`,
+        value:
+          datas.startScore || datas.endScore
+            ? `${datas.startScore}~${datas.endScore}`
+            : '',
       },
       {
         label: '客观题分区间',
-        value: `${datas.objectiveStartScore}~${datas.objectiveEndScore}`,
+        value:
+          datas.objectiveStartScore || datas.objectiveEndScore
+            ? `${datas.objectiveStartScore}~${datas.objectiveEndScore}`
+            : '',
       },
       {
         label: '主观题分区间',
-        value: `${datas.subjectiveStartScore}~${datas.subjectiveEndScore}`,
+        value:
+          datas.subjectiveStartScore || datas.subjectiveEndScore
+            ? `${datas.subjectiveStartScore}~${datas.subjectiveEndScore}`
+            : '',
       },
-    ].filter((item) => item.value && item.value !== '~');
+    ].filter((item) => item.value);
   }
 
   async function toCancel() {