Michael Wang 3 年 前
コミット
3214216bec

+ 1 - 1
config.json

@@ -18,7 +18,7 @@
     "logger": {
         "level": "info"
     },
-    "imagemagick": "/usr/local/bin/",
+    "imagemagickDev": "/usr/local/bin/",
     "openDevTools": false,
     "servers": [
         {

+ 1 - 1
src/components/Layout.vue

@@ -4,7 +4,7 @@
       <div class="logo"><img src="img/logo.png" /></div>
       <span class="y">
         欢迎您,<span id="user-name">{{ userName }}</span>
-        <span class="pipe">|</span><a href="/">退出</a>
+        <span class="pipe">|</span> <router-link to="/">退出</router-link>
       </span>
     </div>
     <div class="cont">

+ 5 - 4
src/features/Sync/Sync.vue

@@ -8,10 +8,10 @@
       本地已下载考生数量:<b id="student-count">{{ studentCount }}</b>
     </p>
     <p>
-      上次下载完成时间:<b id="last-time">{{ lastTime }}</b>
+      上次下载完成时间:<b id="last-time">{{ lastSyncTime }}</b>
     </p>
     <div class="btn">
-      <a href="/sync-run"><span>开始同步数据</span></a>
+      <router-link to="/sync-run"><span>开始同步数据</span></router-link>
     </div>
   </div>
 </template>
@@ -20,8 +20,9 @@
 import { store } from "@/store";
 import { onMounted, ref } from "vue";
 
-const lastTime =
-  store.config["syncTime"][store.env.server.host + store.env.exam.id];
+const syncId = store.env.server.host + "_" + store.env.exam.id;
+const lastSync = store.syncTime.find((v) => v.id === syncId);
+const lastSyncTime = lastSync ? lastSync.time : "无";
 
 let studentCount = ref(0);
 onMounted(async () => {

+ 11 - 0
src/features/SyncRun/SyncRun.vue

@@ -22,6 +22,7 @@ import { onMounted, ref } from "vue";
 import { Modal } from "ant-design-vue";
 import { useRouter } from "vue-router";
 import { getStudents, countStudents, getPackages } from "@/api/api";
+import moment from "moment";
 
 const router = useRouter();
 console.log(router);
@@ -120,6 +121,16 @@ onMounted(async () => {
     status.value = "数据同步完成";
 
     // config.updateSyncTime()
+    const syncId = store.env.server.host + "_" + store.env.exam.id;
+    const lastSync = store.syncTime.find((v) => v.id === syncId);
+    if (lastSync) {
+      lastSync.time = moment().format("YYYY-MM-DD HH:mm:ss");
+    } else {
+      store.syncTime.push({
+        id: syncId,
+        time: moment().format("YYYY-MM-DD HH:mm:ss"),
+      });
+    }
 
     const modal = Modal.success();
     modal.update({

+ 0 - 22
src/lib/config.ts

@@ -1,7 +1,6 @@
 import fs, { readFileSync } from "fs";
 import path from "path";
 import process from "process";
-import moment from "moment";
 
 let configJson;
 // if (process.env.IS_ELECTRON) {
@@ -15,24 +14,3 @@ if (dirName) {
 const store = JSON.parse(configJson.toString());
 
 export default store;
-
-const timeLog = path.join(__dirname, "../../logs/time.log");
-let syncTime = {};
-if (fs.existsSync(path.join(__dirname, "../../logs/time.log"))) {
-  try {
-    syncTime = readFileSync(timeLog).toJSON();
-  } catch (err) {
-    syncTime = {};
-  }
-}
-store["syncTime"] = syncTime;
-
-export function updateSyncTime(): void {
-  if (env.server && env.exam) {
-    syncTime[env.server.host + "_" + env.exam.id] = moment().format(
-      "YYYY-MM-DD HH:mm:ss"
-    );
-    store["syncTime"] = syncTime;
-    fs.writeFileSync(timeLog, JSON.stringify(syncTime));
-  }
-}

+ 13 - 9
src/store.ts

@@ -9,18 +9,21 @@ const _store = {
     loginName: "",
     password: "",
     server: { host: "", name: "" },
-    user: {},
-  },
+    user: {} as Store["env"]["user"],
+    exam: {} as Store["env"]["exam"],
+    examId: -1,
+  } as Store["env"],
   config: JSON.parse(JSON.stringify(window.electron.config)) || {},
-  pageInputs: {},
+  pageInputs: {} as Store["pageInputs"],
+  syncTime: [],
 } as Store;
 
 // for dev
-Object.assign(
-  _store,
-  JSON.parse(window.localStorage.getItem("store") || "{}"),
-  { config: JSON.parse(JSON.stringify(window.electron.config)) || {} } // use 最新的config
-);
+// Object.assign(
+//   _store,
+//   JSON.parse(window.localStorage.getItem("store") || "{}"),
+//   { config: JSON.parse(JSON.stringify(window.electron.config)) || {} } // use 最新的config
+// );
 
 const handler = function () {
   return {
@@ -38,7 +41,8 @@ const handler = function () {
       if (!_inited) {
         Object.assign(
           _store,
-          JSON.parse(window.localStorage.getItem("store") || "{}")
+          JSON.parse(window.localStorage.getItem("store") || "{}"),
+          { config: JSON.parse(JSON.stringify(window.electron.config)) || {} } // use 最新的config
         );
         _inited = true;
       }

+ 2 - 0
src/types/index.ts

@@ -30,6 +30,8 @@ export interface Store {
     imagemagickDev?: string;
   };
 
+  syncTime: Array<{ id: string; time: string }>;
+
   pageInputs: {
     "/image-download": {
       type: string;