1
0
tangning преди 1 ден
родител
ревизия
63f69becbd
променени са 3 файла, в които са добавени 16 реда и са изтрити 4 реда
  1. 3 2
      src/App.vue
  2. 2 2
      src/store/user.ts
  3. 11 0
      src/util/localUtil.ts

+ 3 - 2
src/App.vue

@@ -14,8 +14,9 @@ import { sceneType, show } from "@/store/case";
 import { strToParams } from "@/util";
 import { ElMessageBox } from "element-plus";
 import { browser } from "@/util/browser.ts";
-const params = strToParams(window.location.search);
-console.log("params", params);
+const url = window.location.href.split('?')[1];
+const params = strToParams(url);
+console.log("params", params, url);
 if (params.token) {
   setToken(params.token);
 }

+ 2 - 2
src/store/user.ts

@@ -1,4 +1,4 @@
-import { getLocal, changSaveLocal } from "@/util/localUtil";
+import { getLocal, changSaveLocal, getCookieToken } from "@/util/localUtil";
 import { ref, watchEffect } from "vue";
 import {
   PaggingReq,
@@ -49,7 +49,7 @@ export const getUsers = async (deptId?: string) =>
   (await axios.get<UserInfo[]>(getUserListSelect, { params: { deptId } })).data;
 // 当前用户的信息
 export const user = ref({
-  token: getLocal("token", false) || "",
+  token: getLocal("token", false) || getCookieToken('token'),
   info: getLocal("info", {} as UserInfo),
 });
 export const setToken = (token: string) => {

+ 11 - 0
src/util/localUtil.ts

@@ -24,3 +24,14 @@ export const changSaveLocal = <T>(key: string, get: () => T) => {
     deep: true,
   });
 };
+
+export const getCookieToken = <T>(name: string) => {
+    const cookies = document.cookie.split(';'); // 将Cookie拆分为数组
+    for (let i = 0; i < cookies.length; i++) {
+        const pair = cookies[i].trim().split('='); // 拆分键和值
+        if (pair[0] === name) {
+            return pair[1]; // 返回token值
+        }
+    }
+    return null; // 未找到返回null
+};