From a27ce47f651701b718e69c436d7fe3a40fcf94f6 Mon Sep 17 00:00:00 2001 From: ch Date: Wed, 29 Jun 2022 16:07:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E7=BB=9F=E8=AE=A1=E4=B8=8D?= =?UTF-8?q?=E5=81=9ATK=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/api/comment.js | 15 +++++++++++---- src/common/utils/requset.js | 25 +++++++++++++------------ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/common/api/comment.js b/src/common/api/comment.js index db2f951..2c84564 100644 --- a/src/common/api/comment.js +++ b/src/common/api/comment.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-06-20 11:38:48 * @LastEditors: ch - * @LastEditTime: 2022-06-24 11:15:09 + * @LastEditTime: 2022-06-29 16:04:59 * @Description: file content */ @@ -15,13 +15,18 @@ const BASE_URL = '/mall/comment'; * @param {*} param0 */ export const ApiGetCommentList = (params) => - ToAsyncAwait(MsbRequest.get(`${BASE_URL}/app/comment`, params)); + ToAsyncAwait(MsbRequestTk.get(`${BASE_URL}/app/comment`, { + ...params, + notVerifyToken : true + })); /** * 根据商品获取评论总数 * @param {*} param0 */ export const ApiGetCommentCount = ({productId}) => - ToAsyncAwait(MsbRequest.get(`${BASE_URL}/app/comment/getAllCommentCountByProductId/${productId}`)); + ToAsyncAwait(MsbRequestTk.get(`${BASE_URL}/app/comment/getAllCommentCountByProductId/${productId}`, { + notVerifyToken : true + })); /** * 根据商品获取标签评论总数 * @param {*} param0 @@ -39,7 +44,9 @@ export const ApiGetOrderCommentDetail = ({orderId}) => * @param {*} param0 */ export const ApiGetCommentDetail = ({commentId}) => - ToAsyncAwait(MsbRequest.get(`${BASE_URL}/app/comment/getCommentDetail/${commentId}`)); + ToAsyncAwait(MsbRequestTk.get(`${BASE_URL}/app/comment/getCommentDetail/${commentId}`, { + notVerifyToken : true + })); /** * 新增评论 * @param {*} param0 diff --git a/src/common/utils/requset.js b/src/common/utils/requset.js index 5ed5d10..273ed12 100644 --- a/src/common/utils/requset.js +++ b/src/common/utils/requset.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-03-17 17:42:32 * @LastEditors: ch - * @LastEditTime: 2022-06-28 11:38:02 + * @LastEditTime: 2022-06-29 16:02:20 * @Description: 项目接口请求统一处理器,返回一个需要token和不需要token的请求封装方法 */ @@ -107,24 +107,25 @@ MsbRequestTk.baseUrl = ENV.baseUrl; MsbRequestTk.use('request', (option) => { const token = $store.state.token; option.header.uid = uuid; - if(!token){ + + if(!token && && !config.headers.notVerifyToken){ // 登录状态处理,没有token直接跳转至登录 uni.redirectTo({ url: '/login' }); return Promise.reject({message:'要先登录才能操作哦~'}); - }else{ - option.header = {...option.header, Authorization:token}; - - if(option.header.repeat){ - // 如果当前请求不允许重复调用,则检查重复请求,当前接口有正在请求则不发起请求 - const isRepeatVerify = repeatVerify(option); - if(isRepeatVerify){ - return isRepeatVerify; - } + } + delete config.headers.notVerifyToken + option.header = {...option.header, Authorization:token}; + + if(option.header.repeat){ + // 如果当前请求不允许重复调用,则检查重复请求,当前接口有正在请求则不发起请求 + const isRepeatVerify = repeatVerify(option); + if(isRepeatVerify){ + return isRepeatVerify; } - return option; } + return option; }) MsbRequestTk.use('success', successIntercept); MsbRequestTk.use('error', errorIntercept);