Sfoglia il codice sorgente

优化登录检测的错误处理

Michael Wang 6 anni fa
parent
commit
ea7c324fa8
1 ha cambiato i file con 44 aggiunte e 7 eliminazioni
  1. 44 7
      src/features/Login/Login.vue

+ 44 - 7
src/features/Login/Login.vue

@@ -251,9 +251,37 @@ export default {
         console.log("使用旧客户端");
       } catch (error) {
         console.log("尝试使用新客户端");
-        config = fs.readFileSync("config.js", "utf-8");
+        try {
+          config = fs.readFileSync("config.js", "utf-8");
+        } catch (error) {
+          const appPath = window
+            .nodeRequire("electron")
+            .remote.app.getAppPath();
+          try {
+            console.log("尝试使用最新的appPath");
+            config = fs.readFileSync(appPath + "/config.js", "utf-8");
+          } catch (error) {
+            this.$Message.error({
+              content: "读取本地配置文件出错,请重新打开程序或联系老师!",
+              duration: 15,
+              closable: true,
+            });
+            return;
+          }
+        }
+      }
+      var nameJson;
+
+      try {
+        nameJson = JSON.parse(config);
+      } catch (error) {
+        this.$Message.error({
+          content: "解析本地配置文件出错,请重新打开程序或联系老师!",
+          duration: 15,
+          closable: true,
+        });
+        return;
       }
-      var nameJson = JSON.parse(config);
 
       let electronConfig = null;
       try {
@@ -264,7 +292,7 @@ export default {
         )).data;
       } catch (error) {
         this.$Message.error({
-          content: "获取机构的客户端设置失败,请退出后重试!",
+          content: "获取机构的客户端设置失败,请退出程序后重试!",
           duration: 15,
           closable: true,
         });
@@ -274,10 +302,19 @@ export default {
       //如果配置中配置了  checkRemoteControl:true
       if (electronConfig.otherConfig.checkRemoteControl) {
         window.nodeRequire("node-cmd").get("Project1.exe", function() {
-          var applicationNames = fs.readFileSync(
-            "remoteApplication.txt",
-            "utf-8"
-          );
+          var applicationNames;
+          try {
+            applicationNames = fs.readFileSync(
+              "remoteApplication.txt",
+              "utf-8"
+            );
+          } catch (error) {
+            that.$Message.error({
+              content: "系统检测出错,请退出程序后重试!",
+              duration: 2 * 24 * 60 * 60,
+            });
+            return;
+          }
           if (applicationNames && applicationNames.trim()) {
             that.disableLoginBtn = true;
             that.$Message.info({