Forráskód Böngészése

前端日志添加用户名字段

zhongxiaoyu 3 éve
szülő
commit
9f29628cba
3 módosított fájl, 20 hozzáadás és 5 törlés
  1. 2 1
      src/store/modules/user.js
  2. 14 2
      src/utils/auth.js
  3. 4 2
      src/utils/request.js

+ 2 - 1
src/store/modules/user.js

@@ -1,5 +1,5 @@
 import { login, loginUp, getInfo } from '@/api/login'
-import { getToken, setToken, removeToken, setUserId, TokenKey, setLogId, removeLogId } from '@/utils/auth'
+import { getToken, setToken, removeToken, setUserId, TokenKey, setLogId, removeLogId, setUserName } from '@/utils/auth'
 import { resetRouter } from '@/router'
 import { wsSocketClose } from '@/utils/socket'
 const getDefaultState = () => {
@@ -65,6 +65,7 @@ const actions = {
           setToken('FirstLogin', returnData.FirstLogin);
           setLogId(returnData.LogId)
           setUserId(returnData.UserId)
+          setUserName(returnData.UserName)
           let nowDate = new Date();
           let oldDate = new Date(returnData.ValidTime);
           let diffTime = oldDate - nowDate;

+ 14 - 2
src/utils/auth.js

@@ -31,13 +31,25 @@ export function getCodeToken () {
 }
 
 export function setLogId(id) {
-  sessionStorage.setItem('LogId', id)
+  id && sessionStorage.setItem('LogId', id)
 }
 
 export function getLogId() {
-  return sessionStorage.getItem('LogId')
+  return sessionStorage.getItem('LogId') ?? ''
 }
 
 export function removeLogId() {
   sessionStorage.removeItem('LogId')
 }
+
+export function setUserName(name) {
+  name && sessionStorage.setItem('UserName', name)
+}
+
+export function getUserName() {
+  return sessionStorage.getItem('UserName') ?? ''
+}
+
+export function removeUserName() {
+  sessionStorage.removeItem('UserName')
+}

+ 4 - 2
src/utils/request.js

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2022-01-06 09:45:17
- * @LastEditTime: 2022-04-16 21:51:46
+ * @LastEditTime: 2022-04-19 10:42:27
  * @LastEditors: your name
  * @Description: axios封装
  */
@@ -105,10 +105,12 @@ service.interceptors.response.use(
         if (res.code === 0) {
           config.data.OperatorId = (res.returnData.UserId ?? '').toString()
           config.data.LogId = (res.returnData.LogId ?? '').toString()
+          config.data.UserName = (res.returnData.UserName ?? '').toString()
         }
       } else {
         config.data.OperatorId = getUserId()
-        config.data.LogId = getLogId() ?? ''
+        config.data.LogId = getLogId()
+        config.data.UserName = getUserName()
       }
       service(config)
     }