Browse Source

Merge branch 'master' of http://git.qmth.com.cn/themis/frontend-admin

zhangjie 4 years ago
parent
commit
3d23c37322
6 changed files with 54 additions and 9 deletions
  1. 3 1
      src/api/login.js
  2. 7 1
      src/global.d.ts
  3. 2 0
      src/main.js
  4. 6 6
      src/plugins/axiosApp.js
  5. 24 0
      src/utils/monitors.js
  6. 12 1
      src/utils/utils.js

+ 3 - 1
src/api/login.js

@@ -29,7 +29,9 @@ export function loginByUsername({ loginName, password, code }) {
     password: AES(password),
     password: AES(password),
     code,
     code,
   };
   };
-  return httpApp.post("/api/admin/user/login/account", data);
+  return httpApp.post("/api/admin/user/login/account", data, {
+    noErrorMessage: true,
+  });
 }
 }
 
 
 export function logout() {
 export function logout() {

+ 7 - 1
src/global.d.ts

@@ -62,7 +62,7 @@
 // }
 // }
 
 
 import Vue from "vue";
 import Vue from "vue";
-import { AxiosInstance } from "axios";
+import { AxiosInstance, AxiosRequestConfig } from "axios";
 
 
 // 可惜内部代码不能通过此类型推导
 // 可惜内部代码不能通过此类型推导
 //import * as api from "./api";
 //import * as api from "./api";
@@ -73,6 +73,12 @@ declare module "vue/types/vue" {
     // $api: api;
     // $api: api;
   }
   }
 }
 }
+
+declare module "axios/index" {
+  interface AxiosRequestConfig {
+    noErrorMessage?: boolean | false;
+  }
+}
 // declare module "*.vue" {
 // declare module "*.vue" {
 //   import Vue from "vue";
 //   import Vue from "vue";
 //   export default Vue;
 //   export default Vue;

+ 2 - 0
src/main.js

@@ -15,6 +15,8 @@ import "./plugins/element.js";
 import "./plugins/vueAwesome";
 import "./plugins/vueAwesome";
 import "./plugins/helpers";
 import "./plugins/helpers";
 
 
+import "./utils/monitors";
+
 // styles begin
 // styles begin
 // bootstrap 133KB non-zip
 // bootstrap 133KB non-zip
 import "./styles/bootstrap.scss";
 import "./styles/bootstrap.scss";

+ 6 - 6
src/plugins/axiosApp.js

@@ -71,9 +71,9 @@ _axiosApp.interceptors.response.use(
     return response;
     return response;
   },
   },
   (error) => {
   (error) => {
-    const noErrorMessage = error.config.noErrorMessage;
+    const showErrorMessage = !error.config.noErrorMessage;
     if (!error.response) {
     if (!error.response) {
-      if (noErrorMessage) {
+      if (showErrorMessage) {
         // "Network Error" 网络不通,直接返回
         // "Network Error" 网络不通,直接返回
         Notification({
         Notification({
           showClose: true,
           showClose: true,
@@ -92,7 +92,7 @@ _axiosApp.interceptors.response.use(
       removeToken();
       removeToken();
       return Promise.reject(error);
       return Promise.reject(error);
     } else if (status == 405) {
     } else if (status == 405) {
-      if (noErrorMessage) {
+      if (showErrorMessage) {
         Notification({
         Notification({
           showClose: true,
           showClose: true,
           message: "没有权限!",
           message: "没有权限!",
@@ -101,7 +101,7 @@ _axiosApp.interceptors.response.use(
       }
       }
       return Promise.reject(error);
       return Promise.reject(error);
     } else if (status == 502) {
     } else if (status == 502) {
-      if (noErrorMessage) {
+      if (showErrorMessage) {
         Notification({
         Notification({
           showClose: true,
           showClose: true,
           message: "服务器异常(502)!",
           message: "服务器异常(502)!",
@@ -114,7 +114,7 @@ _axiosApp.interceptors.response.use(
     if (status != 200) {
     if (status != 200) {
       const data = error.response.data;
       const data = error.response.data;
       if (data && data.message) {
       if (data && data.message) {
-        if (noErrorMessage) {
+        if (showErrorMessage) {
           Notification({
           Notification({
             showClose: true,
             showClose: true,
             message: data.message,
             message: data.message,
@@ -122,7 +122,7 @@ _axiosApp.interceptors.response.use(
           });
           });
         }
         }
       } else {
       } else {
-        if (noErrorMessage) {
+        if (showErrorMessage) {
           Notification({
           Notification({
             showClose: true,
             showClose: true,
             message: "未定义异常: " + JSON.stringify(data, 2),
             message: "未定义异常: " + JSON.stringify(data, 2),

+ 24 - 0
src/utils/monitors.js

@@ -0,0 +1,24 @@
+import Vue from "vue";
+import { errorLog } from "@/utils/utils";
+
+Vue.config.errorHandler = (error) => {
+  errorLog(error.message, {
+    stack: error.stack,
+    code: "Vue组件错误",
+  });
+  throw error;
+};
+
+window.addEventListener("error", function (event) {
+  errorLog(event.message, {
+    stack: event.error.stack.replace(/\n/g, "||||"),
+    code: "全局JS错误",
+  });
+});
+
+window.addEventListener("unhandledrejection", function (event) {
+  errorLog(event?.reason?.message, {
+    stack: event.error.stack.replace(/\n/g, "||||"),
+    code: "全局JS错误",
+  });
+});

+ 12 - 1
src/utils/utils.js

@@ -1,4 +1,4 @@
-import { YYYYMMDDHHmmss } from "@/constants/constants";
+import { YYYYMMDDHHmmss } from "@/constant/constants";
 import moment from "moment";
 import moment from "moment";
 
 
 export function dateFormatForAPI(date) {
 export function dateFormatForAPI(date) {
@@ -11,3 +11,14 @@ export function formatEmptyToNull(obj) {
   });
   });
   return obj;
   return obj;
 }
 }
+
+// 错误上报:本地打印,百度统计,阿里云日志
+export function errorLog(message, { stack = "", code = "" }) {
+  console.error({ message, stack, code });
+  window._hmt.push([
+    "_trackEvent",
+    "message: " + message,
+    stack && "stack: " + stack,
+    code && "code: " + code,
+  ]);
+}