From 67b1945747d7f0924f3d74cc39ce869924280ea4 Mon Sep 17 00:00:00 2001 From: zhj Date: Wed, 25 Dec 2024 17:42:12 +0800 Subject: [PATCH] init 4 --- .husky/commit-msg | 4 ++-- src/api/utils.ts | 3 ++- src/views/login/index.vue | 11 ++++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.husky/commit-msg b/.husky/commit-msg index 5ee2d16..96f1018 100644 --- a/.husky/commit-msg +++ b/.husky/commit-msg @@ -1,8 +1,8 @@ #!/bin/sh # shellcheck source=./_/husky.sh -. "$(dirname "$0")/_/husky.sh" +#. "$(dirname "$0")/_/husky.sh" PATH="/usr/local/bin:$PATH" -npx --no-install commitlint --edit "$1" \ No newline at end of file +npx --no-install commitlint --edit "$1" diff --git a/src/api/utils.ts b/src/api/utils.ts index ea1bc4c..46fe977 100644 --- a/src/api/utils.ts +++ b/src/api/utils.ts @@ -11,7 +11,8 @@ export const request = async (url: string, options: RequestInit = {}) => { // 非登录接口才添加token if (!url.includes("/login") && token) { - defaultHeaders["Authorization"] = `Bearer ${token}`; // 添加Bearer前缀 + // defaultHeaders["Authorization"] = `Bearer ${token}`; // 添加Bearer前缀 + defaultHeaders["Authorization"] = `Bearer ${token.accessToken}`; // 添加Bearer前缀 } const config = { diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 7eff978..19ee695 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -14,7 +14,7 @@ import { ref, reactive, toRaw, onMounted, onBeforeUnmount } from "vue"; import { useDataThemeChange } from "@/layout/hooks/useDataThemeChange"; import { request, loginApi } from "@/api/utils"; import { ElMessage } from "element-plus"; -import { setToken } from "@/utils/auth"; +import { setToken, getToken } from "@/utils/auth"; import dayIcon from "@/assets/svg/day.svg?component"; import darkIcon from "@/assets/svg/dark.svg?component"; @@ -61,8 +61,13 @@ const onLogin = async (formEl: FormInstance | undefined) => { console.log("登录成功,开始初始化路由"); console.log("accessToken:", res.data.accessToken); - // 存储token - setToken(res.data.accessToken); + // 存储token 格式为 DataInfo + //setToken(res.data.accessToken); + setToken(res.data); + + // 获取token + console.log("获取token:", getToken()); + console.log(getToken()); // 更新用户信息 const userStore = useUserStoreHook();