From b80c9913781f7d331838c3750d42f536e65f70d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=9A=E7=9A=93?= <1736436516@qq.com> Date: Fri, 25 Oct 2024 17:00:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=9B=B4=E6=96=B0=EF=BC=8Ccr?= =?UTF-8?q?osrToken=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 7 +++++++ src/utils/boxApi.ts | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 75303fa..13d561f 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -10,6 +10,7 @@ import UserList from '@/html/UserList.vue'; import Home from '@/html/Home.vue'; import DataStatistics from '@/html/DataStatistics.vue'; import Cameras from '@/components/Cameras.vue'; +import Settings from '@/components/Settings.vue'; const routes = [ { @@ -65,6 +66,12 @@ const routes = [ name: 'Cameras', component: Cameras, meta: { requiresAuth: true } + }, + { + path:'/settings', + name: 'Settings', + component: Settings, + meta: { requiresAuth: true } } ] }, diff --git a/src/utils/boxApi.ts b/src/utils/boxApi.ts index ed8dfa0..0106201 100644 --- a/src/utils/boxApi.ts +++ b/src/utils/boxApi.ts @@ -382,17 +382,24 @@ class BoxApi { } private _authHeader(token: string | null = null): object { - // const access_token = token === "" ? this.token : token; - const alertToken = localStorage.getItem(`alertToken`) || token || this.token || "" || ""; + const accessToken = token || this.token || localStorage.getItem('alertToken') || ""; return { headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', - 'Authorization': `Bearer ${alertToken}`, - // 'Cookie': `jwt=${access_token}` + 'Authorization': `Bearer ${accessToken}`, + // 'X-CSRFToken': this.getCsrfToken() } - } + }; } + private getCsrfToken(): string { + const cookie = document.cookie.split(';').find(cookie => cookie.trim().startsWith('csrftoken=')); + if (cookie) { + return cookie.split('=')[1]; + } + return ''; + } + private _boxAddr() { return window.location.host.replace(/:\d+/, "");