소스 검색

fix $message duration & 统一退出函数

Michael Wang 3 년 전
부모
커밋
c9b0f456d1

+ 1 - 1
src/App.vue

@@ -39,7 +39,7 @@ watchEffect(() => {
 </script>
 
 <template>
-  <n-message-provider :duration="10000">
+  <n-message-provider :duration="15000">
     <n-dialog-provider>
       <n-config-provider
         :locale="zhCN"

+ 2 - 4
src/features/UserLogin/GeeTest.vue

@@ -41,8 +41,7 @@ async function resetGee() {
         },
       });
       $message.error("资源加载失败,请关闭程序,检查网络状况后重试。", {
-        duration: 1 * 60,
-        closable: true,
+        duration: 24 * 60 * 60 * 1000,
       });
     });
   }
@@ -63,8 +62,7 @@ async function resetGee() {
       ext: { errorName: error.name },
     });
     $message.error("资源注册失败,请关闭程序,检查网络状况后重试。", {
-      duration: 5 * 60,
-      closable: true,
+      duration: 24 * 60 * 60 * 1000,
     });
     return;
   }

+ 2 - 2
src/features/UserLogin/UserLogin.vue

@@ -135,7 +135,7 @@ let disableLoginBtn = $computed(
 //#region form校验
 const domain = DOMAIN;
 if (!domain?.includes(".ecs.qmth.com.cn")) {
-  $message.warning("学校域名不正确", { closable: false, duration: 360000 });
+  $message.warning("学校域名不正确", { duration: 5 * 60 * 1000 });
 }
 type FormModel = {
   accountType: "STUDENT_CODE" | "IDENTITY_NUMBER";
@@ -335,7 +335,7 @@ async function afterLogin(loginRes: any) {
       dtl: "getStudentInfoBySession/getStudentSpecialtyNameListApi失败",
     });
     $message.error("获取学生信息失败,请重试!", {
-      duration: 15,
+      duration: 15 * 60 * 1000,
       closable: true,
     });
   }

+ 6 - 11
src/features/UserLogin/useAppVersion.ts

@@ -9,14 +9,13 @@ export function useAppVersion(newVersionAvailable: Ref<boolean>) {
       disableLoginBtnBecauseAppVersionChecker = true;
       if (ua.getBrowser().version !== "1.9.3") {
         $message.error("请与学校申请最新的客户端,进行考试!", {
-          duration: 2 * 24 * 60 * 60,
+          duration: 24 * 60 * 60 * 1000,
         });
       } else {
         $message.error(
           "电脑环境达不到考试要求,请清理与考试无关软件或更换电脑",
           {
-            duration: 2 * 24 * 60 * 60,
-            closable: false,
+            duration: 24 * 60 * 60 * 1000,
           }
         );
       }
@@ -33,8 +32,7 @@ export function useAppVersion(newVersionAvailable: Ref<boolean>) {
       if (!isElectron() || !fileExists("multiCamera.exe")) {
         disableLoginBtnBecauseAppVersionChecker = true;
         $message.error("请与学校申请最新的客户端,进行考试!", {
-          duration: 2 * 24 * 60 * 60,
-          closable: false,
+          duration: 24 * 60 * 60 * 1000,
         });
       }
     }
@@ -44,15 +42,12 @@ export function useAppVersion(newVersionAvailable: Ref<boolean>) {
         disableLoginBtnBecauseAppVersionChecker = true;
         if (ua.getBrowser().version !== "1.9.3") {
           $message.error("请与学校申请最新的客户端,进行考试!", {
-            duration: 2 * 24 * 60 * 60,
+            duration: 24 * 60 * 60 * 1000,
           });
         } else {
           $message.error(
             "电脑环境达不到考试要求,请清理与考试无关软件或更换电脑",
-            {
-              duration: 2 * 24 * 60 * 60,
-              closable: false,
-            }
+            { duration: 24 * 60 * 60 * 1000 }
           );
         }
       }
@@ -64,7 +59,7 @@ export function useAppVersion(newVersionAvailable: Ref<boolean>) {
   watch(newVersionAvailable, () => {
     if (newVersionAvailable) {
       $message.error("程序有更新,请重新打开客户端!", {
-        duration: 2 * 24 * 60 * 60,
+        duration: 24 * 60 * 60 * 1000,
       });
     }
   });

+ 1 - 2
src/features/UserLogin/useElectronConfig.ts

@@ -33,8 +33,7 @@ export async function getElectronConfig(): Promise<Store["QECSConfig"]> {
       act: "fetch studentClientConfig.json",
     });
     $message.error("获取远程配置文件出错,请重新打开程序!", {
-      duration: 15 * 1000,
-      closable: true,
+      duration: 24 * 60 * 60 * 1000,
     });
     throw e;
   }

