From e296787589fe18e44e36693d2b40eb13fa20ef78 Mon Sep 17 00:00:00 2001 From: smallchill Date: Sat, 2 Jul 2022 19:57:20 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20axios=E5=A2=9E=E5=8A=A0authorization?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=A4=B4=E9=9A=90=E8=97=8F=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user.js | 9 ++++++--- src/router/axios.js | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/api/user.js b/src/api/user.js index ae41c7c..69c7ecb 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -72,12 +72,14 @@ export const getButtons = () => request({ export const getCaptcha = () => request({ url: '/api/blade-auth/oauth/captcha', - method: 'get' + method: 'get', + authorization: false }); export const logout = () => request({ url: '/api/blade-auth/oauth/logout', - method: 'get' + method: 'get', + authorization: false }); export const getUserInfo = () => request({ @@ -93,5 +95,6 @@ export const sendLogs = (list) => request({ export const clearCache = () => request({ url: '/api/blade-auth/oauth/clear-cache', - method: 'get' + method: 'get', + authorization: false }); diff --git a/src/router/axios.js b/src/router/axios.js index 7b0a00d..64b38fe 100644 --- a/src/router/axios.js +++ b/src/router/axios.js @@ -32,10 +32,14 @@ NProgress.configure({ axios.interceptors.request.use(config => { //开启 progress bar NProgress.start(); + //headers判断是否需要 + const authorization = config.authorization === false; + if (!authorization) { + config.headers['Authorization'] = `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}`; + } + //让每个请求携带token const meta = (config.meta || {}); const isToken = meta.isToken === false; - config.headers['Authorization'] = `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}`; - //让每个请求携带token if (getToken() && !isToken) { config.headers[website.tokenHeader] = 'bearer ' + getToken() }