From 845a9f63e7c228c5353c24cd2d29b3b3fe9823d0 Mon Sep 17 00:00:00 2001 From: sws <1141121512@qq.com> Date: Wed, 23 Oct 2024 10:52:19 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=A7=A3=E5=86=B3=E7=BA=BF=E4=B8=8A=E6=8A=A5?= =?UTF-8?q?=E9=94=99token=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/preview/index.vue | 4 ++-- src/utils/request.ts | 6 +++--- src/views/layout/components/main/index.vue | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/common/preview/index.vue b/src/components/common/preview/index.vue index ceb3698e..7229a91b 100644 --- a/src/components/common/preview/index.vue +++ b/src/components/common/preview/index.vue @@ -23,7 +23,7 @@ const new_link = ref(''); const index = window.location.href.lastIndexOf('?s='); const pro_url = window.location.href.substring(0, index); // 如果是本地则使用静态tonken如果是线上则使用cookie的token -const cookie = get_cookie('admin_info'); +const cookie = get_cookie('admin_info') || ''; const token = ref(''); const key = ref(0); onMounted(async () => { @@ -31,7 +31,7 @@ onMounted(async () => { let temp_data = await import(import.meta.env.VITE_APP_BASE_API == '/dev-api' ? '../../../../temp.d.ts' : '../../../../temp_pro.d'); token.value = '&token=' + temp_data.default.temp_token; } else { - if (cookie) { + if (cookie && cookie !== null && cookie !== 'null') { token.value = '&token=' + JSON.parse(cookie).token; } } diff --git a/src/utils/request.ts b/src/utils/request.ts index 44d320ac..2a515aa8 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -33,14 +33,14 @@ const service = axios.create({ service.interceptors.request.use( async (config: InternalAxiosRequestConfig) => { // 如果是本地则使用静态tonken如果是线上则使用cookie的token - const cookie = get_cookie('admin_info'); + const cookie = get_cookie('admin_info') || ''; const symbol = config.url?.includes('?') ? '&' : '?'; if (import.meta.env.VITE_APP_BASE_API == '/dev-api') { let temp_data = await import(import.meta.env.VITE_APP_BASE_API == '/dev-api' ? '../../temp.d' : '../../temp_pro.d'); config.url = config.url + symbol + 'token=' + temp_data.default.temp_token; } else { - if (cookie) { - config.url = config.url + '&token=' + JSON.parse(cookie).token; + if (cookie && cookie !== null && cookie !== 'null') { + config.url = config.url + '&token=' + JSON.parse(cookie) !== 'null' ? JSON.parse(cookie)?.token : ''; } } return config; diff --git a/src/views/layout/components/main/index.vue b/src/views/layout/components/main/index.vue index 35ece6ec..b76a1cfc 100644 --- a/src/views/layout/components/main/index.vue +++ b/src/views/layout/components/main/index.vue @@ -245,7 +245,7 @@ interface componentsData { } const components = ref([]); const url_computer = (name: string) => { - const new_url = ref(new URL(`../../../../assets/images/layout/siderbar/${name}.png`, import.meta.url).href).value; + let new_url = ref(new URL(`../../../../assets/images/layout/siderbar/${name}.png`, import.meta.url).href).value; return new_url; };