From a581d842a42b0c0542e4063edcc090106b91f6a6 Mon Sep 17 00:00:00 2001 From: smallchill Date: Mon, 4 Sep 2023 01:43:10 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20token=E6=96=B0=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AF=86=E9=85=8D=E7=BD=AE=EF=BC=8C=E4=BF=9D=E6=8A=A4=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/desk/notice.js | 5 +++++ src/axios.js | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/api/desk/notice.js b/src/api/desk/notice.js index 0f674f17..3c26a1f0 100644 --- a/src/api/desk/notice.js +++ b/src/api/desk/notice.js @@ -9,6 +9,7 @@ export const getList = (current, size, params) => { current, size, }, + cryptoToken: true, }); }; @@ -19,6 +20,7 @@ export const remove = ids => { params: { ids, }, + cryptoToken: true, }); }; @@ -27,6 +29,7 @@ export const add = row => { url: '/blade-desk/notice/submit', method: 'post', data: row, + cryptoToken: true, }); }; @@ -35,6 +38,7 @@ export const update = row => { url: '/blade-desk/notice/submit', method: 'post', data: row, + cryptoToken: true, }); }; @@ -45,5 +49,6 @@ export const getNotice = id => { params: { id, }, + cryptoToken: true, }); }; diff --git a/src/axios.js b/src/axios.js index 6b05cbf4..4c1ec2c3 100755 --- a/src/axios.js +++ b/src/axios.js @@ -17,6 +17,7 @@ import NProgress from 'nprogress'; // progress bar import 'nprogress/nprogress.css'; // progress bar style import { Base64 } from 'js-base64'; import { baseUrl } from '@/config/env'; +import crypto from '@/utils/crypto'; axios.defaults.timeout = 10000; //返回其他状态吗 @@ -45,11 +46,16 @@ axios.interceptors.request.use( `${website.clientId}:${website.clientSecret}` )}`; } - //让每个请求携带token + //headers判断请求是否携带token const meta = config.meta || {}; const isToken = meta.isToken === false; - if (getToken() && !isToken) { - config.headers[website.tokenHeader] = 'bearer ' + getToken(); + //headers传递token是否加密 + const cryptoToken = config.cryptoToken === true; + const token = getToken(); + if (token && !isToken) { + config.headers[website.tokenHeader] = cryptoToken + ? 'crypto ' + crypto.encrypt(token) + : 'bearer ' + token; } //headers中配置text请求 if (config.text === true) {