+ 1 - 2
src/features/UserLogin/useGeeTestConfig.ts

@@ -24,8 +24,7 @@ export async function getGeeTestConfig(rootOrgId: number): Promise<boolean> {
       act: "fetch geetestConfig.json",
     });
     $message.error("获取远程配置文件出错,请重新打开程序!", {
-      duration: 15 * 1000,
-      closable: true,
+      duration: 24 * 60 * 60 * 1000,
     });
     throw e;
   }

+ 1 - 1
src/features/UserLogin/useNewVersion.ts

@@ -27,7 +27,7 @@ export function useNewVersion() {
           pgu: "AUTO",
           dtl: "service worker刷新失败",
         });
-        $message.info("请重新打开程序。", { duration: 2 * 24 * 60 * 60 });
+        $message.info("请重新打开程序。", { duration: 24 * 60 * 60 * 1000 });
         return true;
       }
       logger({

+ 2 - 3
src/features/UserLogin/useRemoteAppChecker.ts

@@ -36,7 +36,7 @@ export function useRemoteAppChecker() {
         ext: { errorType: "e-01", applicationNames },
       });
       $message.error("系统检测出错(e-01),请退出程序后重试!", {
-        duration: 2 * 24 * 60 * 60,
+        duration: 24 * 60 * 60 * 1000,
       });
       return;
     }
@@ -68,8 +68,7 @@ export function useRemoteAppChecker() {
 
       names = [...new Set(names.split(",").map((v) => v.trim()))].join(",");
       $message.info("在考试期间,请关掉" + names + "软件,诚信考试。", {
-        duration: 2 * 24 * 60 * 60,
-        closable: false,
+        duration: 24 * 60 * 60 * 1000,
       });
     }
   }

+ 2 - 2
src/features/UserLogin/useVCamChecker.ts

@@ -32,7 +32,7 @@ export function useVCamChecker() {
         ext: { errorType: "e-02", applicationNames: cameraInfo },
       });
       $message.error("系统检测出错(e-02),请退出程序后重试!", {
-        duration: 2 * 24 * 60 * 60,
+        duration: 24 * 60 * 60 * 1000,
       });
       return;
     }
@@ -42,7 +42,7 @@ export function useVCamChecker() {
         if (cameraInfo.toUpperCase().includes(vc.toUpperCase())) {
           found = true;
           $message.info("在考试期间,请关掉虚拟摄像头软件,诚信考试。", {
-            duration: 2 * 24 * 60 * 60,
+            duration: 24 * 60 * 60 * 1000,
           });
           logger({
             cnl: ["local", "server"],

+ 2 - 17
src/plugins/axiosNotice.ts

@@ -1,24 +1,9 @@
 import { throttle } from "lodash-es";
-import router from "@/router";
+import { showLogout } from "@/utils/utils";
 
 export const notifyInvalidTokenThrottled = throttle(
   () => {
-    // $message.error("登录失效,请重新登录!");
-    logger({
-      pgu: "AUTO",
-      cnl: ["console", "server"],
-      dtl: "登录失效,请重新登录",
-    });
-    $dialog.error({
-      title: "登录失效",
-      content: "请重新登录。",
-      positiveText: "确定",
-      closable: false,
-      maskClosable: false,
-      onPositiveClick() {
-        void router.push({ name: "UserLogin" });
-      },
-    });
+    showLogout("登录失效");
   },
   3000,
   { trailing: false }

+ 18 - 0
src/utils/utils.ts

@@ -1,3 +1,5 @@
+import router from "@/router";
+
 export function setUUID() {
   if (!localStorage.getItem("uuidForEcs")) {
     const uuidForEcs = "" + Date.now() + Math.random();
@@ -9,3 +11,19 @@ export function setUUID() {
 export function isThisMachineOwnByStudent() {
   return JSON.parse(localStorage.getItem("userIds") || "[]").length < 5;
 }
+
+/** 通用的退出登录函数
+ * @param cause - 退出登录的原因
+ */
+export function showLogout(cause: string) {
+  logger({
+    pgu: "AUTO",
+    cnl: ["console", "local", "server"],
+    dtl: "用户被要求重新登录",
+    ext: {
+      cause,
+    },
+  });
+  $message.warning(cause, { duration: 5 * 60 * 1000, closable: true });
+  void router.push({ name: "UserLogin" });
+}