From 91ceaa2227fba5c98545e7439f6dd8d01cf15e05 Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Tue, 24 Sep 2024 11:12:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?url=E5=8A=A0token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/boot/axios.ts | 8 ++++---- src/configs/TokenManage.ts | 2 +- src/layouts/MainLayout.vue | 15 ++++++++++----- src/router/routes.ts | 4 ++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/boot/axios.ts b/src/boot/axios.ts index 07cf502..4cc9549 100644 --- a/src/boot/axios.ts +++ b/src/boot/axios.ts @@ -2,7 +2,7 @@ import axios, { AxiosInstance } from 'axios'; import { AxiosError } from 'axios'; import { Dialog } from 'quasar'; import { boot } from 'quasar/wrappers'; -//import { getJwtToken } from 'src/configs/TokenManage'; +import { getJwtToken } from 'src/configs/TokenManage'; import { getHttpBase } from 'src/configs/UrlManage'; declare module '@vue/runtime-core' { @@ -76,9 +76,9 @@ export default boot(({ app, router }) => { // 拦截请求,添加 api.interceptors.request.use( (config) => { - //config.headers.Authorization = getJwtToken(); - config.headers.Authorization = 'Bearer 1e2d0d5d96034f4a0805af6512051ddc'; - config.headers['Token'] = '1e2d0d5d96034f4a0805af6512051ddc'; + const token = getJwtToken(); + config.headers.Authorization = `Bearer ${token}`; + config.headers['Token'] = token; config.cancelToken = source.token; if (isOpenDialog) { source.cancel(); diff --git a/src/configs/TokenManage.ts b/src/configs/TokenManage.ts index 96828b1..fab9822 100644 --- a/src/configs/TokenManage.ts +++ b/src/configs/TokenManage.ts @@ -1,7 +1,7 @@ const JwtTokenKey = 'jwttoken'; export function saveJwtToken(token: string) { - sessionStorage.setItem(JwtTokenKey, `Bearer ${token}`); + sessionStorage.setItem(JwtTokenKey, token); } export function getJwtToken(): string | null { diff --git a/src/layouts/MainLayout.vue b/src/layouts/MainLayout.vue index be76d5b..1f778e8 100644 --- a/src/layouts/MainLayout.vue +++ b/src/layouts/MainLayout.vue @@ -121,16 +121,21 @@