瀏覽代碼

补充阿里云SLS日志:为每台设备添加uuid

Michael Wang 5 年之前
父節點
當前提交
1a65214f2d
共有 4 個文件被更改,包括 20 次插入3 次删除
  1. 2 2
      src/features/Login/Login.vue
  2. 2 0
      src/main.js
  3. 9 1
      src/utils/logger.js
  4. 7 0
      src/utils/util.js

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

@@ -131,7 +131,7 @@ import {
   VUE_APP_CONFIG_FILE_SEVER_URL,
 } from "@/constants/constants";
 import UA, { chromeUA } from "@/utils/ua.js";
-import { createLog, createUserLog } from "@/utils/logger";
+import { createLog, createUserDetailLog } from "@/utils/logger";
 
 // 检测devtools.  仅在chrome 72+ 有效。
 let element = new Image();
@@ -562,7 +562,7 @@ export default {
           ]);
           const alreadyInExam = await this.checkExamInProgress();
           window._hmt.push(["_trackEvent", "登录页面", "登录成功"]);
-          createUserLog({ action: "登录成功" });
+          createUserDetailLog({ action: "登录成功" });
           if (alreadyInExam) {
             this.logger({ action: "断点续考", detail: "登录页面" });
             window._hmt.push([

+ 2 - 0
src/main.js

@@ -20,6 +20,8 @@ import "./utils/monitors";
 import "webrtc-adapter";
 
 import MainLayout from "@/components/MainLayout/MainLayout.vue";
+import { setUUID } from "@/utils/util";
+setUUID();
 
 Vue.use(axiosPlugin);
 

+ 9 - 1
src/utils/logger.js

@@ -30,13 +30,17 @@ import store from "@/store";
 
 // ip 定位?
 // 要在用户登录后调用
-export function createUserLog() {
+export function createUserDetailLog() {
   try {
     const user = store.state.user;
     logger.push("userName", user.displayName);
     logger.push("userId", user.id);
     logger.push("rootOrgName", user.rootOrgName);
     logger.push("rootOrgId", user.rootOrgId);
+    const uuidForEcs = localStorage.getItem("uuidForEcs");
+    if (uuidForEcs) {
+      logger.push("uuidForEcs", uuidForEcs);
+    }
     logger.logger();
   } catch (error) {
     console.log(error);
@@ -47,6 +51,10 @@ export function createUserLog() {
 export function createLog(logs) {
   try {
     const user = store.state.user;
+    const uuidForEcs = localStorage.getItem("uuidForEcs");
+    if (uuidForEcs) {
+      logger.push("uuidForEcs", uuidForEcs);
+    }
     if (user) {
       logger.push("userId", user.id);
     }

+ 7 - 0
src/utils/util.js

@@ -23,3 +23,10 @@ export function toChineseNumber(num) {
 export function isThisMachineOwnByStudent() {
   return (JSON.parse(localStorage.getItem("userIds")) || []).length < 5;
 }
+
+export function setUUID() {
+  if (!localStorage.getItem("uuidForEcs")) {
+    const uuidForEcs = "" + Date.now() + Math.random();
+    localStorage.setItem("uuidForEcs", uuidForEcs);
+  }
+}